Files
tailscale/.github/workflows/ssh-integrationtest.yml
T
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

87 lines
3.7 KiB
YAML

# 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"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
on:
workflow_dispatch:
pull_request:
paths:
- "ssh/**"
# gliderssh and x/crypto/ssh bumps.
- "go.mod"
- "go.sum"
- "Makefile"
- ".github/workflows/ssh-integrationtest.yml"
schedule:
# Changes outside ssh/** (ipn/ipnlocal, util/osuser, envknob,
# cmd/tailscaled) can break Tailscale SSH without triggering the
# pull_request paths above, so also run on main daily around
# midnight UK time (cron is UTC; 00:13 GMT, 01:13 BST), so results
# are ready the next morning. Off the hour to avoid GitHub's :00
# cron backlog.
- cron: "13 0 * * *"
jobs:
ssh-integrationtest:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- base: "ubuntu:focal"
tag: "ssh-ubuntu-focal"
- base: "ubuntu:jammy"
tag: "ssh-ubuntu-jammy"
- base: "ubuntu:noble"
tag: "ssh-ubuntu-noble"
- base: "alpine:latest"
tag: "ssh-alpine-latest"
steps:
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Build test binaries
run: |
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 ./tool/go test -tags integrationtest -c ./ssh/tailssh -o ssh/tailssh/testcontainers/tailssh.test
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 ./tool/go build -o ssh/tailssh/testcontainers/tailscaled ./cmd/tailscaled
- 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"'