From fad6bae764e00f89b2e0f546075df329e1a1ec52 Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Tue, 30 Jan 2024 15:49:02 -0600 Subject: [PATCH] ipnlocal: log failure to get ssh host keys 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 --- ipn/ipnlocal/local.go | 6 +++++- ipn/ipnlocal/ssh.go | 14 +++++++++----- ipn/ipnlocal/ssh_stub.go | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 1312e37dc..bdaef23a2 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -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 diff --git a/ipn/ipnlocal/ssh.go b/ipn/ipnlocal/ssh.go index 7a6000a56..fbeb19bd1 100644 --- a/ipn/ipnlocal/ssh.go +++ b/ipn/ipnlocal/ssh.go @@ -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() - for _, signer := range signers { - ret = append(ret, strings.TrimSpace(string(ssh.MarshalAuthorizedKey(signer.PublicKey())))) +func (b *LocalBackend) getSSHHostKeyPublicStrings() ([]string, error) { + signers, err := b.GetSSH_HostKeys() + if err != nil { + return nil, err } - return ret + var keyStrings []string + for _, signer := range signers { + keyStrings = append(keyStrings, strings.TrimSpace(string(ssh.MarshalAuthorizedKey(signer.PublicKey())))) + } + return keyStrings, nil } // tailscaleSSHEnabled reports whether Tailscale SSH is currently enabled based diff --git a/ipn/ipnlocal/ssh_stub.go b/ipn/ipnlocal/ssh_stub.go index abdc65c74..7875ae311 100644 --- a/ipn/ipnlocal/ssh_stub.go +++ b/ipn/ipnlocal/ssh_stub.go @@ -11,8 +11,8 @@ "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) {