Skip to content

feat(ssh): fallback to GlobalKnownHostsFile - #372

Merged
kke merged 16 commits into
mainfrom
ssh-config-global-known-hosts
Jun 5, 2026
Merged

kke merged 16 commits into
mainfrom
ssh-config-global-known-hosts

Conversation

@kke

@kke kke commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Uses GlobalKnownHostsFile when user known_hosts is absent

@kke kke changed the title feat(ssh): fall through to GlobalKnownHostsFile when user known_hosts… feat(ssh): fallback to GlobalKnownHostsFile Jun 3, 2026
@kke
kke requested a review from Copilot June 3, 2026 20:46

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.

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 UserKnownHostsFile to GlobalKnownHostsFile in Connection.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.

Comment thread protocol/ssh/connection.go Resolved
… is absent

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke
kke force-pushed the ssh-config-global-known-hosts branch from a753a32 to 22c7fac Compare June 4, 2026 13:41
@kke
kke requested a review from Copilot June 4, 2026 13:41

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/hostkey/callbacks.go Resolved
Comment thread protocol/ssh/connection.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/connection.go Resolved
Comment thread protocol/ssh/hostkey/callbacks.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

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 UserKnownHostsFile entry that expands, even if it doesn’t exist yet. Because KnownHostsFileCallback always creates the file (ensureFile), this means the new GlobalKnownHostsFile fallback won’t trigger in the common/default case (e.g. ~/.ssh/known_hosts missing) — 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
		}
	}

Comment thread protocol/ssh/hostkey/callbacks_test.go Resolved
Comment thread protocol/ssh/hostkey/callbacks_test.go Resolved
Comment thread protocol/ssh/hostkey/callbacks_test.go Resolved
Comment thread protocol/ssh/hostkey/callbacks_test.go Resolved
Comment thread protocol/ssh/connection_test.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread protocol/ssh/hostkey/callbacks.go Resolved
Comment thread protocol/ssh/connection.go Resolved
Comment thread protocol/ssh/hostkey/callbacks_test.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread protocol/ssh/connection.go Resolved
Comment thread protocol/ssh/connection.go Resolved
Comment thread protocol/ssh/connection_test.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread protocol/ssh/connection.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread protocol/ssh/hostkey/callbacks.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread protocol/ssh/hostkey/callbacks.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread protocol/ssh/hostkey/callbacks.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/hostkey/callbacks.go Resolved
Comment thread protocol/ssh/connection.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread protocol/ssh/hostkey/callbacks.go Resolved
Comment thread protocol/ssh/connection.go Resolved
Comment thread protocol/ssh/connection_test.go Resolved
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread protocol/ssh/connection.go Resolved
kke added 2 commits June 5, 2026 17:18
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread protocol/ssh/connection.go Resolved
@kke
kke marked this pull request as ready for review June 5, 2026 14:30
@kke
kke merged commit 91ac195 into main Jun 5, 2026
13 checks passed
@kke
kke deleted the ssh-config-global-known-hosts branch June 5, 2026 14:30
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.

2 participants