diff --git a/home/bin/security-audit-sandbox b/home/bin/security-audit-sandbox index a46ce92..998f66c 100755 --- a/home/bin/security-audit-sandbox +++ b/home/bin/security-audit-sandbox @@ -205,6 +205,28 @@ container_exists() { docker inspect "$1" >/dev/null 2>&1 } +WALL_CLOCK_PROBE_SECS=2 + +check_wall_clock_guard() { + local container=$1 status elapsed out + SECONDS=0 + set +e + out=$(docker exec "$container" timeout --signal=KILL "$WALL_CLOCK_PROBE_SECS" sleep 10 2>&1) + status=$? + set -e + elapsed=$SECONDS + case $status in + 124|137) ;; + *) + [ -z "$out" ] || printf '%s\n' "$out" >&2 + die "image $STATE_IMAGE's 'timeout' does not enforce '--signal=KILL'; refusing to run without a wall-clock limit" + ;; + esac + if [ "$elapsed" -lt 1 ] || [ "$elapsed" -gt $((WALL_CLOCK_PROBE_SECS + 4)) ]; then + die "image $STATE_IMAGE's 'timeout' did not stop the probe after ${WALL_CLOCK_PROBE_SECS}s; refusing to run without a wall-clock limit" + fi +} + check_run_dir() { local dir=$1 case $dir in @@ -446,9 +468,7 @@ cmd_exec() { container=$STATE_CONTAINER container_running "$container" || die "container $container is not running; run '$PROG stop $app_arg' and start again" - if ! docker exec "$container" sh -c 'command -v timeout >/dev/null 2>&1'; then - die "image $STATE_IMAGE has no 'timeout' binary; refusing to run without a wall-clock limit" - fi + check_wall_clock_guard "$container" docker exec --workdir /scratch/app "$container" timeout --signal=KILL "$timeout_secs" "$@" } diff --git a/readme.md b/readme.md index f71d8b8..3600f3f 100644 --- a/readme.md +++ b/readme.md @@ -76,7 +76,7 @@ Container controls: - `--memory 4g`, `--cpus 2`, `--pids-limit 256`, and `nofile=1024:1024`. - `fsize=104857600` (100 MiB) when the Docker host accepts it. Docker Desktop on macOS may refuse `fsize`; the wrapper then starts without only that cap and prints a warning. -`exec` runs the command from `/scratch/app` under `timeout --signal=KILL`, default 600 seconds. It passes no host environment variables. If the image has no `timeout` binary, `exec` refuses to run rather than dropping the wall-clock limit. +`exec` runs the command from `/scratch/app` under `timeout --signal=KILL`, default 600 seconds. It passes no host environment variables. If the image has no `timeout` binary, or its `timeout` does not enforce the `--signal=KILL` wall-clock limit, `exec` refuses to run rather than dropping the limit. `stop` removes the container, the state file, and the run directory. Pass `--keep` to keep the run directory for inspection. State lives under `${XDG_STATE_HOME:-~/.local/state}/security-audit-sandbox` and is keyed by the canonical app path, so `exec`, `stop`, and `status` find the same run.