Repository navigation
feat(ssh): fallback to GlobalKnownHostsFile - #372
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates SSH host key verification to fall back to GlobalKnownHostsFile when no usable user known_hosts path is resolved, aligning behavior more closely with OpenSSH config semantics.
Changes:
- Add fallback resolution logic from
UserKnownHostsFiletoGlobalKnownHostsFileinConnection.hostkeyCallback. - Add tests covering the global fallback path and the “no known_hosts anywhere” error path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
protocol/ssh/connection.go |
Adds fallback to global known_hosts paths when user known_hosts is not selected. |
protocol/ssh/connection_test.go |
Adds unit tests for global known_hosts fallback and for the no-known-hosts error case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… is absent Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
kke
force-pushed
the
ssh-config-global-known-hosts
branch
from
June 4, 2026 13:41
a753a32 to
22c7fac
Compare
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
protocol/ssh/connection.go:368
- The user known_hosts selection picks the first
UserKnownHostsFileentry that expands, even if it doesn’t exist yet. BecauseKnownHostsFileCallbackalways creates the file (ensureFile), this means the new GlobalKnownHostsFile fallback won’t trigger in the common/default case (e.g.~/.ssh/known_hostsmissing) — it will create the user file instead. To match the PR intent (“fallback when user known_hosts is absent”), only select a user known_hosts path if it already exists (or is/dev/null), otherwise keep searching and allow fallback to global files.
for _, f := range c.sshConfig.UserKnownHostsFile {
if strings.EqualFold(f, "none") {
// "none" is the OpenSSH special value meaning "ignore user known_hosts"
break
}
log.Trace(ctx, "trying known_hosts file from ssh config", log.KeyHost, c, log.KeyFile, f)
exp, err := homedir.Expand(f)
if err == nil {
khPath = exp
break
}
}
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
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.
Uses GlobalKnownHostsFile when user known_hosts is absent