hardening: run production container as non-root user #19

Merged
matt merged 1 commit from mailship-c3s-docker-run-production-container-as-non-r-4e7 into main 2026-09-18 15:33:57 +00:00
Collaborator

mailship-c3s

The production Docker stage currently runs as root. This change creates a dedicated non-root user (app) and switches to it before runtime, reducing the impact of a container compromise.

Changes:

  • Add addgroup -S app && adduser -S -G app app to create the non-root user and group in the production stage
  • Run chown -R app:app /data so the SQLite data directory is writable by the app user
  • Set USER app before EXPOSE and CMD so the container runs as non-root

The build stage is unaffected — it retains root for apk add python3 make g++ git and other build-time needs.

How to test: docker build --target production . then verify the container starts and can write to /data (e.g. docker run --rm <image> touch /data/test.txt).

mailship-c3s The production Docker stage currently runs as root. This change creates a dedicated non-root user (`app`) and switches to it before runtime, reducing the impact of a container compromise. Changes: - Add `addgroup -S app && adduser -S -G app app` to create the non-root user and group in the production stage - Run `chown -R app:app /data` so the SQLite data directory is writable by the app user - Set `USER app` before `EXPOSE` and `CMD` so the container runs as non-root The `build` stage is unaffected — it retains root for `apk add python3 make g++ git` and other build-time needs. How to test: `docker build --target production .` then verify the container starts and can write to `/data` (e.g. `docker run --rm <image> touch /data/test.txt`).
hudson added 1 commit 2026-09-18 14:32:56 +00:00
hardening: run production container as non-root user
All checks were successful
CI / checks (pull_request) Successful in 38s
dfdc6d489c
Add a dedicated 'app' user/group in the production image stage so the
application runs without root privileges. The build stage retains root
for apk add of build-time dependencies.

Changes:
- Create 'app' user and group via addgroup/adduser
- Change ownership of /data to app:app
- Set USER app before EXPOSE and CMD

Closes mailship-c3s
matt approved these changes 2026-09-18 15:33:53 +00:00
matt merged commit 43f2a04de4 into main 2026-09-18 15:33:57 +00:00
matt deleted branch mailship-c3s-docker-run-production-container-as-non-r-4e7 2026-09-18 15:34:10 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: matt/mailship#19
No description provided.