Skip to content

[release-0.x] fix: offer no X25519 key exchanges when the curve is unusable - #512

Merged
kke merged 1 commit into
k0sproject:release-0.xfrom
smerkviladze:release-0.x-bop-7172-fips-kex
Nov 2, 2026
Merged

kke merged 1 commit into
k0sproject:release-0.xfrom
smerkviladze:release-0.x-bop-7172-fips-kex

Conversation

@smerkviladze

Copy link
Copy Markdown

A FIPS 140-only build of a rig v0.21 consumer cannot open an SSH connection to a host whose sshd supports mlkem768x25519-sha256. OpenSSH 10.0 made that algorithm the default key agreement, and Ubuntu 26.04 ships sshd 10.2p1 with it first in the list, so every such host is unreachable.

The failure:

ssh: handshake failed: curve25519: crypto/ecdh: use of X25519 is not allowed in FIPS 140-only mode

Cause, from the sources:

  • crypto/ecdh refuses X25519 under GODEBUG=fips140=only, and toolchains that route crypto through an external FIPS module refuse it whenever that module is active.
  • x/crypto/ssh (v0.48.0) keeps mlkem768x25519-sha256 first in its default key exchange list in FIPS mode too (its kex.go notes it works with fips140=on but not fips140=only).
  • SSH negotiation takes the first client-listed algorithm the server supports, so the server picks the hybrid exchange and the client fails on the X25519 half, even though ecdh-sha2-nistp256 was in the same offer.
  • rig v0.21 exposes no way to set ssh.ClientConfig.KeyExchanges, so consumers cannot work around it.

Fix

clientConfig probes X25519 once per process through crypto/ecdh. When the curve is refused, KeyExchanges is set to ssh.SupportedAlgorithms().KeyExchanges without the X25519 based entries, in x/crypto's order; ssh.Config.SetDefaults then drops what the current mode does not support. When the curve works, nothing is configured and x/crypto keeps its defaults, so non-FIPS behaviour is unchanged.

Verification

  • Unit tests: the X25519 probe is a variable, as agentSignerSource is, and two tests cover both branches.

  • End to end, with a FIPS toolchain (Go 1.26.6 with an OpenSSL FIPS backend, X25519 refused) against an Ubuntu 26.04 sshd (OpenSSH 10.2p1, default config), sshd at LogLevel DEBUG1:

    build result
    FIPS, rig v0.21.11 handshake fails, sshd: `kex: algorithm: mlkem768x25519-sha255
    FIPS, this branch connects, sshd: kex: algorithm: ecdh-sha2-nistp256, Accepted publickey
    stock Go, this branch connects, kex: algorithm: mlkem768x25519-sha256 (fix inactive)

All three also connect to the same sshd started with -o KexAlgorithms=-mlkem768x25519-sha256.

Tracked in BOP-7172.

A FIPS 140-only build refuses X25519, but x/crypto/ssh still offers
mlkem768x25519-sha256 first, so a server that accepts it picks it and
the handshake fails even though usable algorithms were offered too.
Probe the curve once and, when it is refused, configure the supported
key exchanges without the X25519 ones.

Signed-off-by: Sopho Merkviladze <smerkviladze@mirantis.com>
@kke
kke requested a balanced review from Copilot November 2, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the SSH fallback when FIPS restrictions make X25519 unavailable.

No open issues 🎉

What changed in this PR

This release-0.x fix allows SSH connections when FIPS restrictions make X25519 unavailable, while preserving the default key exchange behavior when X25519 works.

Changes:

  • Probe X25519 availability once per process.
  • Exclude X25519-based key exchanges when the probe fails, preserving the remaining supported algorithms’ order.
  • Add tests for both availability outcomes.
File Description
ssh.go Adds the cached X25519 probe and conditional key exchange filtering.
ssh_test.go Tests unchanged defaults when X25519 is available and filtered offers when unavailable.

Review effort: Balanced

@kke

kke commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

in rig v2 these come from the default ssh_config entries :

None of them have that algorithm. I don't know if we need to error out if user has it in their config.

@kke
kke merged commit 2449194 into k0sproject:release-0.x Nov 2, 2026
7 checks passed
@smerkviladze
smerkviladze deleted the release-0.x-bop-7172-fips-kex branch November 2, 2026 09:59
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.

3 participants