Files
pruefwerk/docker/agent-entrypoint.sh
T
Sharang ParnerkarandClaude Opus 5 0f6d88b1a1
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
feat(platform): harden the container images (#261)
- 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
2026-09-21 18:56:45 +02:00

31 lines
1.3 KiB
Bash

#!/usr/bin/env bash
# Check the agent can write where it keeps data, seed the OSCAL snapshot, then
# run the agent.
set -euo pipefail
# The agent runs as an unprivileged user. A volume mounted over a data
# directory keeps the ownership it was created with, so a volume made by an
# older image that ran as root is not writable. Say how to fix it instead of
# failing on the first upload.
for dir in "${ARTIFACT_STORE_BASE_PATH:?}" "${BREAKPILOT_SNAPSHOT_DIR:?}"; do
if ! mkdir -p "$dir" 2>/dev/null || [ ! -w "$dir" ]; then
echo "agent-entrypoint: $dir is not writable by uid $(id -u)." >&2
echo "agent-entrypoint: fix the volume once with: chown -R $(id -u):$(id -g) <volume>" >&2
exit 1
fi
done
# Seed the OSCAL control-catalog snapshot. The image ships a catalog snapshot so
# control mapping works without the breakpilot-compliance backend
# (BREAKPILOT_BASE_URL unset). Copy-if-absent, so a snapshot refreshed from a
# live backend (or a mounted volume) always wins.
for f in /opt/breakpilot/oscal-snapshot/*.json; do
[ -e "$f" ] || continue
if [ ! -e "$BREAKPILOT_SNAPSHOT_DIR/$(basename "$f")" ]; then
cp "$f" "$BREAKPILOT_SNAPSHOT_DIR/" \
&& echo "agent-entrypoint: seeded $(basename "$f") into $BREAKPILOT_SNAPSHOT_DIR"
fi
done
exec compliance-agent "$@"