Closes the last fully-[planned] Track-C dimension (was scored 1). - incident.sh raise <event>: classify severity via incident-severity.map (LOW/MED/HIGH/CRIT), record a structured entry (owner routing), and for HIGH/CRIT auto-engage the scoped kill-switch + dispatch an alert (reuses H6 alert-dispatch.sh). Exit 2 on HIGH/CRIT so a pipeline gate goes red. - kill-switch.sh engage/clear/check/status, scoped by project/model/provider (+ global). `check` exits 2 when engaged so gates honor it. - casan-harness.sh honors an engaged kill-switch before running (opt-in CASAN_KILLSWITCH_ENFORCE=1, default OFF → baseline unchanged). - incident-runbook.md: severity→owner→response + postmortem template + prod TODO. - phase-c7-incident-tests.sh: 15 checks — severity grading, auto kill-switch on HIGH/CRIT, MED-only records, lifecycle, global scope, structured record, and the production wrapper refusing to run under an engaged switch. Baselines: run-casan4 35/35, adversarial 44/44. New suite total: 175 → 190. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
82 lines
4.2 KiB
Bash
Executable File
82 lines
4.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN C7 — Incident response + kill-switch tests (V23).
|
|
#
|
|
# Proves: a detected event is graded (severity map), recorded, and for HIGH/CRIT
|
|
# the scoped kill-switch auto-engages (gates honoring it then stop); MED/LOW only
|
|
# record. Kill-switch check/clear and global scope work. Deterministic, no infra.
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
S="$PROJECT_ROOT/.specify/scripts/bash"
|
|
WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
|
|
export CASAN_KILLSWITCH_DIR="$WORK/ks" # isolate the kill-switch state
|
|
PASS=0; FAIL=0
|
|
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
|
|
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
|
|
expect_rc() {
|
|
local want="$1" desc="$2"; shift 2
|
|
local got=0; { "$@" >/dev/null 2>&1; } || got=$?
|
|
[[ "$got" -eq "$want" ]] && pass "$desc (rc=$got)" || fail "$desc (got rc=$got, want $want)"
|
|
}
|
|
|
|
INC() { bash "$S/incident.sh" "$@"; }
|
|
KS() { bash "$S/kill-switch.sh" "$@"; }
|
|
|
|
echo "===== C7: severity classification + auto kill-switch ====="
|
|
# CRIT event -> exit 2 + kill-switch engaged for its scope
|
|
OUT="$(INC raise secret-to-cloud "key in prompt" --scope model --id m1 2>/dev/null)"; RC=$?
|
|
{ [[ "$RC" -eq 2 ]] && printf '%s' "$OUT" | grep -q "sev=CRIT" && printf '%s' "$OUT" | grep -q "kill_switch_engaged"; } \
|
|
&& pass "CRIT event (secret-to-cloud) → exit 2 + kill-switch engaged" \
|
|
|| fail "CRIT handling wrong (rc=$RC out=$OUT)"
|
|
expect_rc 2 "kill-switch now blocks that scope (model/m1)" KS check model m1
|
|
|
|
# HIGH event also engages
|
|
expect_rc 2 "HIGH event (audit-chain-broken) → exit 2" INC raise audit-chain-broken "line 1" --scope project --id p1
|
|
expect_rc 2 "kill-switch blocks project/p1 after HIGH" KS check project p1
|
|
|
|
# MED event: recorded only, no kill-switch
|
|
expect_rc 0 "MED event (cost-budget-exceeded) → exit 0 (recorded, no kill)" INC raise cost-budget-exceeded "3x budget" --scope model --id m2
|
|
expect_rc 0 "kill-switch stays clear for a MED-only scope (model/m2)" KS check model m2
|
|
|
|
# Unknown event → default severity (MED) → recorded, no kill
|
|
expect_rc 0 "unknown event → default MED (recorded, no kill)" INC raise some-unmapped-thing --scope model --id m3
|
|
|
|
echo "===== C7: kill-switch lifecycle + global scope ====="
|
|
expect_rc 0 "clear an engaged switch" KS clear model m1 "resolved-in-test"
|
|
expect_rc 0 "cleared scope is unblocked again" KS check model m1
|
|
KS engage global all "org-wide freeze" >/dev/null 2>&1
|
|
expect_rc 2 "global kill-switch blocks ANY scope" KS check model brand-new
|
|
KS clear global all "unfreeze" >/dev/null 2>&1
|
|
expect_rc 0 "after clearing global, scopes flow again" KS check model brand-new
|
|
|
|
echo "===== C7: incident record is structured (severity + owner) ====="
|
|
REC="$(INC raise private-key-exposure "id_rsa in output" --scope provider --id prov1 2>/dev/null)" || true
|
|
LOGF="$PROJECT_ROOT/.specify/logs/level5/incidents.jsonl"
|
|
if tail -5 "$LOGF" 2>/dev/null | grep -qE '"severity": ?"CRIT"' && tail -5 "$LOGF" 2>/dev/null | grep -qE '"owner": ?"security-oncall"'; then
|
|
pass "incident recorded with severity + owner (routable)"
|
|
else
|
|
fail "incident record missing severity/owner"
|
|
fi
|
|
KS clear provider prov1 "test-cleanup" >/dev/null 2>&1 || true
|
|
|
|
echo "===== C7: production wrapper honors the kill-switch ====="
|
|
printf 'benign task input\n' > "$WORK/w.txt"
|
|
# switch clear → wrapper runs normally
|
|
expect_rc 0 "wrapper runs when kill-switch is clear (enforce on)" \
|
|
env CASAN_KILLSWITCH_ENFORCE=1 CASAN_KILLSWITCH_SCOPE=project CASAN_KILLSWITCH_ID=wf1 \
|
|
bash "$S/casan-harness.sh" "$WORK/w.txt" "$WORK/wo.txt" agent_step
|
|
KS engage project wf1 "drill" >/dev/null 2>&1
|
|
expect_rc 2 "wrapper REFUSES to run when kill-switch engaged" \
|
|
env CASAN_KILLSWITCH_ENFORCE=1 CASAN_KILLSWITCH_SCOPE=project CASAN_KILLSWITCH_ID=wf1 \
|
|
bash "$S/casan-harness.sh" "$WORK/w.txt" "$WORK/wo.txt" agent_step
|
|
expect_rc 0 "wrapper ignores engaged switch when enforcement is OFF (backward compat)" \
|
|
env CASAN_KILLSWITCH_SCOPE=project CASAN_KILLSWITCH_ID=wf1 \
|
|
bash "$S/casan-harness.sh" "$WORK/w.txt" "$WORK/wo.txt" agent_step
|
|
KS clear project wf1 "cleanup" >/dev/null 2>&1
|
|
|
|
echo ""
|
|
echo "===== C7 INCIDENT SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
|
[[ "$FAIL" -eq 0 ]] || exit 1
|