Skip to content

Commit b69718b

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 d73f99e commit b69718b

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
@@ -23,6 +23,8 @@ RUN --mount=type=cache,target=/root/.cache/uv \
2323

2424
FROM python:3.12-slim-bookworm
2525

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

2830
COPY --from=uv /root/.local /root/.local
@@ -32,6 +34,8 @@ RUN if ! id -u app >/dev/null 2>&1; then \
3234
fi
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/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
@@ -26,6 +26,8 @@ FROM python:3.12-slim-bookworm
2626
RUN apt-get update && apt-get install -y git git-lfs && rm -rf /var/lib/apt/lists/* \
2727
&& git lfs install --system
2828

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

3133
COPY --from=uv /root/.local /root/.local
@@ -35,6 +37,8 @@ RUN if ! id -u app >/dev/null 2>&1; then \
3537
fi
3638
COPY --from=uv --chown=app:app /app/.venv /app/.venv
3739

40+
USER app
41+
3842
# Place executables in the environment at the front of the path
3943
ENV PATH="/app/.venv/bin:$PATH"
4044

‎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
@@ -23,6 +23,8 @@ RUN --mount=type=cache,target=/root/.cache/uv \
2323

2424
FROM python:3.12-slim-bookworm
2525

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

2830
COPY --from=uv /root/.local /root/.local
@@ -32,6 +34,8 @@ RUN if ! id -u app >/dev/null 2>&1; then \
3234
fi
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

0 commit comments

Comments
 (0)