ssh/tailssh: terminate sessions when tailscaled shutsdown

Ideally we would re-establish these sessions when tailscaled comes back
up, however we do not do that yet so this is better than leaking the
sessions.

Updates #3802

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2022-05-28 04:33:46 -07:00
committed by Maisem Ali
parent 760740905e
commit 7cd8c3e839
2 changed files with 52 additions and 9 deletions

View File

@@ -81,6 +81,9 @@ type SSHServer interface {
// so that existing sessions can be re-evaluated for validity
// and closed if they'd no longer be accepted.
OnPolicyChange()
// Shutdown is called when tailscaled is shutting down.
Shutdown()
}
type newSSHServerFunc func(logger.Logf, *LocalBackend) (SSHServer, error)
@@ -346,6 +349,9 @@ func (b *LocalBackend) Shutdown() {
b.mu.Lock()
b.shutdownCalled = true
cc := b.cc
if b.sshServer != nil {
b.sshServer.Shutdown()
}
b.closePeerAPIListenersLocked()
b.mu.Unlock()