Skip to content

Commit 5fdaa2c

Browse files
platzhershclaude
andauthored
fix: change Dockerfiles to not run as root (#21)
fix(security): run Docker containers as non-root user Add non-root user configuration to api and web Dockerfiles to address SonarCloud security hotspot docker:S6471. The python and node base images run as root by default, which is a security risk. - api/Dockerfile: Create appuser (uid 1000) and switch to it - web/Dockerfile: Use built-in node user and switch to it Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9362c69 commit 5fdaa2c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

api/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ COPY api/templates ./templates
1919
# Generate Prisma client
2020
RUN prisma generate
2121

22+
# Create non-root user for security
23+
RUN groupadd --gid 1000 appgroup && \
24+
useradd --uid 1000 --gid appgroup --shell /bin/bash --create-home appuser && \
25+
chown -R appuser:appgroup /app
26+
27+
USER appuser
28+
2229
EXPOSE 8000
2330

2431
# Use Railway's $PORT if available, otherwise default to 8000

web/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ RUN pnpm run build
2020
# Install serve globally using npm (pnpm global install has issues in Docker)
2121
RUN npm install -g serve
2222

23+
# Change ownership to the built-in node user for security
24+
RUN chown -R node:node /app
25+
26+
USER node
27+
2328
EXPOSE 3000
2429

2530
# Use Railway's $PORT if available, otherwise default to 3000

0 commit comments

Comments
 (0)