Skip to content

Commit c37d4d7

Browse files
committed
Undo changes which require further examination
1 parent c7ce29d commit c37d4d7

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

Diff for: base-notebook/start.sh

+6-27
Original file line numberDiff line numberDiff line change
@@ -130,32 +130,8 @@ if [ "$(id -u)" == 0 ] ; then
130130
# Update potentially outdated environment variables since image build
131131
export XDG_CACHE_HOME=/home/$NB_USER/.cache
132132

133-
# Notes on how we ensure that the environment that this container is started
134-
# with is preserved (except vars listen in JUPYTER_ENV_VARS_TO_UNSET) when
135-
# we transition from running as root to running as NB_USER.
136-
#
137-
# - We use `sudo` to execute the command as NB_USER. What then
138-
# happens to the environment will be determined by configuration in
139-
# /etc/sudoers and /etc/sudoers.d/* as well as flags we pass to the sudo
140-
# command. The behavior can be inspected with `sudo -V` run as root.
141-
#
142-
# ref: `man sudo` https://linux.die.net/man/8/sudo
143-
# ref: `man sudoers` https://www.sudo.ws/man/1.8.15/sudoers.man.html
144-
#
145-
# - We use the `--preserve-env` flag to pass through most environment
146-
# variables, but understand that exceptions are caused by the sudoers
147-
# configuration: `env_delete`, `env_check`, and `secure_path`.
148-
#
149-
# - We use the `--set-home` flag to set the HOME variable appropriatly.
150-
#
151-
# - We reduce the `env_delete` list of default variables to be deleted. It
152-
# has higher priority than the `--preserve-env` flag and `env_keep`
153-
# configuration.
154-
#
155-
# - We disable the `secure_path` which is set by default in /etc/sudoers as
156-
# it would override the PATH variable.
157-
echo 'Defaults !secure_path' > /etc/sudoers.d/added-by-start-script
158-
echo 'Defaults env_delete -= "PATH LD_* PYTHON*"' >> /etc/sudoers.d/added-by-start-script
133+
# Add ${CONDA_DIR}/bin to sudo secure_path
134+
sed -r "s#Defaults\s+secure_path\s*=\s*\"?([^\"]+)\"?#Defaults secure_path=\"\1:${CONDA_DIR}/bin\"#" /etc/sudoers | grep secure_path > /etc/sudoers.d/path
159135

160136
# Optionally grant passwordless sudo rights for the desired user
161137
if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then
@@ -167,7 +143,10 @@ if [ "$(id -u)" == 0 ] ; then
167143
run-hooks /usr/local/bin/before-notebook.d
168144

169145
echo "Running as ${NB_USER}:" "${cmd[@]}"
170-
exec sudo --preserve-env --set-home --user "${NB_USER}" "${cmd[@]}"
146+
exec sudo --preserve-env --set-home --user "${NB_USER}" \
147+
PATH="${PATH}" XDG_CACHE_HOME="/home/${NB_USER}/.cache" \
148+
PYTHONPATH="${PYTHONPATH:-}" \
149+
"${cmd[@]}"
171150

172151
# The container didn't start as the root user, so we will have to act as the
173152
# user we started as.

0 commit comments

Comments
 (0)