Resolve every root by marker walk-up instead of a fixed depth that only lands on the app via the .specify compat symlink, so the harness runs correctly when invoked by its real packages/casan-harness path — proven by a full gate run via that path: 64/0/0. - 95 scripts/tests: PROJECT_ROOT/ROOT "$SCRIPT_DIR/../.."-style computations -> $CASAN_APP_ROOT. - 6 leaf scripts (infra-lab, context-validate, secrets-scan, path-guard, toolchain-verify, phase2-sourcegen) now source casan-paths + use CASAN_APP_ROOT. - run-casan4: source casan-paths as a package sibling (facade-independent), PROJECT_ROOT=CASAN_APP_ROOT. - 8 Python files: project_root()/REPO_ROOT/bundle_root walk UP for the .specify marker (control-plane-settings, loop_common, model-call, context-compress, test-integrity, bundle-integrity, traceability-matrix; generate-* fixed earlier). - evidence-pack-build.py + traceability-matrix.py: domain refs -> apps/okr/domain (input/, corpus/redteam-vectors.jsonl, traceability-map.json). - ci-harness-gate.sh: export CASAN_TESTS_DIR/CASAN_TEST_MANIFEST/CASAN_BUNDLE_ROOT so the integrity Python resolves via the harness root regardless of invocation path; ROOT=CASAN_APP_ROOT. - Remove the domain compat symlinks from packages/casan-harness/security (redteam-corpus, redteam-vectors, benign-corpus) — packages now holds NO domain data. Both invocation paths pass (compat facade still present): .specify/... and packages/... Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
85 lines
4.5 KiB
Bash
85 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)"
|
|
source "$SCRIPT_DIR/../scripts/bash/casan-paths.sh"
|
|
PROJECT_ROOT="$CASAN_APP_ROOT"
|
|
S="$CASAN_HARNESS_ROOT/scripts/bash"
|
|
REG="$CASAN_GOVERNANCE_ROOT/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
|