Skip to content

Commit 2275aca

Browse files
committed
Ensure PATH propagates through privilege drops
For the new Docker image to work properly, the PATH variable needs to propagate through user changes performed by `nav start` commands. There were, however, two barriers: First, su is used to drop privileges before starting nav daemons, but this resets the PATH variable to the ones defined in `/etc/login.defs`. Secondly, `nav start` uses a `-` to tell `su` to use a login shell, in which case the PATH is still reset. The login shell option was introduced by a fix for #2218, but it's not clear that the use or non-use of a login shell was the actual problem solved, it was just that the order of the arguments needed to be portable. Tagged #2218 just in case this turns into another BSD regression.
1 parent 2c0895b commit 2275aca

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ ARG UID
8686
ARG GID
8787
RUN groupadd --gid "$GID" nav ; adduser --home=/source --shell=/bin/bash --uid=$UID --gid=$GID nav
8888
RUN echo "nav ALL =(ALL: ALL) NOPASSWD: ALL" > /etc/sudoers.d/nav
89+
# Ensure the virtualenv's bin directory is on everyone's PATH variable
8990
RUN sed -e 's,^Defaults.*secure_path.*,Defaults secure_path="/opt/venvs/nav/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",' -i /etc/sudoers
91+
RUN sed -e 's,^ENV_SUPATH.*,ENV_SUPATH PATH=/opt/venvs/nav/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",' -i /etc/login.defs
92+
RUN sed -e 's,^ENV_PATH.*,ENV_PATH PATH=/opt/venvs/nav/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games",' -i /etc/login.defs
9093

9194
RUN --mount=type=cache,target=/source/.cache \
9295
mkdir -p /opt/venvs/nav && chown nav /opt/venvs/nav && \

python/nav/startstop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def start(self, silent=False):
126126
if not self.service_dict.get("privileged", False):
127127
# run command as regular nav user
128128
user = NAV_CONFIG.get("NAV_USER", "navcron")
129-
command = 'su - {user} -c "{command}"'.format(
129+
command = 'su {user} -c "{command}"'.format(
130130
command=self._command, user=user
131131
)
132132
else:

0 commit comments

Comments
 (0)