feat(controls): ship a CRA catalog snapshot, map without the backend (#250)
Demonstration plan, phase D3: on staging `BREAKPILOT_BASE_URL` points at `api-dev.breakpilot.ai`, which answers 401 until the dsms migration (M-MIG-9, parked). Control mapping was gated on that URL, so demo scans produce findings with **no control references** — the one thing a CRA prospect looks for. The catalog loader already snapshotted the bytes it fetched and fell back to them when the backend was down. This promotes the snapshot to a real source: - `OscalControlsProvider` takes `Option<String>` for the base URL; with `None` it serves snapshots only, and `has_snapshots()` decides whether control triage runs at all. - The agent image ships `compliance-agent/controls/snapshot/oscal-catalog-cra.json` — CRA Annex I, 8 groups / 40 controls, generated by breakpilot-compliance's own `build_cra_catalog()`, so it is byte-identical to what `?framework=cra` serves. The entrypoint copies it into `BREAKPILOT_SNAPSHOT_DIR` only if that file is absent, so a snapshot fetched from a live backend (or a mounted volume) always wins. - `scripts/refresh-oscal-snapshot.sh` regenerates the committed snapshots from a backend when one is reachable. - A test asserts the shipped file parses and still carries 40 controls, so a bad refresh cannot silently disable mapping. `master-controls` is DB-derived (~3k controls) and is not shipped, so the semantic pass stays a no-op offline; staging should set `BREAKPILOT_SEMANTIC_MAPPING=false` and drop `BREAKPILOT_BASE_URL` (separate orca-platform change). Deterministic LUT triage and the grounded surface checks then run against the CRA catalog and findings carry `control_refs`. Verified locally: `cargo fmt --all --check`, `cargo clippy -p compliance-agent -- -D warnings`, `cargo test -p compliance-agent --lib` (314 passed). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Reviewed-on: #250
This commit was merged in pull request #250.
This commit is contained in:
1 parent
7eb4d8054a
commit
728f3ab3bc
9 files changed
+2935
-41
No files matched your search
Executable
+37
@@ -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
|
||||
Reference in new issue
Block a user