Skip to content

Commit

Permalink
fix: don't pass all environment variables through sshd (#1186)
Browse files Browse the repository at this point in the history
The HOME variable was always set to / for non-root shells, when sshd should be setting it.

While we are at it, we might as well filter out several other environment variables which I think ought not to be passed in this way at all.
  • Loading branch information
rb-determined-ai authored Aug 28, 2020
1 parent ab671d1 commit e255979
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions master/static/srv/shell-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ python3.6 -m pip install --user /opt/determined/wheels/determined*.whl
# Prepend each key in authorized_keys with a set of environment="KEY=VALUE"
# options to inject the entire docker environment into the eventual ssh
# session via an options in the authorized keys file. See syntax described in
# `man 8 sshd`. Normal ssh mechanisms for overriding variables as part of the
# protocol (like TERM or LANG) will take precedence, as will normal mechanisms
# like a ~/.bashrc. The purpose of this is to honor the environment variable
# `man 8 sshd`. The purpose of this is to honor the environment variable
# settings as they are set for experiment or notebook configs, while still
# allowing customizations via normal ssh mechanisms.
#
# Not all variables should be overwritten this way; the HOME variable should be
# set by ssh, and the TERM, LANG, and LC_* variables should be passed in from
# the client.
#
# Normal mechanisms like a ~/.bashrc will override these variables.
#
# After openssh 8+ is the only version of openssh supported (that is, after we
# only support ubuntu >= 20.04), we can use the more obvious SetEnv option and
# skip this awkwardness.
vars="$(env | sed -e 's/=.*//')"
blacklist="^(_|HOME|TERM|LANG|LC_.*)"
vars="$(env | sed -E -e "s/=.*//; /$blacklist/d")"
options="$(
for var in $vars ; do
# Note that the syntax ${!var} is for a double dereference.
Expand Down

0 comments on commit e255979

Please sign in to comment.