Przejdź do treści

SSH

SSH (Secure Shell) is the application protocol used for the remote administration of CyberElements Bastion servers. It addresses the known shortcomings of the legacy protocols FTP, RSH, RCP and TELNET.

This chapter sets out the recommendations for hardening the OpenSSH configuration of the Mediation Controller and Edge Gateway servers. Removing the legacy services (telnet, rsh, rlogin, ftp) is covered in Installation and security maintenance.

Information

The ANSSI reference for this chapter is the technical note DAT-NT-007/ANSSI/SDE/NP "Recommandations pour un usage sécurisé d'(Open)SSH". It was last updated on 17 August 2015: unlike ANSSI-BP-028 (2022), it has not been revised since. The directives that have become obsolete in current versions of OpenSSH are pointed out below.

Summary

# Recommendation Mediation Controller Edge Gateway
R25 Protocol and cryptographic algorithms
R26 Authentication and user access control
R27 SSH key authentication and disabling of passwords
R28 Restriction of network and forwarding features
R29 Network listening and exposure of the SSH service
R30 Limitation of sessions and connection timeouts
R31 Banner and logging of SSH connections
R32 Size and robustness of host and user keys
R33 Entropy quality and uniqueness of host keys
R34 Advanced features not retained by default

Information

So as to limit direct changes to the main files shipped with OpenSSH, server hardening should be placed in a dedicated file /etc/ssh/sshd_config.d/00-cyberelements-bastion-hardening.conf.

Warning!

Before any change to the SSH configuration, keep an administration session open and have emergency console access available. After making changes, run sshd -t. Only reload the service if there is no error, then open a second session to validate before closing the first.

1
2
3
sshd -t
systemctl reload ssh
sshd -T

R25. Protocol and cryptographic algorithms

Applies to: Mediation Controller · Edge Gateway

SSHv1 is obsolete and has been removed from the OpenSSH code: only SSHv2 is now supported. The historical Protocol 2 directive is no longer recognised and must not be added to the configuration.

The encryption, integrity and key exchange algorithms must be limited to a robust core. The server configuration protects incoming connections; the client configuration applies when the server itself initiates an outgoing SSH connection.

Recommended server configuration in /etc/ssh/sshd_config.d/00-cyberelements-bastion-hardening.conf:

1
2
3
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512,sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org

Recommended system client configuration in /etc/ssh/ssh_config.d/00-cyberelements-bastion-hardening.conf:

1
2
3
4
5
6
7
Host *
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512,sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org
ForwardX11 no
ForwardX11Trusted no
StrictHostKeyChecking ask

Information

The proposed core keeps the hybrid post-quantum mechanisms available in current OpenSSH, as well as Curve25519 as a widely compatible fallback.

Warning!

An explicit list of algorithms can make certain older SSH clients or certain administration appliances incompatible. Before applying it in production, check the algorithms available and test the administration workstations actually in use.

1
2
3
ssh -Q kex
ssh -Q cipher
ssh -Q mac

For the RSA keys used in user or host authentication, a minimum size can be enforced:

1
RequiredRSASize 3072

Warning!

RequiredRSASize 3072 is classified "to be validated". Any existing RSA key of a smaller size would be rejected. Take an inventory of the keys used by administrators, maintenance accounts and any automated exchanges before applying it (see Classification of recommendations).

R26. Authentication and user access control

Applies to: Mediation Controller · Edge Gateway

Recommended configuration in the server hardening file:

1
2
3
4
5
6
7
8
PermitRootLogin no
PermitEmptyPasswords no
StrictModes yes
PermitUserEnvironment no
MaxAuthTries 4
LoginGraceTime 30
KbdInteractiveAuthentication no
UsePAM yes
  • PermitRootLogin no: direct SSH access to the root account is disabled;
  • PermitEmptyPasswords no: forbids any authentication with an empty password;
  • StrictModes yes: checks the permissions and owners of home directories and SSH files before accepting an authentication;
  • PermitUserEnvironment no: prevents a user from injecting environment variables through ~/.ssh/environment or authorized_keys;
  • KbdInteractiveAuthentication no: avoids exposing a second interactive mechanism equivalent to the password where it is not explicitly needed;
  • UsePAM yes: keeps PAM account and session controls in force, notably the pam_faillock policy defined in R10.

SSH access must be limited to authorised accounts only. A single main restriction model should be chosen (either by users or by groups) so as to avoid combinations that are hard to maintain:

1
2
3
AllowUsers admin1 admin2 systancia
# or, by group:
AllowGroups sudo

Information

A restriction by origin can be added directly in AllowUsers, for instance admin@192.168.17.0/24, where an administration network has been identified. Network filtering nonetheless remains the main control.

Warning!

In the case of an OVA carrying a systancia maintenance account, that account must remain covered by the access policy in line with the applicable support procedure. In cluster mode, if AllowUsers is used, the ipdiva-synchro account must also be kept where it is needed for synchronisation between nodes.

R27. SSH key authentication and disabling of passwords

Applies to: Mediation Controller · Edge Gateway

SSH key authentication should be preferred for administration accounts. Keys must be named after their holder, protected on the administrator's workstation and never shared between several people.

Recommended server configuration once the keys have been deployed and validated:

1
2
3
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no

Warning!

PasswordAuthentication no must only be applied once the public key of every authorised administrator has been deposited and validated. On a newly deployed machine, keep the administration session active, test a key-based connection in a second terminal, and only then disable password authentication.

Audit of the authorised public keys:

1
find /root /home -maxdepth 3 -name authorized_keys -type f -exec echo {} \; -exec cat {} \;

Checking the effective configuration:

1
sshd -T | grep -i -E 'passwordauthentication|kbdinteractiveauthentication|pubkeyauthentication|authorizedkeysfile'

Information

Where the workstations and the security policy allow it, keys protected by a FIDO hardware authenticator can also be considered (types ed25519-sk or ecdsa-sk). This measure remains optional and must be integrated into the administration policy.

R28. Restriction of network and forwarding features

Applies to: Mediation Controller · Edge Gateway

The forwarding mechanisms provided by SSH are not required for the standard administration role of CyberElements Bastion and can turn the server into a network relay. They must be neutralised unless a need is explicitly identified and validated.

1
2
3
4
5
6
7
8
9
DisableForwarding yes
X11Forwarding no
AllowAgentForwarding no
AllowTcpForwarding no
AllowStreamLocalForwarding no
GatewayPorts no
PermitTunnel no
Compression no
TCPKeepAlive no

Information

DisableForwarding yes neutralises X11, agent, TCP and Unix socket forwarding. The individual directives are kept so as to make the expected policy explicit. PermitTunnel no deals separately with network-level tunnels.

Warning!

If an operational procedure or a product mechanism genuinely requires SSH forwarding, DisableForwarding yes must not be used as it stands. The need must then be identified precisely and only the strictly necessary functions re-enabled.

Classification

To be validated: AllowTcpForwarding no, to be checked against maintenance tools and cluster synchronisation. See the Classification of recommendations appendix.

R29. Network listening and exposure of the SSH service

Applies to: Mediation Controller · Edge Gateway

The SSH service must be reachable only from authorised administration networks or addresses. Where several interfaces are present, listening should be limited to the address dedicated to administration:

1
ListenAddress A.B.C.D:22

Restricting exposure must be complemented by the firewall rules, network ACLs and, where possible, a dedicated administration VLAN. The SSH service must not be exposed directly to the Internet without source address filtering.

Information

Changing the SSH port can reduce the noise generated by automated scans, but it is not in itself a security measure. The real control rests on network filtering, robust authentication, limiting the authorised accounts, and logging.

Warning!

Where the non-standard historical port 22123 is kept in a Standalone architecture, that choice must be documented and reflected in the filtering rules and administration procedures. Changing the port is not retained for Cluster architectures where it is incompatible with the synchronisation or support mechanisms.

Classification

To be validated: Dedicated SSH port < 1024 (ANSSI nuance). See the Classification of recommendations appendix.

R30. Limitation of sessions and connection timeouts

Applies to: Mediation Controller · Edge Gateway

1
2
3
4
ClientAliveInterval 300
ClientAliveCountMax 2
MaxSessions 2
MaxStartups 10:30:60

ClientAliveInterval and ClientAliveCountMax make it possible to detect and close a connection whose client no longer responds to the messages sent over the encrypted channel. They are not a mechanism for closing a merely idle user session: a client still connected answers keep-alive messages even if the user types no command.

Closing idle shells is handled through TMOUT in Accounts and privileges. The ChannelTimeout directive can be used to impose an inactivity delay at SSH channel level, but it is classified "to be validated", because the session type also covers remote commands, SCP and SFTP and can therefore interrupt long-running operations.

1
2
# Example, to be validated against actual usage:
ChannelTimeout session=15m

Information

OpenSSH also applies per-source-address penalties to certain abnormal behaviours or repeated failures. That native mechanism must stay active; it complements pam_faillock and fail2ban without replacing them.

R31. Banner and logging of SSH connections

Applies to: Mediation Controller · Edge Gateway

1
2
3
4
5
Banner /etc/issue.net
LogLevel VERBOSE
PrintLastLog yes
UseDNS no
DebianBanner no
  • Banner /etc/issue.net: reuses the generic banner defined in R18;
  • LogLevel VERBOSE: improves the traceability of authentications and key fingerprints without enabling the DEBUG levels, too verbose for production;
  • PrintLastLog yes: shows the user the date of their last interactive login;
  • UseDNS no: avoids reverse DNS resolution when the connection is established;
  • DebianBanner no: avoids adding the distribution suffix to the protocol version banner presented by the server.

After reloading, SSH events can be checked with:

1
journalctl -u ssh -n 100 --no-pager

R32. Size and robustness of host and user keys

Applies to: Mediation Controller · Edge Gateway

For new administration keys, Ed25519 is preferred where the cryptographic policy and tooling allow it. RSA remains a robust compatibility mechanism with a size of at least 3072 bits; 4096 bits is recommended for new RSA keys.

Examples of generating a user key protected by a passphrase:

1
2
ssh-keygen -t ed25519 -a 64 -f ~/.ssh/id_ed25519
ssh-keygen -t rsa -b 4096 -a 64 -f ~/.ssh/id_rsa

Information

The -a option increases the number of rounds of the derivation function used to protect a private key when a passphrase is set. It does not replace the requirement for a strong passphrase and proper protection of the administration workstation.

The host keys present on the server can be inventoried and checked with:

1
2
ls -l /etc/ssh/ssh_host_*_key.pub
for k in /etc/ssh/ssh_host_*_key.pub; do ssh-keygen -lf "$k"; done

DSA keys must not be used or re-enabled. ECDSA keys remain usable where required by the cryptographic policy or by compatibility constraints, but they are no longer the primary choice for new keys in this guide.

Warning!

Any rotation of an SSH host key changes the fingerprint presented to administrators and can trigger a host key changed alert. A rotation must be planned, documented and accompanied by a controlled update of the known_hosts files concerned.

Classification

To be validated: Preferring ECDSA over RSA. See the Classification of recommendations appendix.

R33. Entropy quality and uniqueness of host keys

Applies to: Mediation Controller · Edge Gateway

The robustness of host keys depends on the quality of the random generator at the time they are created. In virtualised environments and cloned images, the essential point is to guarantee that each instance has its own random state and unique host keys.

Useful checks:

1
2
3
4
systemctl status systemd-random-seed.service
dmesg | grep -Ei 'random|rng|virtio'
ls -l /dev/hwrng 2>/dev/null
cat /proc/sys/kernel/random/entropy_avail

Information

The entropy_avail value is only an indicator of the kernel's entropy pool and must not be used on its own as a criterion for deciding whether a key is sufficiently safe. Current kernels have reinforced initialisation and randomness collection mechanisms.

R34. Advanced features not retained by default

Applies to: Mediation Controller · Edge Gateway

Several features described by the ANSSI note remain possible but are not retained by default for CyberElements Bastion. They are documented so that their exclusion is explicit.

  • Authentication agent forwarding for SSH hops: not retained by default, in line with AllowAgentForwarding no and DisableForwarding yes;
  • OpenSSH PKI and key certificates: to be reserved for organisations that already have an SSH certification authority and a certificate lifecycle management process;
  • Publication of SSH fingerprints through DNS (SSHFP): depends on the deployment and DNSSEC validation; not retained as a product requirement;
  • chroot confinement for dedicated SFTP accounts: not relevant for the standard administration of CyberElements Bastion, whose SSH access relies on named administration accounts.

Final validation of the SSH configuration

1
2
3
4
sshd -t
sshd -T | sort
systemctl reload ssh
journalctl -u ssh -n 100 --no-pager

Warning!

The administration session used to carry out the hardening must only be closed once a new SSH connection, sudo elevation, the necessary maintenance accounts and, where applicable, synchronisation between nodes have been validated.