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" "$@"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user