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>
62 lines
2.9 KiB
Bash
62 lines
2.9 KiB
Bash
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Plan-16 SEC-02 (H-02) — no local key auto-generation in enforced mode.
|
|
#
|
|
# The tamper-evidence of the audit chain rests on the head signature. If the
|
|
# signer auto-generates a private key next to the data (as dev convenience does),
|
|
# then any actor who can write the log can also mint a key and re-sign a forged
|
|
# head. In enforced mode the signer must NOT auto-generate — the key is provisioned
|
|
# out-of-band (KMS/HSM). This proves:
|
|
# * permissive mode still auto-generates a local key (dev convenience),
|
|
# * enforced mode does NOT create a key when none is provisioned, and the
|
|
# resulting unsigned head then FAILS strict verification (fail-closed).
|
|
#
|
|
# Deterministic; hermetic (temp key dir + backup/restore of audit + gov dirs).
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/../scripts/bash/casan-paths.sh"
|
|
PROJECT_ROOT="$CASAN_APP_ROOT"
|
|
BASH_DIR="$CASAN_HARNESS_ROOT/scripts/bash"
|
|
WORK="$(mktemp -d)"
|
|
|
|
BK="$WORK/bak"; mkdir -p "$BK"
|
|
cp -a "$CASAN_STATE_ROOT/logs/audit" "$BK/audit" 2>/dev/null || true
|
|
cp -a "$CASAN_GOVERNANCE_ROOT" "$BK/cg" 2>/dev/null || true
|
|
restore() {
|
|
rm -rf "$CASAN_STATE_ROOT/logs/audit"; cp -a "$BK/audit" "$CASAN_STATE_ROOT/logs/audit" 2>/dev/null || true
|
|
rm -rf "$CASAN_GOVERNANCE_ROOT"; cp -a "$BK/cg" "$CASAN_GOVERNANCE_ROOT" 2>/dev/null || true
|
|
}
|
|
trap 'restore; rm -rf "$WORK"' EXIT
|
|
|
|
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-02: no local key auto-gen in enforced mode ====="
|
|
echo "benign input" > "$WORK/in.txt"
|
|
|
|
# 1) Permissive mode: a fresh key dir auto-generates a local key (dev convenience).
|
|
KD1="$WORK/keys-permissive"
|
|
env CASAN_AUDIT_KEY_DIR="$KD1" bash "$BASH_DIR/governance-check.sh" "$WORK/in.txt" "$WORK/out1.txt" agent_step >/dev/null 2>&1
|
|
[[ -f "$KD1/audit-private.pem" ]] \
|
|
&& pass "permissive mode auto-generates a local signing key" \
|
|
|| fail "permissive mode did not auto-generate a key (dev convenience broken)"
|
|
|
|
# 2) Enforced mode: a fresh key dir must NOT auto-generate a key.
|
|
KD2="$WORK/keys-enforced"
|
|
env CASAN_VERIFY_STRICT=1 CASAN_AUDIT_KEY_DIR="$KD2" bash "$BASH_DIR/governance-check.sh" "$WORK/in.txt" "$WORK/out2.txt" agent_step >/dev/null 2>&1
|
|
[[ ! -f "$KD2/audit-private.pem" ]] \
|
|
&& pass "enforced mode does NOT auto-generate a local key (H-02 closed)" \
|
|
|| fail "enforced mode auto-generated a local key (attacker could re-sign forgery)"
|
|
|
|
# 3) The unsigned head produced in enforced mode fails strict verification.
|
|
[[ "$(rc_of env CASAN_VERIFY_STRICT=1 bash "$BASH_DIR/verify-audit-chain.sh")" -ne 0 ]] \
|
|
&& pass "unsigned head from enforced run FAILS strict verify (fail-closed)" \
|
|
|| fail "unsigned head passed strict verify"
|
|
|
|
echo ""
|
|
echo "===== SEC-02 SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
|
[[ "$FAIL" -eq 0 ]] || exit 1
|