Files
CASAN/AINative_OKR_CASAN5/.specify/scripts/bash/audit-ship.sh
T
thanhnvandClaude Opus 4.8 86e13a26ed 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>
2026-07-04 23:16:21 +09:00

26 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -uo pipefail
# CASAN H5 — Ship the audit head to an external append-only WORM ledger (C5/V21).
# Call after each audit seal. Locally this appends a hash-linked anchor to a
# ledger on a separate path (default outside .specify/logs/audit); production
# ships to S3 Object Lock / QLDB. On Linux the ledger is best-effort set
# append-only immutable (chattr +a).
#
# Usage: audit-ship.sh [head-file] [ledger-file]
# Env: CASAN_WORM_LEDGER (default .specify/logs/worm/anchor-ledger.jsonl)
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}}"
mkdir -p "$(dirname "$LEDGER")"
[[ -f "$HEAD_FILE" ]] || { echo "AUDIT_SHIP_NO_HEAD file=$HEAD_FILE" >&2; exit 1; }
# Append-only immutability on Linux (best-effort; no-op on macOS/CI without cap).
if command -v chattr >/dev/null 2>&1; then chattr -a "$LEDGER" 2>/dev/null || true; fi
python "$SCRIPT_DIR/worm-ledger.py" ship "$HEAD_FILE" "$LEDGER"; RC=$?
if command -v chattr >/dev/null 2>&1; then chattr +a "$LEDGER" 2>/dev/null || true; fi
exit "$RC"