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]>
This commit is contained in:
Bazyli Brzoska authored and Brad Fitzpatrick committed 2026-12-04 20:04:46 -08:00
1 parent 67489a9581
commit aeb0f740f5
5 files changed
+691 -45

No files matched your search

+36 -1
View File
@@ -1,4 +1,4 @@
# Run the ssh integration tests in various Docker containers.
# Run the ssh integration tests in various Docker containers and on macOS.
# These tests can also be run locally via `make sshintegrationtest`.
name: "ssh-integrationtest"
@@ -49,3 +49,38 @@ jobs:
- name: Run SSH integration tests (${{ matrix.base }})
run: |
docker build --build-arg="BASE=${{ matrix.base }}" -t "${{ matrix.tag }}" ssh/tailssh/testcontainers
ssh-integrationtest-macos:
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Build test binaries
run: |
./tool/go test -tags integrationtest -c ./ssh/tailssh -o /tmp/tailssh.test
./tool/go build -o /tmp/tailscaled ./cmd/tailscaled
- name: Set up test user and Paramiko
run: |
sudo dseditgroup -o create groupone
sudo dseditgroup -o create grouptwo
# The Linux containers also give testuser /bin/sh. zsh, the macOS
# default, turns ECHO back on for the commands it runs, which
# TestIntegrationPTYTerminalModes notices.
sudo sysadminctl -addUser testuser -password "$(uuidgen)" -shell /bin/sh
sudo dseditgroup -o edit -a testuser -t user groupone
sudo dseditgroup -o edit -a testuser -t user grouptwo
sudo createhomedir -c -u testuser
sudo -H python3 -m pip install paramiko==3.5.1 || sudo -H python3 -m pip install --break-system-packages paramiko==3.5.1
- name: Run SSH integration tests as root
working-directory: /tmp
run: |
eval $(ssh-agent -s)
sudo --preserve-env=SSH_AUTH_SOCK TAILSCALED_PATH=/tmp/tailscaled ./tailssh.test -test.v \
-test.run 'TestSSHAgentForwarding|TestIntegration|TestOpenSSHExitCodes|TestLocalUnixForwardingHalfClose'
- name: Run SSH integration tests as testuser
working-directory: /tmp
run: |
sudo touch /tmp/tailscalessh.log
sudo chown testuser /tmp/tailscalessh.log
sudo -u testuser env TAILSCALED_PATH=/tmp/tailscaled sh -c 'eval $(ssh-agent -s) && ./tailssh.test -test.v \
-test.run "TestSSHAgentForwarding|TestIntegration|TestOpenSSHExitCodes|TestLocalUnixForwardingHalfClose|TestDoDropPrivileges"'