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>
86 lines
3.3 KiB
Bash
Executable File
86 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Track C-MVP — Supply-chain gate for generated dependencies (C2, V18).
|
|
#
|
|
# An agent that writes code can also add a dependency. This gate diffs a
|
|
# dependency manifest against a baseline and decides:
|
|
# BLOCK malicious/denylisted package, typosquat of a known package,
|
|
# or a dangerous lifecycle script (postinstall/preinstall/install) -> exit 2
|
|
# REQUIRE_APPROVAL a genuinely new dependency was added -> exit 3
|
|
# (ALLOW+audit when CASAN_ACTION_APPROVER is set)
|
|
# ALLOW no new dependencies -> exit 0
|
|
#
|
|
# Supports: package.json, requirements.txt, pom.xml, build.gradle(.kts).
|
|
# When npm audit / pip-audit / osv-scanner are installed they are recorded as
|
|
# available; otherwise the local denylist (malicious-packages.txt) is authoritative.
|
|
# The diff/scan logic lives in supply-chain-scan.py (deterministic, no network).
|
|
#
|
|
# Usage: supply-chain-gate.sh <manifest> [baseline-manifest] [report.json]
|
|
# If baseline is omitted, the manifest's committed git version is used.
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/casan-paths.sh"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
|
SEC_DIR="$CASAN_HARNESS_ROOT/security"
|
|
# shellcheck source=casan-log.sh
|
|
source "$SCRIPT_DIR/casan-log.sh"
|
|
|
|
MANIFEST="${1:-}"
|
|
BASELINE="${2:-}"
|
|
REPORT="${3:-$CASAN_STATE_ROOT/logs/level5/supply-chain-report.json}"
|
|
mkdir -p "$(dirname "$REPORT")"
|
|
|
|
if [[ -z "$MANIFEST" || ! -f "$MANIFEST" ]]; then
|
|
echo "Usage: supply-chain-gate.sh <manifest> [baseline-manifest] [report.json]" >&2
|
|
exit 64
|
|
fi
|
|
|
|
# Resolve baseline: explicit file, else the manifest's committed git version,
|
|
# else empty (treat every dependency as new).
|
|
BASELINE_TMP=""
|
|
if [[ -z "$BASELINE" ]]; then
|
|
BASELINE_TMP="$(mktemp)"
|
|
REL="${MANIFEST#"$PROJECT_ROOT"/}"
|
|
if git -C "$PROJECT_ROOT" show "HEAD:$REL" > "$BASELINE_TMP" 2>/dev/null; then
|
|
BASELINE="$BASELINE_TMP"
|
|
else
|
|
: > "$BASELINE_TMP"; BASELINE="$BASELINE_TMP"
|
|
fi
|
|
fi
|
|
|
|
# Record which live scanners are available (honest capability reporting).
|
|
SCANNERS=""
|
|
for pair in "npm:npm" "pip-audit:pip-audit" "osv-scanner:osv-scanner"; do
|
|
command -v "${pair##*:}" >/dev/null 2>&1 && SCANNERS="${SCANNERS:+$SCANNERS }${pair%%:*}"
|
|
done
|
|
|
|
RESULT="$(python "$SCRIPT_DIR/supply-chain-scan.py" \
|
|
"$MANIFEST" "$BASELINE" "$SEC_DIR/known-packages.txt" "$SEC_DIR/malicious-packages.txt" \
|
|
"$REPORT" "$SCANNERS")"
|
|
RC=$?
|
|
[[ -n "$BASELINE_TMP" ]] && rm -f "$BASELINE_TMP"
|
|
[[ "$RC" -ne 0 ]] && { echo "SUPPLY_CHAIN_SCAN_ERROR rc=$RC" >&2; exit 2; }
|
|
|
|
OUTCOME="${RESULT%%|*}"
|
|
REASON="${RESULT#*|}"
|
|
APPROVER="${CASAN_ACTION_APPROVER:-}"
|
|
|
|
case "$OUTCOME" in
|
|
BLOCK)
|
|
casan_log error supply-chain "SUPPLY_CHAIN_BLOCKED $REASON"
|
|
echo "SUPPLY_CHAIN_BLOCKED reason=$REASON report=$REPORT" >&2
|
|
exit 2 ;;
|
|
REQUIRE_APPROVAL)
|
|
if [[ -n "$APPROVER" ]]; then
|
|
echo "SUPPLY_CHAIN_APPROVED by=$APPROVER new=$REASON report=$REPORT"
|
|
exit 0
|
|
fi
|
|
casan_log warn supply-chain "SUPPLY_CHAIN_REQUIRES_APPROVAL new=$REASON (set CASAN_ACTION_APPROVER=<id>)"
|
|
echo "SUPPLY_CHAIN_REQUIRES_APPROVAL new=$REASON report=$REPORT" >&2
|
|
exit 3 ;;
|
|
*)
|
|
echo "SUPPLY_CHAIN_CLEAN reason=$REASON report=$REPORT"
|
|
exit 0 ;;
|
|
esac
|