Repository navigation
fix(docker): run the test image as a non-root user - #46
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Dockerfiles that DockSec flags are fixed: the root one, the ones under
examples/and, in fastapi-guard, the live-smoke one. None installs apt packages any more, uv comes from the official image at an exact tag, every image runs as a numeric non-rootUSERand has a HEALTHCHECK.docksec.ymlnow also watches**/Dockerfile, because DockSec runstrivy configover the whole tree and keeps every file namedDockerfile(findings.py:182-185), so a change to a nested file has to trigger the scan.Closes all open DockSec alerts (rule ids, alert numbers): DS002 (#3, #4), DS026 (#10, #11, #12), DS029 (#5, #6), DL3008 (#7), DL3013 (#8), DL3042 (#9), DL3009 (#13).
Root Dockerfile:
pip install uvbecameCOPY --from=ghcr.io/astral-sh/uv:0.13.4 /uv /uvx /bin/, and I droppedPIP_NO_CACHE_DIR=false, which only configured that pip call.app(uid 10001) owns/app,USER 10001comes beforeuv syncso the venv and/app/dataare writable.http://127.0.0.1:8000/with python and counts any HTTP answer as alive. The one-shot test runner would report a meaningless unhealthy state, socompose.ymlsetshealthcheck: disable: trueon the test service.Nested Dockerfiles:
examples/simple_app/Dockerfile: apt block dropped, userapp(uid 10001),USER 10001, HEALTHCHECK. Run through its owndocker-compose.yml:healthy,GET /200 from the host and from inside the container,uid=10001.examples/advanced_app/Dockerfile: numeric uid 10001 for the existingguarduser,USER 10001, HEALTHCHECK on/health. I could not run the real app: on master the app already dies at boot (ValueError: return_pattern rule with pattern '404' requires reading the response body, but behavior_scan_response_body is False), I confirmed that by building master's Dockerfile and starting it. I did not touch that. To prove the image mechanics I ran the stack with a stand-in server answering/health: apphealthythrough the Dockerfile HEALTHCHECK (compose healthcheck reset),uid=10001,GET /healththrough nginx 200.Verification (python 3.10, own compose projects, Redis without a host port, one run at a time):
localhost:6379inside the test container). I did not touch that.healthy,GET /200,uid=10001(app). The service command incompose.yml(gunicorn examples.main:app) fails on master and on this branch alike (No module named 'examples.main'), so I started it withgunicorn examples.simple_app.main:app --bind 0.0.0.0:8000 --reload.config --file-patterns dockerfile:Dockerfileover the repo: 27 successes, 0 failures for every Dockerfile.refs/pull/46/merge:results_count0 and 0 open alerts on that ref.Not verified: python versions other than 3.10, and the bind-mounted examples (
./:/app) on a Linux host, where a host-owned directory is not writable by uid 10001.