no-mistakes(test): Verify timeout enforces limit before sandbox exec
This commit is contained in:
1 parent
59bdaa6e2a
commit
78424d2778
2 files changed
+24
-4
No files matched your search
@@ -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" "$@"
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in new issue
Block a user