File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -150,8 +150,8 @@ if [ "$(id -u)" == 0 ] ; then
150
150
# Update potentially outdated environment variables since image build
151
151
export XDG_CACHE_HOME=" /home/${NB_USER} /.cache"
152
152
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
155
155
156
156
# Optionally grant passwordless sudo rights for the desired user
157
157
if [[ " $GRANT_SUDO " == " 1" || " $GRANT_SUDO " == " yes" ]]; then
@@ -168,6 +168,12 @@ if [ "$(id -u)" == 0 ] ; then
168
168
PATH=" ${PATH} " \
169
169
PYTHONPATH=" ${PYTHONPATH:- } " \
170
170
" ${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
+
171
177
172
178
# The container didn't start as the root user, so we will have to act as the
173
179
# user we started as.
Original file line number Diff line number Diff line change @@ -306,3 +306,24 @@ def test_jupyter_env_vars_to_unset_as_root(
306
306
** root_args , # type: ignore
307
307
)
308
308
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\n echo "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
You can’t perform that action at this time.
0 commit comments