① Key management (B3/KMS): vault-kms.sh gains `rotate` (Transit key rotation) and `assert-nonexportable` (proves private material never leaves the KMS). Validated live against a Vault dev server: sign→verify (v1) → rotate → sign→verify (v2) → export denied. sign-audit-head.sh already routes to Vault when VAULT_ADDR/TOKEN are set, so this is the real production signing path. ② External WORM audit (C5/V21): worm-ledger.py + audit-ship.sh append the audit head to a hash-linked append-only ledger (chattr +a best-effort on Linux; S3 Object Lock/QLDB in production). verify-audit-gap.sh detects local audit rollback (AUDIT_GAP_DETECTED — the durable ledger still holds the later head) and ledger tampering (AUDIT_LEDGER_TAMPERED). phase-h5-infra-tests.sh: 7 checks — KMS sign/rotate/non-exportable (skip-aware, live when Vault reachable) + WORM in-sync/rollback/tamper (always local). Baselines: run-casan4 35/35, adversarial 44/44, approval 8/8. Lifts H5 key-mgmt 2.5→~4 (KMS live path + rotation + non-exportable) and external-audit 1.5→~3.5 (WORM ledger + gap detection). Suites now 7 (+7 = 155 checks). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
62 lines
3.2 KiB
Bash
Executable File
62 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)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
S="$PROJECT_ROOT/.specify/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
|