Skip to content

Commit

Permalink
ipnlocal: log failure to get ssh host keys
Browse files Browse the repository at this point in the history
When reporting ssh host keys to control, log a warning
if we're unable to get the SSH host keys.

Updates tailscale/escalations#21

Signed-off-by: Percy Wegmann <percy@tailscale.com>
  • Loading branch information
oxtoacart committed Jan 30, 2024
1 parent 9744ad4 commit fad6bae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion ipn/ipnlocal/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -4125,7 +4125,11 @@ func (b *LocalBackend) applyPrefsToHostinfoLocked(hi *tailcfg.Hostinfo, prefs ip
// TODO(bradfitz): this is called with b.mu held. Not ideal.
// If the filesystem gets wedged or something we could block for
// a long time. But probably fine.
sshHostKeys = b.getSSHHostKeyPublicStrings()
var err error
sshHostKeys, err = b.getSSHHostKeyPublicStrings()
if err != nil {
b.logf("warning: unable to get SSH host keys, SSH will appear as disabled for this node: %v", err)
}
}
hi.SSH_HostKeys = sshHostKeys

Expand Down
12 changes: 8 additions & 4 deletions ipn/ipnlocal/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,16 @@ func (b *LocalBackend) getSystemSSH_HostKeys() (ret map[string]ssh.Signer) {
return ret
}

func (b *LocalBackend) getSSHHostKeyPublicStrings() (ret []string) {
signers, _ := b.GetSSH_HostKeys()
func (b *LocalBackend) getSSHHostKeyPublicStrings() ([]string, error) {
signers, err := b.GetSSH_HostKeys()
if err != nil {
return nil, err
}
var keyStrings []string
for _, signer := range signers {
ret = append(ret, strings.TrimSpace(string(ssh.MarshalAuthorizedKey(signer.PublicKey()))))
keyStrings = append(keyStrings, strings.TrimSpace(string(ssh.MarshalAuthorizedKey(signer.PublicKey()))))
}
return ret
return keyStrings, nil
}

// tailscaleSSHEnabled reports whether Tailscale SSH is currently enabled based
Expand Down
4 changes: 2 additions & 2 deletions ipn/ipnlocal/ssh_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"tailscale.com/tailcfg"
)

func (b *LocalBackend) getSSHHostKeyPublicStrings() []string {
return nil
func (b *LocalBackend) getSSHHostKeyPublicStrings() ([]string, error) {
return nil, nil
}

func (b *LocalBackend) getSSHUsernames(*tailcfg.C2NSSHUsernamesRequest) (*tailcfg.C2NSSHUsernamesResponse, error) {
Expand Down

0 comments on commit fad6bae

Please sign in to comment.