Repository navigation
feat: harden container with non-root execution and smoke tests - #201
ashhadali10 wants to merge 6 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. |
|
Hi @ashhadali10 , great work again! Yes, using apt-get is the most straightforward path. you're already using it anyway. Good of you to also verify the test results and make sure it all still works as desired. I'm not an approver or maintainer, just someone like you. I'm sorry. :( One suggestion: if you do all the work to install the GPG key first, you can skip the apt-get in the beginning and combine all the package installs in a single apt-get. Running |
|
Hi @advaitpatel @arkid15r friendly ping on this PR. @pfarikrispy has reviewed the changes and the supply-chain concern he raised Could a maintainer:
Thanks |
DockSecNo container files changed in this pull request. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #201 +/- ##
==========================================
+ Coverage 86.01% 86.02% +0.01%
==========================================
Files 53 53
Lines 8117 8117
==========================================
+ Hits 6982 6983 +1
+ Misses 1135 1134 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| # page to the destination, producing a "successful" build with a text file where | ||
| # the binary should be. | ||
| # Docker CLI (GPG-signed APT repository) | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ |
| RUN rm -rf /src | ||
|
|
||
| # Copy and set permissions for entrypoint | ||
| RUN groupadd -g ${DOCKER_USER_GID} docksec && \ |
| RUN groupadd -g ${DOCKER_USER_GID} docksec && \ | ||
| useradd -m -u ${DOCKER_UID} -g docksec -s /sbin/nologin -c "DockSec App User" docksec | ||
|
|
||
| RUN if getent group ${DOCKER_GID} >/dev/null; then \ |
|
Hello @ashhadali10 can you please fix the github security findings? |
|
Hi @advaitpatel @arkid15r pushed a fix for the CI permission error and the
packaging test regression.
Root cause of the CI failure: `DOCKSEC_RESULTS_DIR` did not reliably reach the
non-root CLI process after the `gosu` drop, so `DocksecConfig` fell back to
`os.getcwd()/results` (`/work/results` in CI, root-owned) and failed with
`PermissionError`.
Fix:
- Baked `HOME` and `DOCKSEC_RESULTS_DIR` into the image via `ENV`, so the
non-root CLI always resolves to `/home/docksec/.docksec/results`. Users can
still override with `docker run -e`.
- Kept `entrypoint.sh`'s standalone privilege-drop block self-contained so the
regression tests still see the forwarded `ARGS:` line.
- Moved `ARG HADOLINT_VERSION` and `ARG TRIVY_VERSION` next to their install
blocks so the packaging test can find the `arm64` case within its scan window.
Verified locally:
- Non-root run: `Standalone run detected` + UID 10001, reports written to
`/home/docksec/.docksec/results`
- Supply chain: `dpkg -l docker-ce-cli` confirms APT repo install (not a tarball)
- GH Action mode (`GITHUB_WORKSPACE` set): stays root, no drop log
- CI case (`-w /work`, root-owned): scan completes, no `PermissionError`
- `pytest tests 546 passed
Please re-approve.
Thanks!
…On Fri, 30 Oct 2026, 12:32 am Advait Patel, ***@***.***> wrote:
*advaitpatel* left a comment (OWASP/DockSec#201)
<#201 (comment)>
Hello @ashhadali10 <https://github.com/ashhadali10> can you please fix
the github security findings?
—
Reply to this email directly, view it on GitHub
<#201?email_source=notifications&email_token=ANB45SMIJK73UJSBLGOVZIT5WOLNXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNJQGY2DCOJVGUY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-6506419551>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANB45SMZJBUIROORQLLGUPT5WOLNXAVCNFSNUABFKJSXA33TNF2G64TZHM4TGMZQGQ3DGMRVHNEXG43VMU5TKOJSGU2TOMBYGAZKC5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/ANB45SLKUJLPDCFATA23COL5WOLNXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNJQGY2DCOJVGUY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/ANB45SN5GHPQUVSAEGIXIFT5WOLNXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNJQGY2DCOJVGUY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
- Bake HOME and DOCKSEC_RESULTS_DIR into the image via ENV so the non-root CLI always resolves to /home/docksec/.docksec/results, regardless of how privileges are dropped. - Keep entrypoint.sh's standalone privilege-drop block self-contained so tests that run entrypoint.sh without a Docker daemon still forward CLI args correctly. - Move ARG HADOLINT_VERSION and ARG TRIVY_VERSION next to their respective install blocks so the packaging test can find the arm64 case within its scan window. Verified locally: - Non-root scan drops to UID 10001 and writes reports to ~/.docksec/results - Docker CLI installed from GPG-signed APT repo (dpkg -l docker-ce-cli) - GITHUB_WORKSPACE mode stays root (no privilege drop) - CI case (root-owned /work) completes without PermissionError - pytest tests/ -> 546 passed
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.