Skip to content

Commit 8be45dc

Browse files
cliffhallclaude
andcommitted
fix(docker): run every server image as its non-root user
The fetch, git and time images created an app user and chowned the virtualenv to it but never switched to it, and the filesystem, memory and sequentialthinking images never used the node user their base image ships, so all six ran their server as root. Each now ends on USER app or USER node. The Python images install the uv-managed interpreter under /python instead of /root/.local, which the app user cannot read, and give app a home directory. The git image trusts every mounted repository (safe.directory '*'), since a bind mount is rarely owned by app. The memory image gives /app/dist, where its default graph lives, to node. The READMEs cover the gitconfig path, --user on Linux hosts, and the one-time chown of a memory volume an older image created. Closes modelcontextprotocol#4741 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent e80aac9 commit 8be45dc

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎Dockerfile‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ ENV UV_COMPILE_BYTECODE=1
1010
# Copy from the cache instead of linking since it's a mounted volume
1111
ENV UV_LINK_MODE=copy
1212

13+
# Install the Python that .python-version pins under /python rather than the
14+
# default /root/.local, which the unprivileged runtime user cannot read (/root
15+
# is mode 700). The virtualenv's interpreter links into this directory.
16+
ENV UV_PYTHON_INSTALL_DIR=/python
17+
1318
# Install the project's dependencies using the lockfile and settings
1419
COPY uv.lock pyproject.toml ./
1520
RUN --mount=type=cache,target=/root/.cache/uv \
@@ -25,13 +30,19 @@ FROM python:3.12-slim-bookworm
2530

2631
WORKDIR /app
2732

28-
COPY --from=uv /root/.local /root/.local
33+
COPY --from=uv /python /python
2934

35+
# The server runs as the unprivileged `app` user, not root (#4741), so files it
36+
# writes into a bind mount are not root-owned on the host and the image passes
37+
# `runAsNonRoot` admission policies. The user gets a home directory, where
38+
# HOME points, for any per-user configuration a tool reads.
3039
RUN if ! id -u app >/dev/null 2>&1; then \
31-
useradd -rUM -s /usr/sbin/nologin app; \
40+
useradd -rUm -d /home/app -s /usr/sbin/nologin app; \
3241
fi
3342
COPY --from=uv --chown=app:app /app/.venv /app/.venv
3443

44+
USER app
45+
3546
# Place executables in the environment at the front of the path
3647
ENV PATH="/app/.venv/bin:$PATH"
3748

0 commit comments

Comments
 (0)