Skip to content

Commit

Permalink
knownhosts hostname fix (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb-mp authored May 21, 2024
1 parent 1b23c72 commit 2dff216
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/ssh/hostkey/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ func wrapCallback(hkc ssh.HostKeyCallback, path string, permissive, hash bool) s
return fmt.Errorf("failed to open ssh known_hosts file %s for writing: %w", path, err)
}

knownHostsEntry := knownhosts.Normalize(remote.String())
knownHostsEntry := ""
if t, ok := remote.(*net.TCPAddr); ok && t.IP.IsUnspecified() {
// fallback to hostname if remote addr is unspecified
// see: https://github.com/k0sproject/k0sctl/issues/717
knownHostsEntry = knownhosts.Normalize(hostname)
} else {
knownHostsEntry = knownhosts.Normalize(remote.String())
}

if hash {
knownHostsEntry = knownhosts.HashHostname(knownHostsEntry)
}
Expand Down

0 comments on commit 2dff216

Please sign in to comment.