feat(controls): ship a CRA catalog snapshot, map without the backend
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 5m55s

Control mapping was gated on BREAKPILOT_BASE_URL, so on staging (where
breakpilot-compliance is not reachable until the dsms migration) every
finding came back without control_refs. The catalog loader already
snapshots fetched bytes and falls back to them offline; this makes the
snapshot a first-class source:

- the provider takes an optional base URL and serves snapshots alone,
- the agent image ships compliance-agent/controls/snapshot (CRA Annex I,
  40 controls, built by breakpilot-compliance's build_cra_catalog) and
  the entrypoint seeds it into BREAKPILOT_SNAPSHOT_DIR if absent, so a
  snapshot refreshed from a live backend always wins,
- scripts/refresh-oscal-snapshot.sh regenerates the committed files.

master-controls stays DB-derived and unshipped, so the semantic pass is
still a no-op offline; run those environments with
BREAKPILOT_SEMANTIC_MAPPING=false.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
Sharang ParnerkarandClaude Opus 5 committed 2026-09-12 20:20:04 +02:00
1 parent 7eb4d8054a
commit 3c8de961aa
9 files changed
+2935 -41

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Refresh the committed OSCAL catalog snapshots from a breakpilot-compliance
# backend. The agent image ships these files and seeds them into
# BREAKPILOT_SNAPSHOT_DIR on start, so control mapping works without the
# backend (see docs/features/control-mapping.md).
#
# BREAKPILOT_BASE_URL=https://api-dev.breakpilot.ai \
# BREAKPILOT_TOKEN=<bearer> \
# scripts/refresh-oscal-snapshot.sh [framework ...]
#
# Default frameworks: cra. `master-controls` is DB-derived and large (~3k
# controls); pass it explicitly when the backend is healthy and you want the
# semantic pass to work offline too.
set -euo pipefail
: "${BREAKPILOT_BASE_URL:?set BREAKPILOT_BASE_URL}"
out="$(cd "$(dirname "$0")/.." && pwd)/compliance-agent/controls/snapshot"
mkdir -p "$out"
frameworks=("$@")
[ ${#frameworks[@]} -eq 0 ] && frameworks=(cra)
for fw in "${frameworks[@]}"; do
url="${BREAKPILOT_BASE_URL%/}/api/compliance/v1/oscal/catalog?framework=${fw}"
tmp="$(mktemp)"
code=$(curl -sS -o "$tmp" -w '%{http_code}' \
${BREAKPILOT_TOKEN:+-H "Authorization: Bearer ${BREAKPILOT_TOKEN}"} "$url")
if [ "$code" != "200" ]; then
echo "refresh-oscal-snapshot: $fw -> HTTP $code" >&2
head -c 200 "$tmp" >&2; echo >&2
rm -f "$tmp"; exit 1
fi
python3 -c 'import json,sys; json.dump(json.load(open(sys.argv[1])), open(sys.argv[2],"w"), indent=2, ensure_ascii=False); open(sys.argv[2],"a").write("\n")' \
"$tmp" "$out/oscal-catalog-${fw}.json"
rm -f "$tmp"
n=$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); c=d.get("catalog",d); print(sum(len(g.get("controls",[])) for g in c.get("groups",[])))' "$out/oscal-catalog-${fw}.json")
echo "refresh-oscal-snapshot: $fw -> $out/oscal-catalog-${fw}.json ($n controls)"
done