Skip to content

fix(docker): run the images as a non-root user and scan them with DockSec - #102

Merged
rennf93 merged 1 commit into
masterfrom
fix/docker-image-hardening
Oct 21, 2026
Merged

rennf93 merged 1 commit into
masterfrom
fix/docker-image-hardening

Conversation

@rennf93

@rennf93 rennf93 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

The root Dockerfile follows the standard of the adapters' root Dockerfiles, and DockSec scans the repo.

Root Dockerfile (the dev and test image, and the compose example that runs guard-core-mcp):

  1. The apt block (libsodium23, wget, build-essential, libffi-dev, curl) is gone. I built the image and ran the suite and the server without it and nothing needed it, so there is nothing to pin.
  2. pip install uv became COPY --from=ghcr.io/astral-sh/uv:0.13.4 /uv /uvx /bin/, and PIP_NO_CACHE_DIR=false is gone.
  3. User app (uid 10001) owns /app, USER 10001 comes before uv sync. --frozen and the uv.lock mount stay, because this repo tracks uv.lock.
  4. HEALTHCHECK is python -c "from guard_core_mcp.server import mcp". The server speaks MCP over stdio and opens no port (server.py:506, mcp.run()), so there is nothing to probe over the network. The check confirms the server module and its tool registrations load.

.github/workflows/docksec.yml is copied from fastapi-guard master: same pinned OWASP/DockSec SHA, same pinned upload-sarif, push and pull_request paths including '**/Dockerfile', category docksec, fork-PR guard on the upload.

release-docker.yml builds Dockerfile.hosted, not the root Dockerfile, so this PR does not change the published image. Dockerfile.hosted is not scanned by DockSec (the scan keeps files named exactly Dockerfile) and I left it alone. For reference, hadolint 2.15.1 on it reports DL3008, DL3009, DL3015 (unpinned apt install of libsodium23 and curl), DL3013, DL3042 (pip install uv) and DL3066 (named user guard), and it has no HEALTHCHECK.

Verification (compose test service, own compose project, one run at a time, master vs this branch, pytest -v --cov=guard_core_mcp --cov-branch):

  • Python 3.10: master 157 passed; branch 157 passed.
  • Python 3.14: master 157 passed; branch 157 passed.
  • Example service from compose.yml (guard-core-mcp, Python 3.10): healthy, uid=10001. I ran the entrypoint with docker compose run -T, sent an MCP initialize request on stdin and got a valid JSON-RPC result with the tools capability back, as uid 10001. The server writes nothing outside /app, opens no port and needs no privilege.
  • hadolint 2.15.1 on the root Dockerfile: no output (master: DL3008, DL3009, DL3015, DL3013, DL3042).
  • trivy 0.74.0 config --file-patterns dockerfile:Dockerfile on the root Dockerfile: 27 successes, 0 failures.
  • DockSec check on this PR: pass. Analysis on refs/pull/102/merge (commit 69fcc6e): results_count 0.

Not verified: Python versions other than 3.10 and 3.14, the hosted image (not changed, not built), and the CI result beyond the checks listed on this PR.

@rennf93 rennf93 added the no-issue Chore or dependency PR that does not need an issue label Oct 21, 2026
@github-actions github-actions Bot added ci GitHub Actions and pre-commit build Makefile / Docker / packaging labels Oct 21, 2026
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@rennf93
rennf93 merged commit 6798ecf into master Oct 21, 2026
18 of 19 checks passed
@rennf93
rennf93 deleted the fix/docker-image-hardening branch October 22, 2026 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Makefile / Docker / packaging ci GitHub Actions and pre-commit no-issue Chore or dependency PR that does not need an issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants