#!/bin/sh # Derives the seccomp allowlist of the decode child from a real trace and checks it against # `sandbox::ALLOWED_SYSCALLS` (review Part IV.1: "derived by strace over the fixture corpus # at the caps on the production image, not hand-written"). Runs in the Alpine `test` stage # of crates/worker/Dockerfile, where the musl binary that ships is built. # # Exit 1 when a traced syscall is missing from the allowlist (the sandbox would kill a # legitimate decode). Syscalls the list allows but the trace never shows are printed for # review (the abort path is expected there). set -eu bin=target/release/faunosteo-worker cargo build -p faunosteo-worker --release --features test-hooks --locked work=$(mktemp -d) fixtures="png jpeg webp big-jpeg big-png" : > "$work/traced.raw" for kind in $fixtures; do "$bin" fixture "$kind" > "$work/$kind.bin" # `env -i`: the child refuses a non-empty environment; `--no-seccomp` keeps the rlimits # and makes one sched_yield where the filter would be installed (strace cannot read the # child's memory once PR_SET_DUMPABLE is 0, so the marker is a syscall, not a string). env -i strace -f -qq -o "$work/trace.$kind" "$bin" decode --no-seccomp \ < "$work/$kind.bin" > "$work/$kind.webp" awk 'found { print } /sched_yield\(/ { found = 1 }' "$work/trace.$kind" \ | sed -E 's/^[0-9]+ +//; /^(\+\+\+|---)/d; s/^<\.\.\. ([a-z0-9_]+) resumed>.*/\1/; s/\(.*//' \ | grep -E '^[a-z0-9_]+$' >> "$work/traced.raw" || true done sort -u "$work/traced.raw" > "$work/traced.txt" "$bin" print-allowlist | sort -u > "$work/allowed.txt" if [ ! -s "$work/traced.txt" ]; then echo "== NO SYSCALL TRACED AFTER THE MARKER: the derivation is broken, not the allowlist" >&2 echo "== tail of the png trace:" >&2 tail -n 40 "$work/trace.png" >&2 exit 1 fi echo "== syscalls traced after the sandbox marker" cat "$work/traced.txt" missing=$(comm -23 "$work/traced.txt" "$work/allowed.txt") extra=$(comm -13 "$work/traced.txt" "$work/allowed.txt") echo "== allowed but not traced (abort path expected): $(echo "$extra" | tr '\n' ' ')" if [ -n "$missing" ]; then echo "== TRACED BUT NOT ALLOWED (the filter would kill a legitimate decode):" echo "$missing" exit 1 fi echo "== allowlist covers the trace"