feat: not fail on non-default ports - #6895
Merged
tonistiigi merged 1 commit intoJun 26, 2026
Merged
Conversation
Signed-off-by: Giles Cope <gilescope@gmail.com>
gilescope
force-pushed
the
giles-fix-sshkeyscan-nonstandard-port
branch
from
June 24, 2026 05:31
deef161 to
6678be5
Compare
AkihiroSuda
approved these changes
Jun 24, 2026
tonistiigi
approved these changes
Jun 26, 2026
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.
Description
SSHKeyScanbuilds aknown_hostsentry from the scanned host key butdiscards the port, always emitting a bare hostname:
For a server reachable on a non-standard port (e.g.
git.example.com:2222)this stores the key under
git.example.com, butsshlooks it up under[git.example.com]:2222per theSSH_KNOWN_HOSTSformat insshd(8). Theentry never matches, so host-key verification fails for any git source or
SSH endpoint on a non-22 port.
Fix
Render non-standard ports as
[host]:port; keep the default port (22) as abare hostname (matching
ssh-keyscanand the known_hosts format). Theformatting is extracted into a small pure helper,
knownHostsServerID, whichis unit-tested directly (a full SSH handshake is impractical to fake in a
unit test).
Test
go test ./util/sshutil/— new table test covers default port, empty port,non-standard port, and IPv6 (default and non-standard).