Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ncm-metaconfig: ssh daemon configuration support #1377

Closed
wants to merge 6 commits into from

Conversation

gombasg
Copy link
Contributor

@gombasg gombasg commented Apr 11, 2019

This allows deprecating ncm-ssh. I'd appreciate if someone cross-checked the schema with the sshd_options man page.

@gombasg gombasg requested a review from jrha April 11, 2019 14:26
@jrha jrha added this to the 19.6 milestone Apr 12, 2019
@ned21
Copy link
Contributor

ned21 commented Jul 10, 2019

@hpcugentbot test this please

@jrha
Copy link
Member

jrha commented Jul 11, 2019

Looks nice, ncm-ssh does run-time validation of the generated configuration, is this now considered unnecessary?

@gombasg
Copy link
Contributor Author

gombasg commented Jul 12, 2019

@jrha: It would still be nice to have the run-time check, because the templates cannot verify if the generated configuration is compatible with the version of sshd which happens to be installed. I just don't know how that could be implemented with metaconfig. Maybe @stdweird has ideas :-)


prefix "/software/components/metaconfig/services/{/etc/ssh/sshd_config}/contents";

"main/AcceptEnv" = list("LC_CTYPE", "LANG", "TERM");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use relative main prefix (or add main to the absolute prefix path)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, this is a test

@@ -0,0 +1,96 @@
object template server_allopts;

include 'metaconfig/ssh/server_config';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment on what ssh release this is based? or which OS?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, didn't see that this was a test.

'RekeyLimit' ] -%]
[% commalist = ['Ciphers', 'HostKeyAlgorithms', 'HostbasedAcceptedKeyTypes', 'KexAlgorithms', 'MACs', 'PubkeyAcceptedKeyTypes' ] -%]
[% multilinelist = ['HostKey', 'ListenAddress', 'Port' ] -%]
[% booleans = ['AllowAgentForwarding',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are not needed if they are true pan booleans. you can test those explicitly in TT using CCM.is_boolean() (but not in a case block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's value.is_boolean; see default case below

SetEnv [% item.key %]="[% item.value %]"
[% END -%]
[% CASE -%]
[% pair.key %] [% pair.value %]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or do the boolean check here, and maybe add a the most common type pf list and have that here as default list format (saves you another static list)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[%             pair.key %] [% -%]
[-% IF pair.value.is_boolean -%]
[%- pair.value ? 'Yes' : 'No' -%]
[%- ELSIF CCM.is_list(pair.value) -%]
[%- pair.value.join(' ') -%]
[%- ELSE -%]
[%- pair.value -%]
[-% END -%]

@@ -0,0 +1,44 @@
[% spacelist = ['AcceptEnv', 'AllowGroups', 'AllowUsers', 'AuthenticationMethods', 'AuthorizedKeysFile', 'AuthorizedPrincipalsFile',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems the longest list; use this as the default list fallback

@stdweird
Copy link
Member

@gombasg i have ideas 😄
i have an objection against implementing another "run arbitrary something as root" from the profiles, but hardcoding a whole bunch of test commands and being able to call them is fine for me.
and here it would be easy because the test does not require a file (or "the" final file).
anything that can be verified from stdin is easy to do.

verifying from file might be easy to do, if we patch/hack the atomic filewriter so we can test on the temp file. but it needs a patch to the atomicwriter.

@jrha
Copy link
Member

jrha commented Jul 15, 2019

@gombasg if it was desirable then the cleanest (IMHO) way to implement it would be to make the existing component use textrender with these TT files.

@jrha jrha modified the milestones: 19.12, 20.2 Dec 12, 2019
@jrha
Copy link
Member

jrha commented Dec 12, 2019

I'm bumping this - I want to look at migrating ncm-ssh to use these TT files with textrender so we can keep the validation logic.

@gombasg
Copy link
Contributor Author

gombasg commented Jan 31, 2020

@jrha The question is, where to put the schema? I don't want to duplicate the definitions which are common between the client and the server.

@gombasg
Copy link
Contributor Author

gombasg commented Feb 13, 2020

There is another issue with ncm-ssh. It is currently using CAF::FileEditor, and not CAF::FileWriter, which is a pain if one has to switch between different OpenSSH version supporting a different set of parameters, with the ability to back the change out if needed. However, making the switch in the ncm-ssh component would break deployments which do not define all SSH daemon options in profiles, but depend on system default remaining undisturbed. Using a different component means the template changes need updating anyway, so the missing options could be added.

Add support for prefixing various key types with "+" or "-" to indicate
relative changes to the built-in defaults.
The main driver was getting support for "Match ..." blocks, which would
have been more dificult to add to ncm-ssh.
Use value.is_boolean instead.
Re-work some regular expressions to make lines shorter. Add
GSSAPIKexAlgorithms and a missing CASignatureAlgorithms setting.
@ned21
Copy link
Contributor

ned21 commented Mar 5, 2020

There is another issue with ncm-ssh. It is currently using CAF::FileEditor, and not CAF::FileWriter, which is a pain if one has to switch between different OpenSSH version supporting a different set of parameters, with the ability to back the change out if needed. However, making the switch in the ncm-ssh component would break deployments which do not define all SSH daemon options in profiles, but depend on system default remaining undisturbed. Using a different component means the template changes need updating anyway, so the missing options could be added.

How about adding a "full control" option to ncm-ssh? That would allow us to keep the config validation check prior to restarting sshd? Or have I not understood the constraint with Atomic FileWriter?

@gombasg
Copy link
Contributor Author

gombasg commented Mar 6, 2020

A "full control" option need a new implementation of the Configure method. The schema used by ncm-ssh is incompatible with the metaconfig-based schema, so either the TT files will have to be re-written from scratch, or the entire schema need to be switched based on the value of "full control". So essentially, we'd end up with two independent, incompatible components disguised as one. I'm not sure keeping the validation would worth it. If validation is really needed, then we should convince @stdweird to add a generic validation step to metaconfig. Yes, that would in fact mean running arbitrary commands as root, because we do not always run the OS-supplied sshd, so the full path of the daemon would need to be specified in the templates, it cannot be hard-coded in the component.

@stdweird
Copy link
Member

stdweird commented Jun 5, 2020

@gombasg @ned21 @jrha @jouvin lets settle this: feel free to vote and/or campaign for

a: run arbitrary commands via ncm-metaconfig
b: make static list of allowed commands (or list of regexes or somesuch) for things that make sense (like the ssh config self test or others)
c: do nothing, if you want to run arbitrary code, make a service/unit and call it as part of the daemons (should fix the dependecy order to run ncm-systemd before ncm-metaconfig)

whatever is decided, i can then also implement it to run validation

@gombasg
Copy link
Contributor Author

gombasg commented Jun 7, 2020 via email

@stdweird
Copy link
Member

stdweird commented Jun 8, 2020

@gombasg thanks for voting! ;) i get that, i also struggle with that, as it's hard to try to limit the power of running arbitrary commands in a practical way.

i can add a pre, verifiy and post command option. verify will receive the file content on stdin (like ncm-ssh checks the validity).

in this case, i would then set a default value of the verify command to list("/usr/sbin/sshd", '-t', '-f', '/dev/stdin').
i would stick to the list format (no subshell), but not sure this is enough? should it be a list of lists to support running multiple commands? or just a string?

@gombasg
Copy link
Contributor Author

gombasg commented Jun 8, 2020 via email

};

type sshd_config_match = {
"matches" : string[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gombasg why did you choose this so freeform? why not a list of dicts wit allowed keys and arbitrary values?

@gombasg
Copy link
Contributor Author

gombasg commented Jun 10, 2020 via email

@stdweird
Copy link
Member

@gombasg i don't see why the matches itself need to be a list. all criteria have to match, so order seems irrelavnt. and if the 'All' key is used, we can handle in TT to only print 'All' without anything else.

wrt the mixed type type, if you really want that, you can

[stdweird@localhost tmp]$ cat t.pan 
object template t;

type x = element with is_string(SELF) || is_list(SELF);

bind "/a" = x{};

"/a/b" = "string";
"/a/c" = list(0,1);

[stdweird@localhost tmp]$ cat t.xml 
<?xml version="1.0" encoding="UTF-8"?><nlist format="pan" name="profile">
    <nlist name="a">
        <string name="b">string</string>
        <list name="c">
            <long>0</long>
            <long>1</long>
        </list>
    </nlist>
</nlist>

@stdweird
Copy link
Member

@gombasg commands implemented in #1451
i'm going to take over this PR

@stdweird
Copy link
Member

@gombasg i've opened #1452

@ned21
Copy link
Contributor

ned21 commented Jun 11, 2020

Superseded by #1452

@ned21 ned21 closed this Jun 11, 2020
@jrha jrha removed this from the 20.12 milestone Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants