Skip to content

Commit 6fa67cc

Browse files
committed
Append $CONDA_DIR/bin to sudo secure_path
Retain behavior when su was used instead
1 parent 2c80cf3 commit 6fa67cc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

base-notebook/start.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ if [ $(id -u) == 0 ] ; then
4848

4949
# Enable sudo if requested
5050
if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then
51-
echo "Granting $NB_USER sudo access"
51+
echo "Granting $NB_USER sudo access and appending $CONDA_DIR/bin to sudo PATH"
5252
echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/notebook
53+
sed -ri "s#Defaults\s+secure_path=\"([^\"]+)\"#Defaults secure_path=\"\1:$CONDA_DIR/bin\"#" /etc/sudoers
5354
fi
5455

5556
# Exec the command as NB_USER with the PATH and the rest of

base-notebook/test/test_container_options.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ def test_sudo(container):
7171
assert rv == 0
7272
assert 'uid=0(root)' in c.logs(stdout=True).decode('utf-8')
7373

74+
75+
def test_sudo_path(container):
76+
"""Container should include /opt/conda/bin in the sudo secure_path."""
77+
c = container.run(
78+
tty=True,
79+
user='root',
80+
environment=['GRANT_SUDO=yes'],
81+
command=['start.sh', 'sudo', 'jupyter', '--version']
82+
)
83+
rv = c.wait(timeout=10)
84+
assert rv == 0
85+
86+
7487
def test_group_add(container, tmpdir):
7588
"""Container should run with the specified uid, gid, and secondary
7689
group.

0 commit comments

Comments
 (0)