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>
63 lines
3.2 KiB
Bash
Executable File
63 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN H5 — Key-management (KMS) + external WORM audit tests (C5/B3 · V21).
|
|
#
|
|
# ① KMS (Vault Transit): sign→verify, rotate→sign→verify, prove NON-exportable.
|
|
# Skip-aware — runs live only when Vault is reachable (VAULT_ADDR/TOKEN set),
|
|
# mirroring the Ollama-dependent tests; SKIP counts as pass otherwise.
|
|
# ② WORM ledger: ship anchors → in-sync; roll back local audit → AUDIT_GAP_DETECTED;
|
|
# tamper the ledger → AUDIT_LEDGER_TAMPERED. Always runs (deterministic, local).
|
|
|
|
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"
|
|
WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
|
|
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)"
|
|
}
|
|
|
|
echo "===== ① H5 key management — Vault KMS (live if reachable) ====="
|
|
if [[ -n "${VAULT_ADDR:-}" && -n "${VAULT_TOKEN:-}" ]] && curl -sf "$VAULT_ADDR/v1/sys/health" >/dev/null 2>&1; then
|
|
KEY="casan-test-$$"
|
|
printf 'audit-head-%s\n' "$$" > "$WORK/head.txt"
|
|
bash "$S/vault-kms.sh" enable-transit >/dev/null 2>&1
|
|
bash "$S/vault-kms.sh" sign "$WORK/head.txt" "$WORK/h1.sig" "$KEY" >/dev/null 2>&1
|
|
expect_rc 0 "KMS signs + verifies head (v1)" bash "$S/vault-kms.sh" verify "$WORK/head.txt" "$WORK/h1.sig" "$KEY"
|
|
bash "$S/vault-kms.sh" rotate "$KEY" >/dev/null 2>&1
|
|
bash "$S/vault-kms.sh" sign "$WORK/head.txt" "$WORK/h2.sig" "$KEY" >/dev/null 2>&1
|
|
expect_rc 0 "KMS signs + verifies after key rotation (v2)" bash "$S/vault-kms.sh" verify "$WORK/head.txt" "$WORK/h2.sig" "$KEY"
|
|
expect_rc 0 "KMS signing key is NON-exportable (private material never leaves KMS)" bash "$S/vault-kms.sh" assert-nonexportable "$KEY"
|
|
else
|
|
echo " SKIP Vault KMS (set VAULT_ADDR/VAULT_TOKEN + reachable to run live)"; PASS=$((PASS+3))
|
|
fi
|
|
|
|
echo "===== ② H5 external WORM audit ledger ====="
|
|
LEDGER="$WORK/anchor-ledger.jsonl"
|
|
H="$WORK/head.txt"
|
|
printf 'HEAD-1\n' > "$H"; bash "$S/audit-ship.sh" "$H" "$LEDGER" >/dev/null 2>&1
|
|
printf 'HEAD-2\n' > "$H"; bash "$S/audit-ship.sh" "$H" "$LEDGER" >/dev/null 2>&1
|
|
expect_rc 0 "WORM in-sync when local head matches the latest anchor" \
|
|
bash "$S/verify-audit-gap.sh" "$H" "$LEDGER"
|
|
# roll back local audit tip to an older head that was already durably anchored
|
|
printf 'HEAD-1\n' > "$H"
|
|
expect_rc 1 "WORM detects local audit rollback (AUDIT_GAP_DETECTED)" \
|
|
bash "$S/verify-audit-gap.sh" "$H" "$LEDGER"
|
|
grep -q "AUDIT_GAP_DETECTED" <(bash "$S/verify-audit-gap.sh" "$H" "$LEDGER" 2>&1) \
|
|
&& pass "WORM rollback reason is AUDIT_GAP_DETECTED" || fail "WORM rollback reason wrong"
|
|
# tamper the ledger itself (edit an anchored head)
|
|
printf 'HEAD-2\n' > "$H"
|
|
sed -i.bak 's/HEAD-1/HACKED/' "$LEDGER" 2>/dev/null || sed -i '' 's/HEAD-1/HACKED/' "$LEDGER"
|
|
expect_rc 1 "WORM detects a tampered ledger (AUDIT_LEDGER_TAMPERED)" \
|
|
bash "$S/verify-audit-gap.sh" "$H" "$LEDGER"
|
|
|
|
echo ""
|
|
echo "===== H5 INFRA SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
|
[[ "$FAIL" -eq 0 ]] || exit 1
|