Files
tailscale/ssh
Andrew Dunham c49d1fbaba ssh/tailssh: always set a LANG environment variable
In Tailscale SSH, we clear the local environment before running the
incubator process, which means that the incubator starts without a
LANG/LC_* environment variable passed from the `tailscaled` parent. In
the child, we don't use PAM, and thus never load environment variables
specified by pam_env.so. Additionally, our previous implementation of
envForUser didn't set a `LANG` variable by default.

On systems where we are capable of using the `login` or `su` commands to
create a login shell, the launched shell will read these environment
variables (e.g. from /etc/default/locale). However, this doesn't apply
in all cases:
  1. Where we handle SSH in-process (handleSSHInProcess), e.g. due to
     SELinux being enabled.
  2. Where we are able to use `su` or `login`, but where the user's
     shell *isn't Bash* (see below).

In such cases, we'd launch a process without a LANG/LC_* environment
set, possibly mangling output for the user.

One thing I discovered while testing this: on some distros, Bash is
compiled with the SSH_SOURCE_BASHRC option. If set, and if the bash
process is both the parent shell and the SSH_CLIENT variable is set,
Bash loads the ~/.bashrc environment variable *even if it's not an
interactive shell*. This is part of the reason that
`ssh user@host cmd` works if `cmd` isn't in the system-default $PATH
variable.

However, since this is a bash-specific configuration, if the user's
shell is set to something else (zsh, etc.), we would never execute the
~/.zshrc file and thus never set LANG (or similar).

(I also added a comment documenting this)

It should essentially always be safe to set the LANG environment
variable if not otherwise specified, and it's reset by both the `login`
and `su` command (tested on Ubuntu).

Updates #TODO

Signed-off-by: Andrew Dunham <[email protected]>
2026-05-13 17:27:00 -04:00
..