Files
CASAN/packages/casan-harness/scripts/bash/approval-jwt-mint.py
T
thanhnvandClaude Opus 4.8 36a4812ef3 refactor(structure): promote app to repo root + remove redundant workspace cruft
Standard production layout: the OKR app (was nested under AINative_OKR_CASAN5/) is now
the repository root. No more wrapper directory.

- Promote AINative_OKR_CASAN5/* -> repo root (backend/ frontend/ packages/ apps/
  .specify/ docs/ infra/ nginx/ scripts/ + configs). Merge tool dirs: .gitea (kept the
  active deploy ci.yml, added harness-ci.yml + runbooks), .claude (agents/commands +
  launch.json), .github moved up.
- Remove redundant: 00_SUBMISSION_PACKAGE, scattered root notes (FPT_CASAN_Full.md,
  tu-tuong-casan.md, casan-tu-sinh..., casan_harness_assessment.md, source-review...,
  README_CASAN5_REFINED.md), casan-next-plans/ and optimize-docs/ (competition/planning
  artifacts — roadmap + design history preserved in git log / commit messages).
- Update all references to the old layout:
  - .gitea/workflows/{ci,harness-ci}.yml, .github/workflows/{ci,deploy}.yml:
    working-directory .; drop AINative_OKR_CASAN5/ prefix; .specify/{tests,scripts}
    -> packages/casan-harness/... (.specify/logs state kept)
  - .claude/launch.json, .gitea/*-runbook.md: path prefixes
  - CLAUDE.md, README.md: docs/input -> apps/okr/domain/input
  - policy-bundle.yaml: 8 policy paths -> packages/casan-harness/...; manifest re-signed
- secrets-scan.sh: fixture excludes -> new package/domain paths.

Full gate from the new root: PASS=64 FAIL=0 SKIP=3.

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

70 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""Mint a mock IdP RS256 approval JWT for CASAN tests/dev.
The token is bound to the same high-risk request that governance-check verifies:
sub=<approver>, role=<IdP role>, action, actor, and input_sha256.
"""
import argparse
import base64
import hashlib
import json
import os
import subprocess
import sys
import tempfile
import time
def b64u(data: bytes) -> str:
return base64.urlsafe_b64encode(data).decode().rstrip("=")
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--key", required=True)
ap.add_argument("--sub", required=True)
ap.add_argument("--role", required=True)
ap.add_argument("--action", required=True)
ap.add_argument("--actor", required=True)
ap.add_argument("--input", required=True)
ap.add_argument("--exp-offset", type=int, default=300)
args = ap.parse_args()
with open(args.input, "rb") as f:
input_sha = hashlib.sha256(f.read()).hexdigest()
now = int(time.time())
header = {"alg": "RS256", "typ": "JWT"}
claims = {
"iss": "casan-mock-idp",
"sub": args.sub,
"role": args.role,
"action": args.action,
"actor": args.actor,
"input_sha256": input_sha,
"iat": now,
"exp": now + args.exp_offset,
}
signing_input = ".".join([
b64u(json.dumps(header, separators=(",", ":"), sort_keys=True).encode()),
b64u(json.dumps(claims, separators=(",", ":"), sort_keys=True).encode()),
])
with tempfile.TemporaryDirectory() as td:
msg = os.path.join(td, "msg.txt")
sig = os.path.join(td, "sig.bin")
open(msg, "wb").write(signing_input.encode())
rc = subprocess.run(
["openssl", "dgst", "-sha256", "-sign", args.key, "-out", sig, msg],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode
if rc != 0:
print("approval-jwt-mint: signing failed", file=sys.stderr)
return 1
token = signing_input + "." + b64u(open(sig, "rb").read())
print(token)
return 0
if __name__ == "__main__":
raise SystemExit(main())