Resolve every root by marker walk-up instead of a fixed depth that only lands on the app via the .specify compat symlink, so the harness runs correctly when invoked by its real packages/casan-harness path — proven by a full gate run via that path: 64/0/0. - 95 scripts/tests: PROJECT_ROOT/ROOT "$SCRIPT_DIR/../.."-style computations -> $CASAN_APP_ROOT. - 6 leaf scripts (infra-lab, context-validate, secrets-scan, path-guard, toolchain-verify, phase2-sourcegen) now source casan-paths + use CASAN_APP_ROOT. - run-casan4: source casan-paths as a package sibling (facade-independent), PROJECT_ROOT=CASAN_APP_ROOT. - 8 Python files: project_root()/REPO_ROOT/bundle_root walk UP for the .specify marker (control-plane-settings, loop_common, model-call, context-compress, test-integrity, bundle-integrity, traceability-matrix; generate-* fixed earlier). - evidence-pack-build.py + traceability-matrix.py: domain refs -> apps/okr/domain (input/, corpus/redteam-vectors.jsonl, traceability-map.json). - ci-harness-gate.sh: export CASAN_TESTS_DIR/CASAN_TEST_MANIFEST/CASAN_BUNDLE_ROOT so the integrity Python resolves via the harness root regardless of invocation path; ROOT=CASAN_APP_ROOT. - Remove the domain compat symlinks from packages/casan-harness/security (redteam-corpus, redteam-vectors, benign-corpus) — packages now holds NO domain data. Both invocation paths pass (compat facade still present): .specify/... and packages/... 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="$CASAN_APP_ROOT"
|
|
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
|