Skip to content

Commit b6f0d9a

Browse files
torrid-fishclaude
andcommitted
fix(docker): run container as non-root user (least privilege)
No USER directive meant uvicorn ran as root (uid 0). Add an unprivileged `appuser` (uid 10001) and switch to it before CMD. The app binds 8000 (>1024) so root isn't needed; app files stay root-owned and read-only to appuser. Verified the image runs as uid 10001 and /api/MarkAccent/ still returns 200. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 432af8b commit b6f0d9a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ RUN python -m compileall -b -q main.py api config \
1919

2020
FROM python:3.11-slim
2121

22+
# Least privilege: run as an unprivileged user, not root. The app binds
23+
# port 8000 (>1024) so no root is needed. App files stay root-owned and
24+
# read-only to this user — the process can't modify its own code or deps.
25+
RUN useradd --system --no-create-home --uid 10001 appuser
26+
2227
WORKDIR /app
2328

2429
# Copy installed dependencies and app from builder
@@ -33,4 +38,6 @@ ENV PYTHONUNBUFFERED=1
3338

3439
EXPOSE 8000
3540

41+
USER appuser
42+
3643
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

0 commit comments

Comments
 (0)