Commit Graph
2 Commits
Author SHA1 Message Date
Bazyli Brzoska aeb0f740f5 ssh/tailssh: report command exit status through login on macOS
On macOS, the incubator execs /usr/bin/login to run non-interactive
commands so that they run in a macOS login session (see #4939). But
macOS login runs the program as a child and exits 0 regardless of how
it exited, so every command over Tailscale SSH to a Mac reported
success to the client: "ssh mac 'exit 7'" exited 0. The same happened
to shells without a TTY, such as "ssh -T mac < script".

For those sessions, run login as a child instead, telling it to run
"tailscaled be-child ssh-login-cmd", which runs the user's shell as
login would have (as a login shell, with argv[0] "-zsh") and writes its
exit status to a file created by the incubator and owned by the local
user. login closes inherited descriptors, so a pipe can't be used. The
helper unlinks the file as soon as it starts, and the incubator reads
the status through its own descriptor and exits with it, or with
login's status (or 1) if none was recorded, so an unknown result is
never reported as success.

login stays in the incubator's process group, as it did when the
incubator exec'd into it, so the ssh-monitor's SIGHUP and SIGKILL to
the session's group still reach it and the command. With a TTY that
group is the terminal's foreground group, so the incubator ignores the
terminal's SIGINT and SIGQUIT while it waits.

Interactive shells with a TTY and SFTP still exec into login, and other
platforms are unchanged.

Also run the SSH integration tests on macOS in CI, as root and as a
regular user, and fix the tests that assumed /proc or Linux's stty -a
output.

Fixes #18256

RELNOTE: Tailscale SSH on macOS now reports the exit status of
non-interactive commands instead of always exiting 0.

Change-Id: I3fb4f5201667a5a218b996e0d9762429337857eb
Signed-off-by: Bazyli Brzoska <[email protected]>
2026-12-04 20:04:46 -08:00
Brad Fitzpatrick 05abd5d73e ssh/tailssh, tstest/natlab/vmtest: expand Tailscale SSH test coverage
Add Docker integration tests for TCP and Unix forwarding, pty size,
resize and modes, session env, envknobs, x11 rejection, session
teardown, SessionDuration, policy changes and RuleExpires on active
sessions, Shutdown, host keys and utmp, and run every integrationtest
test in the Dockerfile. Extend the vmtest SSH tests to use real
OpenSSH clients across the tailnet for pty, sftp/scp, agent and port
forwarding, AcceptEnv, ControlMaster, large transfers, banners, user
mapping, revocation, check mode (via a new testcontrol handler),
recording, and the tailscale ssh CLI. Fix make sshintegrationtest,
which only ever tested one image and always exited 0, and trigger the
workflow on go.mod changes and a schedule.

Updates #13038
Updates tailscale/corp#50380

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ie4fffad7e9298b6b77c3ec3a6ae81fd784d182ce
2026-11-20 12:44:01 -08:00