feat(h5): ① KMS key rotation/non-exportable + ② external WORM audit ledger

① 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>
This commit is contained in:
thanhnv
2026-07-04 23:16:21 +09:00
co-authored by Claude Opus 4.8
parent e21a1472b1
commit 86e13a26ed
5 changed files with 246 additions and 1 deletions
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -uo pipefail
# CASAN H5 — Detect audit rollback / evidence deletion vs the WORM ledger (C5/V21).
# Verifies the external anchor ledger is internally intact (hash-linked) AND that
# the local audit head has not been rolled back below the durable anchor. Deleting
# the tail of the local audit log surfaces as AUDIT_GAP_DETECTED because the WORM
# ledger still holds the later head.
#
# Usage: verify-audit-gap.sh [head-file] [ledger-file]
# Exit: 0 in-sync, 1 tamper/gap/unshipped, 64 usage.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
HEAD_FILE="${1:-$PROJECT_ROOT/.specify/logs/audit/audit-head.txt}"
LEDGER="${2:-${CASAN_WORM_LEDGER:-$PROJECT_ROOT/.specify/logs/worm/anchor-ledger.jsonl}}"
[[ -f "$HEAD_FILE" ]] || { echo "AUDIT_GAP_NO_HEAD file=$HEAD_FILE" >&2; exit 1; }
python "$SCRIPT_DIR/worm-ledger.py" verify "$HEAD_FILE" "$LEDGER"