Skip to content

Commit e6baebb

Browse files
committed
fix(docker): drop root privileges and switch to non-root user in container images
Closes #4741. Switched fetch, git, and time images to app user and filesystem/memory to node user.
1 parent 76d64c8 commit e6baebb

5 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/fetch/Dockerfile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ RUN --mount=type=cache,target=/root/.cache/uv \
2424

2525
FROM python:3.12-slim-bookworm
2626

27+
RUN if ! id -u app >/dev/null 2>&1; then useradd -rUM -s /usr/sbin/nologin app; fi
28+
2729
WORKDIR /app
2830

2931
COPY --from=uv /root/.local /root/.local
3032
COPY --from=uv --chown=app:app /app/.venv /app/.venv
3133

34+
USER app
35+
3236
# Place executables in the environment at the front of the path
3337
ENV PATH="/app/.venv/bin:$PATH"
3438

‎src/filesystem/Dockerfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ ENV NODE_ENV=production
2222

2323
RUN npm ci --ignore-scripts --omit-dev
2424

25+
USER node
26+
2527
ENTRYPOINT ["node", "/app/dist/index.js"]

‎src/git/Dockerfile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ FROM python:3.12-slim-bookworm
2727
RUN apt-get update && apt-get install -y git git-lfs && rm -rf /var/lib/apt/lists/* \
2828
&& git lfs install --system
2929

30+
RUN if ! id -u app >/dev/null 2>&1; then useradd -rUM -s /usr/sbin/nologin app; fi
31+
3032
WORKDIR /app
3133

3234
COPY --from=uv /root/.local /root/.local
3335
COPY --from=uv --chown=app:app /app/.venv /app/.venv
3436

37+
USER app
38+
3539
# Place executables in the environment at the front of the path
3640
ENV PATH="/app/.venv/bin:$PATH"
3741

‎src/memory/Dockerfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ WORKDIR /app
2121

2222
RUN npm ci --ignore-scripts --omit-dev
2323

24+
USER node
25+
2426
ENTRYPOINT ["node", "dist/index.js"]

‎src/time/Dockerfile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ RUN --mount=type=cache,target=/root/.cache/uv \
2424

2525
FROM python:3.12-slim-bookworm
2626

27+
RUN if ! id -u app >/dev/null 2>&1; then useradd -rUM -s /usr/sbin/nologin app; fi
28+
2729
WORKDIR /app
2830

2931
COPY --from=uv /root/.local /root/.local
3032
COPY --from=uv --chown=app:app /app/.venv /app/.venv
3133

34+
USER app
35+
3236
# Place executables in the environment at the front of the path
3337
ENV PATH="/app/.venv/bin:$PATH"
3438

0 commit comments

Comments
 (0)