feat(platform): harden the container images (#261) #307

Merged
sharang merged 1 commits from feat/container-hardening into main 2026-09-21 17:28:24 +00:00
Owner

MVP-0.8 of #253. Closes #261.

Deploy order: merge this first and let the new images reach staging. Only then merge the matching orca-platform PR, which moves the agent onto a new data volume. A fresh named volume takes its ownership from the image mounting it, so the unprivileged image has to be running first.

Change

  • Non-root: the agent, dashboard and MCP run as app (uid 10001).

    • The agent writes only to $HOME (tool caches), /data/compliance-scanner (uploaded artifacts and the OSCAL snapshot, where a volume belongs) and /tmp (git checkouts), so the rest can be read-only.
    • The entrypoint checks the data directories are writable. If a volume made by an older root image isn't, it stops with the exact chown -R 10001:10001 <volume> fix instead of failing on the first upload.
  • HEALTHCHECK in all three images:

    • agent /api/v1/health
    • MCP /health
    • dashboard: a new /health route outside /api/, so it needs no session

    They are liveness only for now; #262 makes the probes check Mongo and the registry, which is what turns them unhealthy when a dependency is down.

  • Pinned tools, all set as ARGs at the top of Dockerfile.agent and written to /opt/pruefwerk/tool-versions.json for the evidence pack (MVP-3.3):

    Tool Before Now
    Rust (cargo for lockfiles and metadata) rustup stable under /root 1.98.1, system-wide, per-user CARGO_HOME
    cargo-audit latest, no --locked 0.22.2 --locked, built in its own stage (no C toolchain in the runtime)
    syft install.sh from main 1.52.0, sha256-verified
    gitleaks 8.21.2 8.21.2, sha256-verified (not bumped, to avoid finding churn)
    semgrep / ruff latest 1.177.0 / 0.16.8
  • Nix removed: the store bootstrap, nix.conf and entrypoint seeding are gone. The firmware reproducible build is off in shared deployments (#257), and without Nix it falls back to analysis-only, which the code already handled. I updated the docs.

  • Unused runtimes removed: Go, PHP, Composer, Ruby and Bundler; nothing invokes them. apt no longer installs recommended packages, which dropped a full C toolchain that came in with python3-pip.

  • .dockerignore: keeps target/ (24 GB locally), node_modules, .git and .env out of the build context.

  • docker-compose: mounts a data volume at /data/compliance-scanner instead of a root-owned clone volume.

Size

The old image is 1,187 MB compressed (registry manifest). The new runtime layers without the agent binary are 474 MB, so with the binary it's roughly half.

Verification

  • docker build --check passes for all three Dockerfiles. cargo fmt, clippy on both dashboard feature sets and the dashboard tests (28) pass.
  • I built the new tools stage locally. The builder stage is skipped because it's a full, unbounded cargo build plus the private Firmwerk dependency. Running as uid 10001:
    • every tool reports its pinned version;
    • cargo generate-lockfile and cargo metadata resolve a real dependency;
    • semgrep and syft scans work, with caches landing in $HOME;
    • there is no nix, go, php, ruby, composer or C compiler in the image.
  • End to end, with the new runtime plus the current staging agent binary, a fresh named volume and local Mongo:
    • docker inspect shows User=app, Health=healthy;
    • the volume came up owned by app, and the snapshot was seeded into it;
    • a manual scan of github.com/dtolnay/itoa completed as uid 10001 (every stage, Cargo.lock generated, 67 SBOM entries, 18 findings) with no permission errors.
  • A root-owned volume makes the entrypoint stop with …/artifacts is not writable by uid 10001 and the fix command.
  • MCP runtime with the current binary: uid 10001 and healthy. Dashboard runtime: uid 10001, serves / with 200. Its /health ships in this PR, so the old binary can't show it.

After deploy (manual, on the stage node)

  • Delete the old volumes the orca PR stops mounting:
    • the Nix store orca-pruefwerk-stage-nixstore
    • the agent's former /data/compliance-scanner/ssh volume, which still holds the shared SSH deploy key removed in #255
  • I'll file a follow-up for the Rust toolchain: at 626 MB uncompressed, it's now the largest layer.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

MVP-0.8 of #253. Closes #261. > **Deploy order:** merge this first and let the new images reach staging. Only then merge the matching orca-platform PR, which moves the agent onto a new data volume. A fresh named volume takes its ownership from the image mounting it, so the unprivileged image has to be running first. ## Change - **Non-root:** the agent, dashboard and MCP run as `app` (uid 10001). - The agent writes only to `$HOME` (tool caches), `/data/compliance-scanner` (uploaded artifacts and the OSCAL snapshot, where a volume belongs) and `/tmp` (git checkouts), so the rest can be read-only. - The entrypoint checks the data directories are writable. If a volume made by an older root image isn't, it stops with the exact `chown -R 10001:10001 <volume>` fix instead of failing on the first upload. - **HEALTHCHECK** in all three images: - agent `/api/v1/health` - MCP `/health` - dashboard: a new `/health` route outside `/api/`, so it needs no session They are liveness only for now; **#262 makes the probes check Mongo and the registry**, which is what turns them unhealthy when a dependency is down. - **Pinned tools**, all set as `ARG`s at the top of `Dockerfile.agent` and written to `/opt/pruefwerk/tool-versions.json` for the evidence pack (MVP-3.3): | Tool | Before | Now | |---|---|---| | Rust (cargo for lockfiles and metadata) | rustup `stable` under `/root` | 1.98.1, system-wide, per-user `CARGO_HOME` | | cargo-audit | latest, no `--locked` | 0.22.2 `--locked`, built in its own stage (no C toolchain in the runtime) | | syft | `install.sh` from `main` | 1.52.0, sha256-verified | | gitleaks | 8.21.2 | 8.21.2, sha256-verified (not bumped, to avoid finding churn) | | semgrep / ruff | latest | 1.177.0 / 0.16.8 | - **Nix removed:** the store bootstrap, `nix.conf` and entrypoint seeding are gone. The firmware reproducible build is off in shared deployments (#257), and without Nix it falls back to analysis-only, which the code already handled. I updated the docs. - **Unused runtimes removed:** Go, PHP, Composer, Ruby and Bundler; nothing invokes them. `apt` no longer installs recommended packages, which dropped a full C toolchain that came in with `python3-pip`. - **`.dockerignore`:** keeps `target/` (24 GB locally), `node_modules`, `.git` and `.env` out of the build context. - **`docker-compose`:** mounts a data volume at `/data/compliance-scanner` instead of a root-owned clone volume. ## Size The old image is 1,187 MB compressed (registry manifest). The new runtime layers without the agent binary are 474 MB, so with the binary it's roughly half. ## Verification - `docker build --check` passes for all three Dockerfiles. `cargo fmt`, clippy on both dashboard feature sets and the dashboard tests (28) pass. - I built the new `tools` stage locally. The builder stage is skipped because it's a full, unbounded cargo build plus the private Firmwerk dependency. Running as uid 10001: - every tool reports its pinned version; - `cargo generate-lockfile` and `cargo metadata` resolve a real dependency; - semgrep and syft scans work, with caches landing in `$HOME`; - there is no nix, go, php, ruby, composer or C compiler in the image. - **End to end**, with the new runtime plus the current staging agent binary, a fresh named volume and local Mongo: - `docker inspect` shows `User=app`, `Health=healthy`; - the volume came up owned by `app`, and the snapshot was seeded into it; - a manual scan of `github.com/dtolnay/itoa` completed as uid 10001 (every stage, `Cargo.lock` generated, 67 SBOM entries, 18 findings) with no permission errors. - A root-owned volume makes the entrypoint stop with `…/artifacts is not writable by uid 10001` and the fix command. - MCP runtime with the current binary: uid 10001 and **healthy**. Dashboard runtime: uid 10001, serves `/` with 200. Its `/health` ships in this PR, so the old binary can't show it. ## After deploy (manual, on the stage node) - Delete the old volumes the orca PR stops mounting: - the Nix store `orca-pruefwerk-stage-nixstore` - the agent's former `/data/compliance-scanner/ssh` volume, which **still holds the shared SSH deploy key removed in #255** - I'll file a follow-up for the Rust toolchain: at 626 MB uncompressed, it's now the largest layer. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-09-21 16:57:28 +00:00
feat(platform): harden the container images (#261)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 6m36s
0f6d88b1a1
- Agent, dashboard and MCP run as an unprivileged user (uid 10001). The agent
  writes only to its home (tool caches), /data/compliance-scanner (uploaded
  artifacts, the OSCAL snapshot; mount a volume there) and /tmp (git
  checkouts). If a volume created by an older root image is not writable, the
  entrypoint stops with the chown command that fixes it.
- Docker HEALTHCHECKs: agent /api/v1/health, MCP /health, and a new dashboard
  /health route outside /api (no session needed). #262 makes the probes check
  dependencies.
- Pinned tools: Rust 1.98.1 (installed system-wide, per-user CARGO_HOME),
  cargo-audit 0.22.2 (`--locked`, compiled in its own stage so the runtime has
  no C toolchain), syft 1.52.0 and gitleaks 8.21.2 (sha256-verified), semgrep
  1.177.0 and ruff 0.16.8. They are recorded in
  /opt/pruefwerk/tool-versions.json for the evidence pack.
- Removed Nix (store bootstrap, nix.conf, entrypoint seeding) and runtimes
  nothing invokes (Go, PHP, Composer, Ruby, Bundler), and install without
  recommended packages. The runtime layers shrink from about 1.19 GB to about
  0.5 GB compressed.
- .dockerignore keeps target/ (24 GB locally), node_modules, .git and .env out
  of the build context.
- docker-compose mounts a data volume instead of a root-owned clone volume.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 0444f18a8e into main 2026-09-21 17:28:24 +00:00
sharang deleted branch feat/container-hardening 2026-09-21 17:28:25 +00:00
Sign in to join this conversation.