Files
CASAN/AINative_OKR_CASAN5/packages/casan-harness/scripts/bash/artifact-attest.sh
T
thanhnvandClaude Opus 4.8 664bd1f00c feat(plan-01): Phase 1 — relocate harness code to packages/casan-harness (symlink facade)
Physically move the pure-code subtrees out of .specify into the package, leaving
compat symlinks at the old .specify/<dir> paths so every existing reference (internal
CASAN_HARNESS_ROOT + external CI/docker/mjs) keeps resolving. Runtime state stays put.

Moved (git mv): scripts/ tests/ security/ templates/ config/ governance/ memory/
  .specify/<dir>  ->  packages/casan-harness/<dir>   (+ .specify/<dir> symlink)
Stays in .specify (state/governance/domain, handled later): logs/ agentops/ level5/
  init-options.json traceability-map.json

Python `.resolve()` self-location followed the compat symlink into packages and lost
the app root; generate-casan-demo-context.py, generate-agentops-dashboard.py and
dashboard-server.py now walk UP for the `.specify` state marker instead of a fixed
parent depth (fixes "missing trace files" in run-casan4).

Full gate: PASS=64 FAIL=0 SKIP=3 (CASAN_CI_STEP_TIMEOUT_SEC=1200 — track-a ~450s runs
close to the 600s default and can tip over under load; this is timing variance, not a
regression — it passed cleanly with headroom). Runtime log/audit artifacts kept unstaged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 00:06:00 +09:00

61 lines
2.8 KiB
Bash

#!/usr/bin/env bash
set -uo pipefail
# CASAN Plan-16 SEC-25 (SC-07, offline) — build-artifact attestation (tested==deployed).
#
# A green CI gate proves the TESTED artifact is sound, but nothing binds it to what
# is DEPLOYED — a different artifact could ship. This produces a signed attestation
# over an artifact's content hash; verification recomputes the hash and checks the
# signature, so a swapped/modified artifact (deployed != tested) or a forged
# attestation is REFUSED (fail-closed). Offline form of SLSA-style provenance;
# real signed-commit enrollment + full provenance chain need CI/key infra.
#
# Usage:
# artifact-attest.sh attest <artifact> <priv-key> # -> <artifact>.att (+ .att.sig)
# artifact-attest.sh verify <artifact> <attestation> <pub> # tested==deployed check
# Exit: 0 ok · 2 mismatch/forged/tampered · 3 missing/unsigned/openssl · 64 usage.
CMD="${1:-}"; ART="${2:-}"
command -v openssl >/dev/null 2>&1 || { echo "OPENSSL_UNAVAILABLE" >&2; exit 3; }
sha256_of() {
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}'
else shasum -a 256 "$1" | awk '{print $1}'; fi
}
case "$CMD" in
attest)
KEY="${3:-}"
[[ -f "$ART" && -f "$KEY" ]] || { echo "usage: artifact-attest.sh attest <artifact> <priv-key>" >&2; exit 64; }
H="$(sha256_of "$ART")"
ATT="$ART.att"
printf '{"artifact":"%s","sha256":"%s","attested_at":"%s"}\n' \
"$(basename "$ART")" "$H" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$ATT"
openssl dgst -sha256 -sign "$KEY" -out "$ATT.sig" "$ATT" 2>/dev/null \
|| { echo "ATTEST_SIGN_FAILED" >&2; exit 2; }
echo "ARTIFACT_ATTESTED artifact=$(basename "$ART") sha256=${H:0:16}… att=$ATT"
exit 0
;;
verify)
ATT="${3:-}"; KEY="${4:-}"
[[ -f "$ART" ]] || { echo "ARTIFACT_MISSING file=$ART" >&2; exit 3; }
[[ -n "$ATT" && -f "$ATT" ]] || { echo "ATTESTATION_MISSING file=$ATT — refusing (fail-closed)" >&2; exit 3; }
[[ -f "$KEY" ]] || { echo "ATTEST_PUBKEY_MISSING key=$KEY" >&2; exit 3; }
[[ -f "$ATT.sig" ]] || { echo "ATTESTATION_UNSIGNED file=$ATT — refusing (fail-closed)" >&2; exit 3; }
if ! openssl dgst -sha256 -verify "$KEY" -signature "$ATT.sig" "$ATT" >/dev/null 2>&1; then
echo "ATTESTATION_FORGED file=$ATT — tampered or wrong key" >&2; exit 2
fi
WANT="$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1])).get("sha256",""))' "$ATT" 2>/dev/null)"
HAVE="$(sha256_of "$ART")"
if [[ -z "$WANT" || "$WANT" != "$HAVE" ]]; then
echo "ARTIFACT_MISMATCH deployed!=tested want=${WANT:0:16}… have=${HAVE:0:16}…" >&2; exit 2
fi
echo "ARTIFACT_VERIFIED tested==deployed sha256=${HAVE:0:16}…"
exit 0
;;
*)
echo "Usage: artifact-attest.sh {attest <artifact> <priv>|verify <artifact> <att> <pub>}" >&2
exit 64
;;
esac