Repository navigation
fix(sshconfig): apply algorithm list modifiers to the built-in defaults - #513
Merged
Merged
Conversation
The +, - and ^ modifiers of the algorithm lists worked against `ssh -Q <key>` from the local ssh binary: every algorithm that binary supports, in OpenSSH's table order rather than any preference order. That starts with diffie-hellman-group1-sha1, so KexAlgorithms +x made rig prefer the weakest key exchanges. It also says nothing about rig, which negotiates through x/crypto, not the ssh binary. Without an ssh binary, as in a container, the lookup fell back to constants it never reached: defaultList was called with "KexAlgorithms" while its switch only knew "kexalgorithms", so the modifiers worked against an empty list. The defaults now come from the platform's built-in default config, the same lists rig uses when nothing is configured, matched without regard to case and through the deprecated HostbasedKeyTypes and PubkeyAcceptedKeyTypes names that the Windows defaults use. Importing sshconfig no longer runs ssh at package init. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The - modifier appended a default once for every pattern it did not match, so -a,b listed each remaining default twice. It also passed the pattern as the value to patternMatch, so a wildcard such as -ecdh-* removed nothing. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
There was a problem hiding this comment.
🟡 Changes recommended
Removing all default algorithms leaves an empty field that the parser repopulates with built-in defaults, silently undoing the removal; the setter needs to reject empty results and include a parser regression test.
1 open issue
What changed in this PR
This PR makes SSH algorithm-list modifiers use rig’s built-in defaults rather than the local OpenSSH binary’s supported algorithms, preserving rig’s default preferences.
Changes:
- Resolve default lists case-insensitively, including deprecated aliases, without running SSH commands at package initialization.
- Correct multi-pattern removal and wildcard matching.
- Add regression tests for default lookup and modifiers, and make existing removal checks unconditional.
| File | Description |
|---|---|
sshconfig/setterbuilders.go |
Fix wildcard matching and prevent duplicate entries during removal. |
sshconfig/set_test.go |
Run removal assertions unconditionally against built-in defaults. |
sshconfig/parser_test.go |
Add end-to-end coverage for algorithm-list modifiers. |
sshconfig/defaults.go |
Replace OpenSSH queries with case-insensitive built-in default lookup. |
sshconfig/defaults_test.go |
Test default lists, deprecated aliases, and unknown keys. |
Review effort: Balanced
With wildcards now matching, -* empties the list. An empty field reads as unset, so the built-in defaults filled it back in and quietly undid the removal. ssh accepts the line but is left with nothing to negotiate, so refuse it where the config says so. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes how the
+,-and^modifiers of the ssh_config algorithm lists (KexAlgorithms,Ciphers,MACs,HostKeyAlgorithms,PubkeyAcceptedAlgorithms,HostbasedAcceptedAlgorithms,CASignatureAlgorithms) build their result. Four bugs, all in that path:ssh -Q <key>. That is every algorithm the local ssh binary supports, in OpenSSH's table order, not a preference order. It starts withdiffie-hellman-group1-sha1, soKexAlgorithms +xmade rig prefer the weakest key exchanges. It also says nothing about rig, which negotiates through x/crypto rather than the ssh binary.defaultListwas called with"KexAlgorithms"but its switch only knew"kexalgorithms", so in a container without ssh the modifiers worked against an empty list.-a,bduplicated the defaults. Each default was appended once per pattern it did not match.-wildcards never matched. The pattern was passed topatternMatchas the value, so-ecdh-*removed nothing.The modifiers now work against the platform's built-in default config, the same lists rig already uses when nothing is configured. Keys match without regard to case and through the deprecated
HostbasedKeyTypes/PubkeyAcceptedKeyTypesnames the Windows defaults use. As a side effect, importingsshconfigno longer runsssh -Vandssh -Qat package init.1 and 2 are one change, since fixing 1 removes the code 2 was in. 3 and 4 are a second commit.
Found while checking whether release-0.x #512 (FIPS / X25519 key exchange) needs a v2 port. It doesn't for the default path: v2 always sends the built-in
KexAlgorithmslist, which has nomlkem768x25519-sha256, and in FIPS mode x/crypto narrows it to the NIST ECDH curves.Tests
TestDefaultList: every modifier key has a non-empty built-in list, case-insensitive, aliases resolve.TestParserAlgorithmListModifiers:+,^, multi-pattern-and wildcard-end to end through the parser, against the built-in list. With the old code all four fail; with only the new base, the two-cases still fail.-test inTestSetterField*no longer skips itself when the runner'sssh -Qlist is short.🤖 Generated with Claude Code