feat(plan-01): Phase 1 — relocate harness code to packages/casan-harness (symlink facade)
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>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
2c765c9a45
commit
664bd1f00c
+68
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# CASAN Track C — TRUE runtime isolation via container (C6 / V22, production form).
|
||||
#
|
||||
# Upgrades the static-policy scaffold (sandbox-run.sh) to real kernel isolation:
|
||||
# the command runs inside a locked-down container where the KERNEL — not a grep —
|
||||
# neutralises escapes:
|
||||
# --network=none → no egress at all
|
||||
# --read-only → root filesystem is immutable (can't write outside workspace)
|
||||
# --pids-limit → fork bombs are capped
|
||||
# --memory/--cpus → resource abuse is bounded
|
||||
# -v <ws>:/work:rw → ONLY the workspace is writable; host $HOME/.ssh is NOT mounted
|
||||
# --cap-drop=ALL --security-opt=no-new-privileges → no privilege escalation
|
||||
#
|
||||
# Usage:
|
||||
# sandbox-container.sh --workspace <dir> [--image busybox] [--timeout 20]
|
||||
# [--memory 256m] [--pids 128] [--cpus 1] -- <command...>
|
||||
# Exit: command's exit code · 124 timeout · 2 policy/setup error · 127 no docker.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
IMAGE="${CASAN_SANDBOX_IMAGE:-busybox}"
|
||||
WORKSPACE="$PWD"; TIMEOUT="${CASAN_SANDBOX_TIMEOUT:-20}"
|
||||
MEMORY="${CASAN_SANDBOX_MEMORY:-256m}"; PIDS="${CASAN_SANDBOX_PIDS:-128}"; CPUS="${CASAN_SANDBOX_CPUS:-1}"
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--workspace) WORKSPACE="${2:-}"; shift 2 ;;
|
||||
--image) IMAGE="${2:-}"; shift 2 ;;
|
||||
--timeout) TIMEOUT="${2:-}"; shift 2 ;;
|
||||
--memory) MEMORY="${2:-}"; shift 2 ;;
|
||||
--pids) PIDS="${2:-}"; shift 2 ;;
|
||||
--cpus) CPUS="${2:-}"; shift 2 ;;
|
||||
--) shift; break ;;
|
||||
*) echo "sandbox-container: unknown arg $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
[[ "$#" -ge 1 ]] || { echo "Usage: sandbox-container.sh --workspace <dir> -- <command...>" >&2; exit 2; }
|
||||
|
||||
command -v docker >/dev/null 2>&1 || { echo "SANDBOX_CONTAINER_NO_DOCKER" >&2; exit 127; }
|
||||
docker info >/dev/null 2>&1 || { echo "SANDBOX_CONTAINER_DOCKER_DOWN" >&2; exit 127; }
|
||||
|
||||
WS_ABS="$(cd "$WORKSPACE" 2>/dev/null && pwd)" || { echo "SANDBOX_CONTAINER_BAD_WORKSPACE" >&2; exit 2; }
|
||||
|
||||
# Join the command into a single shell string to run inside the container.
|
||||
CMD="$*"
|
||||
|
||||
# Hardened container. --init reaps zombies; tmpfs gives a small writable /tmp
|
||||
# without a writable rootfs. The wall-clock timeout goes through tool-exec.sh
|
||||
# (portable: `timeout` if present, else a perl alarm — macOS has no coreutils
|
||||
# `timeout`). Container name is tracked so a timed-out container is force-removed.
|
||||
CID="casan-sbx-$$-${RANDOM}"
|
||||
set +e
|
||||
bash "$SCRIPT_DIR/tool-exec.sh" "$TIMEOUT" -- \
|
||||
docker run --rm --init --name "$CID" \
|
||||
--network=none --read-only \
|
||||
--pids-limit="$PIDS" --memory="$MEMORY" --cpus="$CPUS" \
|
||||
--cap-drop=ALL --security-opt=no-new-privileges \
|
||||
--tmpfs /tmp:rw,size=16m \
|
||||
-v "$WS_ABS":/work:rw -w /work \
|
||||
"$IMAGE" sh -c "$CMD"
|
||||
rc=$?
|
||||
set -e
|
||||
if [[ "$rc" -eq 124 ]]; then
|
||||
docker rm -f "$CID" >/dev/null 2>&1 || true
|
||||
echo "SANDBOX_CONTAINER_TIMEOUT after ${TIMEOUT}s" >&2
|
||||
exit 124
|
||||
fi
|
||||
exit "$rc"
|
||||
Reference in New Issue
Block a user