From b1582deed478f8c9a7e223a2b5decf34fca53cf7 Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Mon, 26 Oct 2026 16:02:10 -0500 Subject: [PATCH] ssh/tailssh: set $LOGNAME to same value as $USER in incubator When the ssh incubator runs the shell itself instead of using `su` or `login`, it needs to set the `$LOGNAME` environment variable. Just like OpenSSH `sshd`, it sets this to the same value as `$USER`. Updates tailscale/corp#50380 Signed-off-by: Percy Wegmann --- ssh/tailssh/incubator.go | 3 +++ ssh/tailssh/incubator_test.go | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ssh/tailssh/incubator.go b/ssh/tailssh/incubator.go index 2a6d4f2f2..41b1a397c 100644 --- a/ssh/tailssh/incubator.go +++ b/ssh/tailssh/incubator.go @@ -1273,6 +1273,9 @@ func envForUser(u *userMeta) []string { return []string{ fmt.Sprintf("SHELL=%s", u.LoginShell()), fmt.Sprintf("USER=%s", u.Username), + // Some systems require $LOGNAME. Just like OpenSSH sshd, set it to the + // same value as $USER. + fmt.Sprintf("LOGNAME=%s", u.Username), fmt.Sprintf("HOME=%s", u.HomeDir), fmt.Sprintf("PATH=%s", defaultPathForUser(u)), } diff --git a/ssh/tailssh/incubator_test.go b/ssh/tailssh/incubator_test.go index d72c049b1..c74901e20 100644 --- a/ssh/tailssh/incubator_test.go +++ b/ssh/tailssh/incubator_test.go @@ -178,9 +178,9 @@ func TestIncubatorEnvServerOnly(t *testing.T) { } } } - // USER/HOME come from the server; TERM is the one client-controlled value - // allowed in (OpenSSH parity). - for _, want := range []string{"USER=alice", "HOME=/home/alice", "TERM=xterm-256color"} { + // USER/LOGNAME/HOME come from the server; TERM is the one client-controlled + // value allowed in (OpenSSH parity). + for _, want := range []string{"USER=alice", "LOGNAME=alice", "HOME=/home/alice", "TERM=xterm-256color"} { if !slices.Contains(env, want) { t.Errorf("%q missing from child environment: %q", want, env) }