From 0d9bd33b648695e1934e5a5a0e477221b72728ff Mon Sep 17 00:00:00 2001 From: Takwa Date: Wed, 11 Nov 2026 12:55:15 +0100 Subject: [PATCH] hardening: offer post-quantum hybrid key exchange in sshd 99-hardening.conf pinned KexAlgorithms to curve25519 and DH group16 only, so OpenSSH 10 clients warn that the connection is not using a post-quantum key exchange. Put mlkem768x25519-sha256 and sntrup761x25519-sha512@openssh.com ahead of the existing list, keeping the existing algorithms after them. sshd refuses a KexAlgorithms name it does not know, and mlkem needs OpenSSH 9.9 while Ubuntu 24.04 ships 9.6p1, so each PQ algorithm is offered only where `ssh -Q kex` on the box lists it: sntrup761x25519 on the ipfs_nodes boxes, both on indexers-chic1 (Debian 13, OpenSSH 10.0). Co-Authored-By: Claude Opus 5.5 --- roles/hardening/defaults/main.yml | 7 +++++++ roles/hardening/tasks/main.yml | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/roles/hardening/defaults/main.yml b/roles/hardening/defaults/main.yml index 005c850..4998a2a 100644 --- a/roles/hardening/defaults/main.yml +++ b/roles/hardening/defaults/main.yml @@ -12,3 +12,10 @@ hardening_removed_accounts: # yes, which beats 99-hardening.conf) and set ssh_pwauth: false. Off by default # so the IPFS boxes are left as they are; group_vars/indexers turns it on. hardening_fix_cloud_init_sshd: false + +# Post-quantum hybrid key exchange for sshd, in order of preference, ahead of +# the classical KexAlgorithms. Each is offered only where the box's OpenSSH has +# it (tasks/main.yml): mlkem768x25519-sha256 needs 9.9, sntrup761x25519 8.5. +hardening_pq_kex_algorithms: + - mlkem768x25519-sha256 + - sntrup761x25519-sha512@openssh.com diff --git a/roles/hardening/tasks/main.yml b/roles/hardening/tasks/main.yml index f05056d..c687be7 100644 --- a/roles/hardening/tasks/main.yml +++ b/roles/hardening/tasks/main.yml @@ -261,7 +261,21 @@ notify: Reload sshd when: hardening_fix_cloud_init_sshd | bool +# Post-quantum hybrid key exchange, offered ahead of the classical algorithms +# so OpenSSH 10 clients stop warning. sshd refuses to start on a name it does +# not know, and mlkem768x25519-sha256 needs OpenSSH 9.9: Ubuntu 24.04 has 9.6 +# (sntrup761x25519 only), Debian 13 has 10.0. So offer only the ones this +# box's OpenSSH lists; the client and sshd come from the same source package. +- name: List the key exchange algorithms this box's OpenSSH supports + ansible.builtin.command: + argv: [ssh, -Q, kex] + register: ssh_supported_kex + changed_when: false + check_mode: false + - name: Harden sshd configuration + vars: + hardening_pq_kex_supported: "{{ hardening_pq_kex_algorithms | select('in', ssh_supported_kex.stdout_lines) | list }}" ansible.builtin.copy: dest: /etc/ssh/sshd_config.d/99-hardening.conf mode: "0644" @@ -286,7 +300,7 @@ ClientAliveInterval 300 ClientAliveCountMax 2 # Modern algorithms only - KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512 + KexAlgorithms {{ (hardening_pq_kex_supported + ['curve25519-sha256', 'curve25519-sha256@libssh.org', 'diffie-hellman-group16-sha512']) | join(',') }} Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com validate: '/usr/sbin/sshd -t -f %s'