Repository navigation
fix(docker): run the test image as a non-root user - #172
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 (#2, #3, #4), DS026 (#10, #11, #12, #13), DS029 (#5, #6), DL3008 (#7), DL3013 (#8), DL3042 (#9), DL3009 (#14).
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 built it the waycontainer-release.ymldoes (docker compose buildinexamples/advanced_app) and ran the stack with nginx on a high host port: apphealthy,uid=10001,GET /healththrough nginx 200. I also ran it with the compose healthcheck reset so the Dockerfile HEALTHCHECK is the one reporting:healthy.tests/live_smoke/stack/Dockerfile: userapp(uid 10001),USER 10001, HEALTHCHECK on/health. I ran the wholelive-smoke.ymlsequence locally (wheel build,copy_example_app.py,patch_example_config.py,docker compose up --build --wait, thenpytest tests/live_smoke -m live_smokewith Redis on 16379): stack healthy, 101 passed in 371.88s.live-smoke.ymlgets achmod a+rwx tests/live_smoke/stack/scenario_datastep: the container now writes/smokeas uid 10001 and the checkout on the runner belongs to another uid. The live-smoke check on this PR runs it on Linux.Verification (python 3.10, own compose projects, Redis without a host port, one run at a time):
localhost:6379inside the test container,tests/conftest.py:32). I did not touch that.healthy,GET /200,uid=10001(app). Thecompose.ymlservice command works for this repo.config --file-patterns dockerfile:Dockerfileover the repo: 27 successes, 0 failures for every Dockerfile.refs/pull/172/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.