feat(h5): approval-identity MVP — signed reviewer approvals (C4/V20)
Under CASAN_APPROVAL_STRICT=1, a high-risk approval is trusted ONLY when a REGISTERED reviewer cryptographically signs THIS exact request and their role is authorized for the action — a plain env-var CASAN_APPROVER is no longer enough. - approval-sign.sh: reviewer signs assertion "casan-approval|v1|<action>|<actor>|<input_sha256>|<approver_id>" with their key. - approval-verify.sh: gate looks up reviewer role+pubkey in reviewers.registry, enforces role→action authorization, verifies the RSA signature (fail-closed). - governance-check.sh: strict branch requires a valid signed approval; SoD still enforced; default (non-strict) env-var path UNCHANGED (baseline preserved). - reviewers.registry: role-scoped reviewer identity registry (pubkeys off-repo; production replaces with OIDC/JWT from a real IdP). - phase-h5-approval-tests.sh: 8 checks — valid/authorized approve; unsigned, wrong-role, forged-key, unregistered, replay-to-other-request, self-approval all denied; non-strict backward-compat. Baselines: run-casan4 35/35, adversarial 44/44. Lifts H5 policy-approval (C4) 2.5 -> ~3.5-4 / 5. Total suites now 6 (+8 checks = 148). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d8583fdb2e
commit
e21a1472b1
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# CASAN H5 — Reviewer-side approval signer (Approval-identity MVP · C4 / V20).
|
||||
#
|
||||
# A reviewer runs this to APPROVE a specific high-risk request by signing the
|
||||
# canonical assertion with THEIR OWN private key. The resulting signature is
|
||||
# handed to governance-check.sh via CASAN_APPROVAL_SIG (with CASAN_APPROVER=<id>
|
||||
# and CASAN_APPROVAL_STRICT=1). The private key stays with the reviewer / in an
|
||||
# IdP-issued credential — never in the pipeline env.
|
||||
#
|
||||
# Assertion (must match approval-verify.sh):
|
||||
# casan-approval|v1|<action>|<actor>|<input_sha256>|<approver_id>
|
||||
#
|
||||
# Usage:
|
||||
# approval-sign.sh <action> <actor> <input-file> <approver-id> <privkey> <out-sig>
|
||||
# Exit: 0 signed, 64 usage, 1 sign error.
|
||||
|
||||
ACTION="${1:-}"; ACTOR="${2:-}"; INPUT_FILE="${3:-}"; APPROVER="${4:-}"; PRIV="${5:-}"; OUT="${6:-}"
|
||||
if [[ -z "$ACTION" || -z "$ACTOR" || -z "$INPUT_FILE" || -z "$APPROVER" || -z "$PRIV" || -z "$OUT" ]]; then
|
||||
echo "Usage: approval-sign.sh <action> <actor> <input-file> <approver-id> <privkey> <out-sig>" >&2
|
||||
exit 64
|
||||
fi
|
||||
[[ -f "$INPUT_FILE" ]] || { echo "approval-sign: input file not found: $INPUT_FILE" >&2; exit 1; }
|
||||
[[ -f "$PRIV" ]] || { echo "approval-sign: private key not found: $PRIV" >&2; exit 1; }
|
||||
command -v openssl >/dev/null 2>&1 || { echo "approval-sign: openssl required" >&2; exit 1; }
|
||||
|
||||
hash_file() {
|
||||
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}'
|
||||
else shasum -a 256 "$1" | awk '{print $1}'; fi
|
||||
}
|
||||
|
||||
INPUT_SHA="$(hash_file "$INPUT_FILE")"
|
||||
MSG="casan-approval|v1|$ACTION|$ACTOR|$INPUT_SHA|$APPROVER"
|
||||
TMP="$(mktemp)"; trap 'rm -f "$TMP"' EXIT
|
||||
printf '%s' "$MSG" > "$TMP"
|
||||
openssl dgst -sha256 -sign "$PRIV" -out "$OUT" "$TMP" \
|
||||
|| { echo "approval-sign: signing failed" >&2; exit 1; }
|
||||
echo "APPROVAL_SIGNED approver=$APPROVER action=$ACTION sig=$OUT"
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# CASAN H5 — Signed-approval verifier (Approval-identity MVP · C4 / V20).
|
||||
#
|
||||
# Problem: high-risk approval used to trust a plain env var (CASAN_APPROVER=bob) —
|
||||
# anyone who can set the env can "approve". This binds an approval to a REGISTERED
|
||||
# reviewer's cryptographic identity: the reviewer must SIGN this exact request with
|
||||
# their private key, AND their role must be authorized for the action class.
|
||||
#
|
||||
# The signed assertion is: casan-approval|v1|<action>|<actor>|<input_sha256>|<approver_id>
|
||||
# — so a signature for one request/reviewer cannot be replayed for another.
|
||||
#
|
||||
# Usage:
|
||||
# approval-verify.sh <action> <actor> <input-file> <approver-id> <sig-file>
|
||||
# Registry (line format, no yaml dep):
|
||||
# reviewer <id> <role> <pubkey-file>
|
||||
# action <action-name|default> <comma,roles>
|
||||
# Env: CASAN_REVIEWERS_FILE (default governance/reviewers.registry)
|
||||
# CASAN_REVIEWERS_DIR (default governance/reviewers) — base dir for pubkey-file
|
||||
# Exit: 0 ok (prints "APPROVAL_OK role=<role>"), 3 deny (reason on stderr), 64 usage.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
||||
GOV_DIR="$PROJECT_ROOT/.specify/level5/central-governance"
|
||||
REVIEWERS_FILE="${CASAN_REVIEWERS_FILE:-$GOV_DIR/reviewers.registry}"
|
||||
REVIEWERS_DIR="${CASAN_REVIEWERS_DIR:-$GOV_DIR/reviewers}"
|
||||
|
||||
ACTION="${1:-}"; ACTOR="${2:-}"; INPUT_FILE="${3:-}"; APPROVER="${4:-}"; SIG_FILE="${5:-}"
|
||||
if [[ -z "$ACTION" || -z "$ACTOR" || -z "$INPUT_FILE" || -z "$APPROVER" || -z "$SIG_FILE" ]]; then
|
||||
echo "Usage: approval-verify.sh <action> <actor> <input-file> <approver-id> <sig-file>" >&2
|
||||
exit 64
|
||||
fi
|
||||
|
||||
deny() { echo "APPROVAL_DENIED reason=$1 approver=$APPROVER action=$ACTION" >&2; exit 3; }
|
||||
|
||||
[[ -f "$INPUT_FILE" ]] || deny "input_file_missing"
|
||||
[[ -f "$SIG_FILE" ]] || deny "signature_missing"
|
||||
[[ -f "$REVIEWERS_FILE" ]] || deny "reviewer_registry_missing"
|
||||
command -v openssl >/dev/null 2>&1 || deny "openssl_unavailable"
|
||||
|
||||
hash_file() {
|
||||
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}'
|
||||
else shasum -a 256 "$1" | awk '{print $1}'; fi
|
||||
}
|
||||
|
||||
# Reviewer lookup (first matching registered reviewer).
|
||||
REV_LINE="$(awk -v id="$APPROVER" '$1=="reviewer" && $2==id {print $3" "$4; exit}' "$REVIEWERS_FILE")"
|
||||
[[ -n "$REV_LINE" ]] || deny "approver_not_registered"
|
||||
ROLE="${REV_LINE%% *}"
|
||||
PUB_REL="${REV_LINE##* }"
|
||||
|
||||
# Role authorization for this action (fallback to the "default" action policy).
|
||||
ROLES="$(awk -v a="$ACTION" '$1=="action" && $2==a {print $3; exit}' "$REVIEWERS_FILE")"
|
||||
[[ -n "$ROLES" ]] || ROLES="$(awk '$1=="action" && $2=="default" {print $3; exit}' "$REVIEWERS_FILE")"
|
||||
case ",$ROLES," in
|
||||
*",$ROLE,"*) : ;;
|
||||
*) deny "approver_role_not_authorized(role=$ROLE action=$ACTION allowed=$ROLES)" ;;
|
||||
esac
|
||||
|
||||
# Resolve pubkey path (absolute or relative to reviewers dir).
|
||||
PUB="$PUB_REL"; [[ "$PUB" = /* ]] || PUB="$REVIEWERS_DIR/$PUB_REL"
|
||||
[[ -f "$PUB" ]] || deny "approver_pubkey_missing($PUB)"
|
||||
|
||||
# Rebuild the exact signed assertion and verify.
|
||||
INPUT_SHA="$(hash_file "$INPUT_FILE")"
|
||||
MSG="casan-approval|v1|$ACTION|$ACTOR|$INPUT_SHA|$APPROVER"
|
||||
TMP="$(mktemp)"; trap 'rm -f "$TMP"' EXIT
|
||||
printf '%s' "$MSG" > "$TMP"
|
||||
openssl dgst -sha256 -verify "$PUB" -signature "$SIG_FILE" "$TMP" >/dev/null 2>&1 \
|
||||
|| deny "approval_signature_invalid"
|
||||
|
||||
echo "APPROVAL_OK role=$ROLE approver=$APPROVER action=$ACTION"
|
||||
exit 0
|
||||
@@ -88,7 +88,34 @@ if [[ "$RISK_LEVEL" == "medium" ]]; then
|
||||
fi
|
||||
|
||||
if [[ "$RISK_LEVEL" == "high" ]]; then
|
||||
if [[ "$APPROVAL_DECISION" == "approve" && -n "$APPROVER" ]]; then
|
||||
if [[ "${CASAN_APPROVAL_STRICT:-0}" == "1" ]]; then
|
||||
# Approval-identity mode (V20): an env-var approver is NOT enough — the
|
||||
# reviewer must cryptographically SIGN this exact request and their role must
|
||||
# be authorized for the action. SoD (actor != approver) still enforced.
|
||||
if [[ "$APPROVAL_DECISION" == "approve" && -n "$APPROVER" && -n "${CASAN_APPROVAL_SIG:-}" ]]; then
|
||||
if [[ "$APPROVER" == "$ACTOR" ]]; then
|
||||
APPROVAL_STATUS="separation_of_duties_violation"
|
||||
DECISION="denied"
|
||||
REASONS+=("separation-of-duties:actor-equals-approver")
|
||||
else
|
||||
AV_RC=0
|
||||
AV_OUT="$(bash "$SCRIPT_DIR/approval-verify.sh" "$ACTION_NAME" "$ACTOR" "$INPUT_FILE" "$APPROVER" "$CASAN_APPROVAL_SIG" 2>/dev/null)" || AV_RC=$?
|
||||
if [[ "$AV_RC" -eq 0 ]]; then
|
||||
APPROVAL_STATUS="human_approved_signed"
|
||||
DECISION="approved"
|
||||
REASONS+=("signed-approval:${AV_OUT#APPROVAL_OK }")
|
||||
else
|
||||
APPROVAL_STATUS="approval_signature_invalid"
|
||||
DECISION="denied"
|
||||
REASONS+=("signed-approval-failed")
|
||||
fi
|
||||
fi
|
||||
else
|
||||
APPROVAL_STATUS="approval_required_signed"
|
||||
DECISION="denied"
|
||||
REASONS+=("strict-requires-signed-approval")
|
||||
fi
|
||||
elif [[ "$APPROVAL_DECISION" == "approve" && -n "$APPROVER" ]]; then
|
||||
if [[ "$APPROVER" == "$ACTOR" ]]; then
|
||||
# Separation of duties: the submitter may not approve their own action.
|
||||
APPROVAL_STATUS="separation_of_duties_violation"
|
||||
|
||||
Reference in New Issue
Block a user