Skip to content

Conversation

bhouse-nexthop
Copy link
Contributor

@bhouse-nexthop bhouse-nexthop commented Apr 11, 2025

The SSH configuration does not contain many of the hardening requirements by the various standards bodies. This adds support for:

  • password_authentication - ability to disable password auth
  • permit_root_login - ability to control root login rights
  • ciphers - ability to specify available ciphers
  • kex_algorithms - ability to specify key exchange algorithms
  • macs - ability to specify macs

Depends on sonic-net/sonic-buildimage#22308
Fixes sonic-net/sonic-buildimage#22309

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

The SSH configuration does not contain many of the hardening
requirements by the various standards bodies.  This adds
support for:
 * password_authentication - ability to disable password auth
 * permit_root_login - ability to prevent root logins
 * ciphers - ability to specify available ciphers
 * kex_algorithms - ability to specify key exchange algorithms
 * macs - ability to specify macs

Signed-off-by: Brad House <bhouse@nexthop.ai>
@bhouse-nexthop bhouse-nexthop force-pushed the bhouse-nexthop/ssh-config branch from 19a049a to 84f7678 Compare May 20, 2025 12:40
@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft qiluo-msft requested review from Copilot and liuh-80 June 19, 2025 18:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the SSH configuration options to support hardening requirements by adding new configuration vectors for password authentication, root login, ciphers, key exchange algorithms, and MACs. Key changes include:

  • Updates to test vectors and sample outputs for various SSH hardening options.
  • Addition of new test cases in hostcfgd tests to validate the updated SSH configuration.
  • Modifications in the SshServer code to support the new configuration keys and proper value conversion.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

File Description
tests/hostcfgd/test_ssh_server_vectors.py Added new test vectors for password_authentication, permit_root_login, ciphers, kex_algorithms, and macs.
tests/hostcfgd/sample_output/*/sshd_config Updated sample SSHD configuration outputs to reflect the new hardening options.
tests/hostcfgd/hostcfgd_ssh_server_test.py Added new test cases corresponding to each new SSH hardening option.
scripts/hostcfgd Modified the SSH configuration processing to support additional options and value conversions.


if key in SSH_INT_VALUES and (int(value) < SSH_MIN_VALUES.get(key, 65535) or
SSH_MAX_VALUES.get(key, -1) < int(value)):
syslog.syslog(syslog.LOG_ERR, "Ssh {} {} out of range".format(key, value))
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

The out-of-range check logs an error but does not stop further processing. Consider adding an early return or skipping further processing to prevent invalid configuration values from being applied.

Suggested change
syslog.syslog(syslog.LOG_ERR, "Ssh {} {} out of range".format(key, value))
syslog.syslog(syslog.LOG_ERR, "Ssh {} {} out of range".format(key, value))
continue

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reject

Copy link
Contributor

@liuh-80 liuh-80 Jun 20, 2025

Choose a reason for hiding this comment

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

May I know the reject reason and also update to code comments?
If out of range is not an error, maybe write warning log here.
#Closed

Copy link

@bradh352 bradh352 Jun 20, 2025

Choose a reason for hiding this comment

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

Actually, may be i did miss the 'continue' clause addition here after looking at the code not the diff.

Choose a reason for hiding this comment

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

fixed

#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
Copy link
Contributor

Choose a reason for hiding this comment

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

PasswordAuthentication

Is this new feature backward-compatible? If the new config is not used, the default value should ensure sshd_config same as old behavior, so it does not break existing production usage easily. We can keep this file unchanged to test backward-compatible. If you need, you can add extra testcases (test output files).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is 100% backwards compatible. Not a single default is changed. The file you are commenting on is the result file for a test case that is changing every one of the configuration knobs. Previously password authentication couldn't be toggled, but now it can, so you see it being toggled by this test case.

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@prabhataravind
Copy link
Contributor

@bhouse-nexthop it looks like there is a test failure. Could you pls check?

=========================== short test summary info ============================
FAILED tests/hostcfgd/hostcfgd_ssh_server_test.py::TestHostcfgdSSHServer::test_hostcfgd_sshs_all_0_SSH_SERVER
============= 1 failed, 319 passed, 7 warnings in 91.13s (0:01:31) =============

@bradh352
Copy link

looks like the input file was changed by a different PR, I'll update to match

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: SSH configuration hardening

7 participants