mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-05 16:12:20 -08:00
ssh/tailssh: stop killing session processes on graceful disconnects
Monitor teardown SIGHUPed and SIGKILLed every remembered child group
when the transport closed. sshd signals nothing at a non-PTY session
end; background jobs with redirected stdio survive and reparent to
init. Clients rely on that: VS Code Remote-SSH starts its remote
server as a plain background job in the session's group and expects
it to outlive connection drops, and tailscale upgrades run as
non-PTY execs whose work should survive a daemon restart.
Use an explicit graceful monitor close to preserve session jobs on
ordinary disconnect and daemon shutdown. Close PTY masters normally,
letting the terminal driver signal the foreground group, but do not
signal non-PTY jobs. Remove Linux Pdeathsig from session children;
forwarding children retain it and always die with the connection.
Commit duration and recording-failure termination to the monitor
before publishing cancellation or writing the termination message.
The monitor owns per-session HUP-to-KILL escalation even after the
leader exits or the connection closes. Revocation arms connection-wide
cleanup. Pin every termination target's leader until after SIGKILL,
including during teardown, so group signaling cannot hit reused PIDs.
Select teardown targets explicitly and leave graceful survivors alone.
Unexpected RPC loss fails closed. If a termination mandate cannot be
delivered, close the RPC rather than subsequently requesting graceful
teardown; this may also kill sibling jobs on a broken channel. Keep
both the escalation and monitor shutdown waits bounded.
Add coverage for default-HUP graceful survivors, actual duration and
recording-failure termination followed by immediate disconnect, sibling
survival, HUP-exiting leaders with immune group members, broken RPCs,
and leader pinning through teardown's SIGKILL pass.
Fixes #22076
Signed-off-by: James Tucker <[email protected]>
Change-Id: I70b4ef40035330dd542d256ba79d889a12426a74
(cherry picked from commit 1334899864)
Signed-off-by: James Tucker <[email protected]>
This commit is contained in:
1 parent
b571dac619
commit
fb7712ece2
19 files changed
+798
-231
No files matched your search
@@ -12,16 +12,15 @@ import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// monChildAttr returns the SysProcAttr for one monitor child. A ctty
|
||||
// child gets Setsid+Setctty with the PTY child endpoint as fd 0; Setpgid is
|
||||
// set only for non-ctty children. Pdeathsig is advisory: it fires on
|
||||
// the exit of the creating thread, not the process, per golang/go#27505.
|
||||
// monChildAttr returns process attributes for a session child.
|
||||
// With ctty, the child starts a session with fd 0 as its controlling terminal.
|
||||
// Otherwise it starts a process group.
|
||||
// Pdeathsig is unset so the child can survive monitor exit.
|
||||
func monChildAttr(ctty bool) *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{
|
||||
Setpgid: !ctty,
|
||||
Setsid: ctty,
|
||||
Setctty: ctty,
|
||||
Pdeathsig: unix.SIGHUP,
|
||||
Setpgid: !ctty,
|
||||
Setsid: ctty,
|
||||
Setctty: ctty,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +36,9 @@ func scrubFds() error {
|
||||
return scrubFdsByScan("/proc/self/fd")
|
||||
}
|
||||
|
||||
// fwdChildAttr returns the SysProcAttr for a one-shot forwarding child
|
||||
// whose identity must be applied, that is a root monitor's child. The
|
||||
// Credential carries the connection's bound identity from ma. The child
|
||||
// leads its own group so the op deadline and teardown can kill the
|
||||
// whole group, and Pdeathsig is set as in monChildAttr.
|
||||
// fwdChildAttr returns process attributes for a forwarding child.
|
||||
// The child runs with ma's credentials in its own process group.
|
||||
// Pdeathsig sends SIGHUP when the creating thread exits. See golang/go#27505.
|
||||
func fwdChildAttr(ma monitorArgs) *syscall.SysProcAttr {
|
||||
return &syscall.SysProcAttr{
|
||||
Credential: &syscall.Credential{
|
||||
|
||||
Reference in new issue
Block a user