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>
66 lines
2.3 KiB
Bash
66 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Plan-16 SEC-20 (ARCH-04 / ARCH-09) — verify the required toolchain.
|
|
#
|
|
# Gate verdicts depend on external binaries (python/openssl/grep/sha256sum...). If
|
|
# one is MISSING the control can silently no-op (ARCH-09); if one is PATH-SHADOWED
|
|
# by an attacker-planted copy (ARCH-04, e.g. a fake `grep` that always matches
|
|
# nothing) the attacker controls the verdict. This fails CLOSED:
|
|
# * a required tool that is not found -> refuse,
|
|
# * a tool resolving INSIDE the workspace / cwd -> refuse (planted binary),
|
|
# * with CASAN_TOOLCHAIN_TRUSTED_DIRS set, a tool outside those dirs -> refuse.
|
|
#
|
|
# Usage: toolchain-verify.sh [tool ...] (default: python3 openssl grep awk sed)
|
|
# Env: CASAN_TOOLCHAIN_TRUSTED_DIRS=/usr/bin:/bin:... (opt-in allowlist; prod sets it)
|
|
# Exit: 0 ok, 1 missing/shadowed/untrusted.
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/casan-paths.sh"
|
|
PROJECT_ROOT="$CASAN_APP_ROOT"
|
|
|
|
REQUIRED=("$@")
|
|
if [[ ${#REQUIRED[@]} -eq 0 ]]; then
|
|
REQUIRED=(python3 openssl grep awk sed)
|
|
fi
|
|
|
|
IFS=':' read -r -a TRUSTED <<< "${CASAN_TOOLCHAIN_TRUSTED_DIRS:-}"
|
|
|
|
fail=0
|
|
for tool in "${REQUIRED[@]}"; do
|
|
path="$(command -v "$tool" 2>/dev/null || true)"
|
|
if [[ -z "$path" ]]; then
|
|
echo "TOOLCHAIN_MISSING tool=$tool (fail-closed)" >&2
|
|
fail=1; continue
|
|
fi
|
|
# Resolve to a real, absolute path (follow the symlink dir).
|
|
dir="$(cd "$(dirname "$path")" 2>/dev/null && pwd -P || echo "")"
|
|
real="$dir/$(basename "$path")"
|
|
|
|
# A required tool resolving inside the repo / cwd is a planted-binary red flag.
|
|
case "$real" in
|
|
"$PROJECT_ROOT"/*|"$PWD"/*|./*)
|
|
echo "TOOLCHAIN_SHADOWED tool=$tool path=$real (fail-closed)" >&2
|
|
fail=1; continue ;;
|
|
esac
|
|
|
|
# Opt-in allowlist: in prod the tool MUST live under a trusted system dir.
|
|
if [[ -n "${CASAN_TOOLCHAIN_TRUSTED_DIRS:-}" ]]; then
|
|
ok=0
|
|
for pfx in "${TRUSTED[@]}"; do
|
|
[[ -n "$pfx" ]] || continue
|
|
case "$real" in "$pfx"/*) ok=1; break ;; esac
|
|
done
|
|
if [[ "$ok" -ne 1 ]]; then
|
|
echo "TOOLCHAIN_UNTRUSTED_PATH tool=$tool path=$real (not under CASAN_TOOLCHAIN_TRUSTED_DIRS)" >&2
|
|
fail=1
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if [[ "$fail" -eq 0 ]]; then
|
|
echo "TOOLCHAIN_OK tools=${#REQUIRED[@]}"
|
|
exit 0
|
|
fi
|
|
exit 1
|