Skip to content

Commit

Permalink
fix: use UID not username to set HOME dir (#10010)
Browse files Browse the repository at this point in the history
When a task's uid was is nonzero but username was still "root", we
would accidentally set the HOME directory to /root.

This happens because we started the container based on the UID, then we
looked up the username (uid->username lookup) and we found that we were
called "root", then we did a username->HOME lookup to arrive at /root.
  • Loading branch information
rb-determined-ai authored Oct 2, 2024
1 parent 49e72a8 commit 1297899
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
19 changes: 0 additions & 19 deletions master/static/srv/generic-task-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@ source /run/determined/task-setup.sh
set -e

STARTUP_HOOK="startup-hook.sh"
export PATH="/run/determined/pythonuserbase/bin:$PATH"

# If HOME is not explicitly set for a container, libcontainer (Docker) will
# try to guess it by reading /etc/password directly, which will not work with
# our libnss_determined plugin (or any user-defined NSS plugin in a container).
# The default is "/", but HOME must be a writable location for distributed
# training, so we try to query the user system for a valid HOME, or default to
# the working directory otherwise.
if [ "$HOME" = "/" ]; then
HOME="$(
set -o pipefail
getent passwd "$(whoami)" | cut -d: -f6
)" || HOME="$PWD"
export HOME
fi

if [ -z "$DET_PYTHON_EXECUTABLE" ]; then
export DET_PYTHON_EXECUTABLE="python3"
fi

# In order to be able to use a proxy when running a generic task, Python must be
# available in the container, and the "determined*.whl" must be installed,
Expand Down
2 changes: 1 addition & 1 deletion master/static/srv/task-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fi
if [ "$HOME" = "/" ]; then
HOME="$(
set -o pipefail
getent passwd "$(whoami)" | cut -d: -f6
getent passwd "$UID" | cut -d: -f6
)" || HOME="$PWD"
export HOME
fi
Expand Down

0 comments on commit 1297899

Please sign in to comment.