Repository navigation
feat: harden container with non-root execution and smoke tests - #201
ashhadali10 wants to merge 5 commits into
Conversation
|
@ashhadali10 I think is really great work! Thanks. You were very thorough and structured. The UID/GUID handling is well thought out and marked with clear variables. The smoke test is excellent! very very nice. My only remark would be that you are pulling in a binary from docker to install the docker CLI from a curl. Since this is a security tool, I think the source and integrity of any deps should be verified before installing. Right? This is often overlooked but these days that can become a costly mistake. Granted, docker.io is not just any source, but still. |
|
While searching for the docker cli tar.gz files, I found the official docker cli image. I couldn't find a clear way to check the source (via signatures) or integrity (via checksums).
|
Thanks @pfarikrispy for the kind words and for catching this you re right, and I appreciate the careful review. You correctly identified a real supply-chain risk the previous Dockerfile fetched the Docker CLI as a tarball over Fixed in 70bc9c4: the Docker CLI is now installed from Docker's official GPG-signed APT repository ( Verified locally:
The CI workflows are still awaiting maintainer approval would you be able to approve them so the checks can run? Thanks again for the thorough review. |
Description
Implements the non-root container hardening portion of #109.
This PR makes the container drop privileges to a dedicated non-root user
(
docksec, UID/GID 10001) for standalonedocker run, while keeping rootfor GitHub Docker container actions (required for
GITHUB_WORKSPACEaccess).longer ships
docker.io, so the previous install silently produced a brokenimage with
docker: not found); createddocksecuser (UID/GID 10001);matched container
dockergroup GID to the host socket GID at build time;pre-created
/home/docksec/.docksec/resultswith correct ownership to fixPermissionErrorwhen writing reports as non-root; installedgosuforsafe privilege dropping.
USERis intentionally not set because GitHubDocker container actions must run as root to access
GITHUB_WORKSPACE.docksecviagosuwhen runningstandalone; stays root when
GITHUB_WORKSPACEis set (GitHub Actioncompatibility); users can override with
docker run --user ....CLI (
--version/--help) works as non-root, GitHub Action mode staysroot, and
--user 0override works.Closes #109 (non-root + smoke tests portion)
Type of Change
How Has This Been Tested?
Test Configuration:
Test evidence:
pytest tests/— 546 passed, 153 subtests passed in 22.91sbash tests/smoke-test-nonroot.sh— all 4 tests pass:--user 0override works ✅vulnerables/web-dvwa:latestsucceeds,producing HTML and JSON reports under the mounted output directory.
Behaviour matrix:
docker run ... docksec10001(non-root, auto-drop)docker run -e GITHUB_WORKSPACE=... docksec(Action)0(root)docker run --user 0 docksec0(explicit override)docker run --user 10001:10001 docksec10001Checklist
Screenshots (if applicable)
N/A — no UI changes.
Related Issues / PRs
Note on
make check-test: Localblack --check .reports 46 pre-existingfiles that
blackwould reformat. This is a version mismatch (blackisunpinned in
pyproject.toml, sopip install -e ".[dev]"pulls a newerversion than the code was formatted with). No
.pyfiles are modified inthis PR, so this is unrelated to these changes.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.