Skip to content

Commit cf5a7ab

Browse files
authored
Merge pull request #1270 from maresb/patch-1
Prepend $CONDA_DIR/bin instead of appending
2 parents 0eb36d7 + 1d4bd5d commit cf5a7ab

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

base-notebook/start.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ if [ "$(id -u)" == 0 ] ; then
150150
# Update potentially outdated environment variables since image build
151151
export XDG_CACHE_HOME="/home/${NB_USER}/.cache"
152152

153-
# Add ${CONDA_DIR}/bin to sudo secure_path
154-
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
153+
# Prepend ${CONDA_DIR}/bin to sudo secure_path
154+
sed -r "s#Defaults\s+secure_path\s*=\s*\"?([^\"]+)\"?#Defaults secure_path=\"${CONDA_DIR}/bin:\1\"#" /etc/sudoers | grep secure_path > /etc/sudoers.d/path
155155

156156
# Optionally grant passwordless sudo rights for the desired user
157157
if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == "yes" ]]; then
@@ -168,6 +168,12 @@ if [ "$(id -u)" == 0 ] ; then
168168
PATH="${PATH}" \
169169
PYTHONPATH="${PYTHONPATH:-}" \
170170
"${cmd[@]}"
171+
# Note on the purpose of "PATH=${PATH}":
172+
# In case "${cmd[@]}" is "bash", then PATH will be used by this bash shell.
173+
# However, PATH is irrelevant to how the above sudo command resolves the
174+
# path of "${cmd[@]}". Sudo's path resolution is done via the "secure_path"
175+
# variable set above in /etc/sudoers.d/path.
176+
171177

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

base-notebook/test/test_container_options.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,24 @@ def test_jupyter_env_vars_to_unset_as_root(
306306
**root_args, # type: ignore
307307
)
308308
assert "I like bananas and stuff, and love to keep secrets!" in logs
309+
310+
311+
def test_secure_path(container: TrackedContainer, tmp_path: pathlib.Path) -> None:
312+
"""Make sure that the sudo command has conda's python (not system's) on path.
313+
See <https://github.com/jupyter/docker-stacks/issues/1053>.
314+
"""
315+
d = tmp_path / "data"
316+
d.mkdir()
317+
p = d / "wrong_python.sh"
318+
p.write_text('#!/bin/bash\necho "Wrong python executable invoked!"')
319+
p.chmod(0o755)
320+
321+
logs = container.run_and_wait(
322+
timeout=5,
323+
tty=True,
324+
user="root",
325+
volumes={p: {"bind": "/usr/bin/python", "mode": "ro"}},
326+
command=["start.sh", "python", "--version"],
327+
)
328+
assert "Wrong python" not in logs
329+
assert "Python" in logs

0 commit comments

Comments
 (0)