- SEC-07 (M-08): real approval verification via approval-verify.sh in enforced mode (CASAN_PROFILE=prod / CASAN_APPROVAL_STRICT=1) for control-plane `set` (sensitive keys), kill-switch `clear`, and self-improve (inherits control-plane). A bare or forged approval string is now denied; dev mode stays backward-compatible. - SEC-10 (M-05): non-spoofable agent identity. tool-registry-gate least-privilege no longer trusts CASAN_AGENT env in enforced mode (CASAN_IDENTITY_STRICT=1) — the caller must present a signed token (agent-identity-sign.sh) bound to agent id + run id, verified against agent-identities.registry. Blocks env spoofing + replay. Verify: SEC+integrity gate 18/0, run-casan4 0-FAIL, adversarial 44/44 (H2 intact), control-plane 9/0, h5-approval 12/0, c7-incident 15/0, self-improve 7/0, track-c 29/0. Plan-16 P0 + P1 now complete; remaining: P2 (SEC-12/13/14/15/22..30). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
84 lines
4.5 KiB
Bash
84 lines
4.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Plan-16 SEC-07 (M-08) — real approval on the remaining approval sites.
|
|
#
|
|
# control-plane `set` (sensitive), self-improve `apply`, and kill-switch `clear`
|
|
# used to accept ANY non-empty approval string. In enforced mode they now require a
|
|
# REGISTERED reviewer to cryptographically sign the request (verified by
|
|
# approval-verify.sh) — a bare/forged string is denied. Dev mode stays unchanged.
|
|
#
|
|
# Self-contained: ephemeral reviewer keypair into a temp reviewers dir, using the
|
|
# committed reviewers.registry (security-lead → security role; policy_change needs
|
|
# security; kill_switch falls back to the default roles).
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
S="$PROJECT_ROOT/.specify/scripts/bash"
|
|
REG="$PROJECT_ROOT/.specify/level5/central-governance/reviewers.registry"
|
|
WORK="$(mktemp -d)"; RV="$WORK/reviewers"; mkdir -p "$RV"
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
|
|
# Ephemeral keys: a registered reviewer (security-lead) and an unregistered attacker.
|
|
openssl genrsa -out "$WORK/sl.priv" 2048 2>/dev/null
|
|
openssl rsa -in "$WORK/sl.priv" -pubout -out "$RV/security-lead.pub.pem" 2>/dev/null
|
|
openssl genrsa -out "$WORK/atk.priv" 2048 2>/dev/null
|
|
|
|
export CASAN_REVIEWERS_FILE="$REG" CASAN_REVIEWERS_DIR="$RV"
|
|
export CASAN_CP_STORE_FILE="$WORK/store.json" CASAN_CP_KEY_DIR="$WORK/cpk" CASAN_CP_PUB="$WORK/cp.pub"
|
|
|
|
PASS=0; FAIL=0
|
|
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
|
|
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
|
|
rc_of() { set +e; "$@" >/dev/null 2>&1; echo $?; set -e 2>/dev/null || true; }
|
|
|
|
echo "===== Plan-16 SEC-07: real approval verification ====="
|
|
|
|
# ---- control-plane set (security-sensitive) ----
|
|
CP="$S/control-plane-settings.py"
|
|
|
|
# Backward compat: dev (non-strict) accepts a plain --approval string.
|
|
[[ "$(rc_of python3 "$CP" set security.strict true --actor alice --reason r --approval tok)" -eq 0 ]] \
|
|
&& pass "dev mode: plain --approval string still works (backward compatible)" \
|
|
|| fail "dev-mode approval broke"
|
|
|
|
# Enforced: bare string is NOT enough.
|
|
[[ "$(rc_of env CASAN_APPROVAL_STRICT=1 python3 "$CP" set security.strict true --actor alice --reason r --approval bogus)" -eq 3 ]] \
|
|
&& pass "enforced: bare approval string is DENIED" \
|
|
|| fail "enforced mode accepted a bare approval string"
|
|
|
|
# Enforced: a valid signed approval by the registered reviewer is accepted.
|
|
printf 'security.strict' > "$WORK/keyin"
|
|
bash "$S/approval-sign.sh" policy_change alice "$WORK/keyin" security-lead "$WORK/sl.priv" "$WORK/ok.sig" >/dev/null 2>&1
|
|
[[ "$(rc_of env CASAN_APPROVAL_STRICT=1 CASAN_ACTOR=alice CASAN_APPROVER=security-lead CASAN_APPROVAL_SIG="$WORK/ok.sig" \
|
|
python3 "$CP" set security.strict true --actor alice --reason r --approval x)" -eq 0 ]] \
|
|
&& pass "enforced: valid reviewer signature is ACCEPTED" \
|
|
|| fail "enforced mode rejected a valid signed approval"
|
|
|
|
# Enforced: a forged signature (attacker key claiming to be the reviewer) is denied.
|
|
bash "$S/approval-sign.sh" policy_change alice "$WORK/keyin" security-lead "$WORK/atk.priv" "$WORK/forged.sig" >/dev/null 2>&1
|
|
[[ "$(rc_of env CASAN_APPROVAL_STRICT=1 CASAN_ACTOR=alice CASAN_APPROVER=security-lead CASAN_APPROVAL_SIG="$WORK/forged.sig" \
|
|
python3 "$CP" set security.strict true --actor alice --reason r --approval x)" -eq 3 ]] \
|
|
&& pass "enforced: forged signature is DENIED" \
|
|
|| fail "enforced mode accepted a forged signature"
|
|
|
|
# ---- kill-switch clear ----
|
|
export CASAN_KILLSWITCH_DIR="$WORK/ks"
|
|
bash "$S/kill-switch.sh" engage project ks7 "t" >/dev/null 2>&1
|
|
[[ "$(rc_of env CASAN_APPROVAL_STRICT=1 bash "$S/kill-switch.sh" clear project ks7 r)" -eq 3 ]] \
|
|
&& pass "enforced: kill-switch clear without approval is DENIED" \
|
|
|| fail "enforced kill-switch clear allowed without approval"
|
|
[[ "$(rc_of bash "$S/kill-switch.sh" check project ks7)" -eq 2 ]] \
|
|
&& pass "kill-switch remained engaged after denied clear" || fail "switch cleared despite denial"
|
|
|
|
printf 'project/ks7' > "$WORK/ksin"
|
|
bash "$S/approval-sign.sh" kill_switch admin "$WORK/ksin" security-lead "$WORK/sl.priv" "$WORK/ks.sig" >/dev/null 2>&1
|
|
[[ "$(rc_of env CASAN_APPROVAL_STRICT=1 CASAN_ACTOR=admin CASAN_APPROVER=security-lead CASAN_APPROVAL_SIG="$WORK/ks.sig" \
|
|
bash "$S/kill-switch.sh" clear project ks7 r)" -eq 0 ]] \
|
|
&& pass "enforced: kill-switch clear WITH valid approval succeeds" \
|
|
|| fail "enforced kill-switch clear rejected a valid approval"
|
|
|
|
echo ""
|
|
echo "===== SEC-07 SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
|
[[ "$FAIL" -eq 0 ]] || exit 1
|