fix(worker): security audit of R0 — no core dumps, tkill/tgkill limited to SIGABRT on self, mmap without PROT_EXEC, Broken outcome for a broken child environment, frame vs canvas check, unsafe denied with local allows, sandbox tests and derivation on the release profile (syscall marker); wasm proof exports behind a feature; ci: release-images hardened (typed input via env, advisories gate, ephemeral builder, env secrets + logout, ref gate, pinned checkout)

This commit is contained in:
bchanot committed 2026-10-13 00:18:53 +02:00
1 parent 9d3e0294e2
commit 11813f5560
14 files changed
+293 -58

No files matched your search

+38 -14
View File
@@ -89,9 +89,13 @@ a plain `main` (no async runtime, no thread), so `decode` installs its
sandbox in a single-threaded process:
- `decode`: refuses a non-empty environment; checks `Threads: 1` in
`/proc/self/status`; `RLIMIT_AS` 512 MiB, `RLIMIT_CPU` 10 s soft / 12 s
hard (soft = hard made the kernel SIGKILL first, finding §5.4); seccomp
allowlist installed with TSYNC, `KillProcess` on anything else; then reads
`/proc/self/status`; disables core dumps (`PR_SET_DUMPABLE 0`,
`RLIMIT_CORE 0`: a dump would hold the uploaded photo); `RLIMIT_AS`
512 MiB, `RLIMIT_CPU` 10 s soft / 12 s hard (soft = hard made the kernel
SIGKILL first, finding §5.4); seccomp allowlist installed with TSYNC,
`KillProcess` on anything else, with argument filters: `tkill`/`tgkill`
may only send SIGABRT to the child's own pid (never a signal to the keyed
parent or a sibling), `mmap` may not map `PROT_EXEC`; then reads
≤ 5 MiB on stdin, sniffs the format (JPEG, PNG, WebP), decodes with
`image::Limits` (sides ≤ 4096, alloc 256 MiB), applies the EXIF
orientation, `resize_to_fill` 512 × 512, encodes lossy WebP (q 82) through
@@ -100,11 +104,16 @@ sandbox in a single-threaded process:
- the parent side (`spawn::Spawner`, used by the tests now and by R1):
`env_clear`, stdin/stdout/stderr piped, output read up to 512 KiB (the
child is killed past it), 20 s deadline, classification of every exit
(`Produced`, `Rejected{code}`, `Signalled{signal}`, `OutputOverflow`,
`Timeout`, `Failed`). The parent **never decodes**: `webp_check::inspect`
parses the RIFF container only (chunk allowlist `VP8X`, `VP8 `, `VP8L`,
`ALPH`; canvas size from the headers; any `EXIF`, `XMP `, `ICCP` or unknown
chunk refuses the output; owner amendment of D-R4).
(`Produced`, `Rejected{code}` for the content codes 12 to 17,
`Broken{code}` when the child could not even start (usage, non-empty
environment, sandbox failure, internal: R1 alerts instead of blaming the
upload), `Signalled{signal}`, `OutputOverflow`, `Timeout`, `Failed`). The
parent **never decodes**: `webp_check::inspect` parses the RIFF container
only (chunk allowlist `VP8X`, `VP8 `, `VP8L`, `ALPH`; canvas size from the
headers, the frame size must agree with the canvas; any `EXIF`, `XMP `,
`ICCP` or unknown chunk refuses the output; owner amendment of D-R4). The
child's stderr (≤ 4 KiB) is child-controlled text: R1 never logs it raw
(LRN-044).
- `run --check`: prints the resolved configuration without secrets (which
variables are set, the linked libwebp version, refused below 1.6.0). A
plain `run` does nothing before R1 and says so.
@@ -116,7 +125,9 @@ sandbox in a single-threaded process:
`print-allowlist`.
Image: `crates/worker/Dockerfile`, stages `build` (release, static),
`test` (sandbox tests + `scripts/derive-seccomp.sh`), `runtime`
`test` (sandbox tests and `scripts/derive-seccomp.sh` on the **release
profile** with the `test-hooks` feature, so the binary under test differs
from the shipped one by the feature-gated hooks only), `runtime`
(`gcr.io/distroless/static-debian12:nonroot`, `USER nonroot`, `ENTRYPOINT
/faunosteo-worker`, `CMD run --check`). Measured 2026-10-12: image 8.7 MB (one static
binary), `run --check` exits 0 with `--read-only --cap-drop ALL
@@ -134,9 +145,15 @@ binary), `run --check` exits 0 with `--read-only --cap-drop ALL
started once with `--read-only --cap-drop ALL`.
- `rust-advisories.yml`: nightly and manual `cargo deny check advisories`,
out of the blocking path on purpose.
- `release-images.yml`: manual only; builds and pushes `faunosteo_app:<sha>`
and `faunosteo_worker:<sha>` to the registry of the `REGISTRY` secret and
prints their digests. Deploys nothing (DEPLOY.md "Image deploy by digest").
- `release-images.yml`: manual only, on `main` or `develop`; the dispatch
input is a typed choice re-validated through an environment variable;
the RustSec advisories gate runs first; an ephemeral `buildx` builder with
its own cache builds the images (nothing a PR build left in the daemon's
cache mounts or volumes can reach a release image); secrets reach the
shell through env only, the login lives in a per-job `DOCKER_CONFIG`
removed at the end; `actions/checkout` pinned to a commit. It pushes
`faunosteo_app:<sha>` and `faunosteo_worker:<sha>` and prints their
digests. Deploys nothing (DEPLOY.md "Image deploy by digest").
Not measured here: the forge runner's cache behaviour and cold build times
(the runner was not available from this host). The builder image build took
@@ -196,8 +213,8 @@ static binary.
neither `brk` nor `mprotect`; no `futex` in a single-threaded decode. The
allowlist is that set plus the abort path (`rt_sigaction`,
`rt_sigprocmask`, `getpid`, `gettid`, `tkill`, `tgkill`, `exit`).
- Proven on the musl binary that ships, inside Docker's default seccomp
profile: 13 tests green (`png_jpeg_and_webp_decode_through_the_full_sandbox`,
- Proven on the release-profile musl binary with the test hooks, inside
Docker's default seccomp profile: 13 tests green (`png_jpeg_and_webp_decode_through_the_full_sandbox`,
`inputs_at_the_caps_decode_within_the_limits` (4096²), dimensions 32 px
and 20 000² header, GIF and SVG refused, truncated PNG, non-empty
environment refused, `--violate` → SIGSYS 31, `--flood` → output cut,
@@ -249,6 +266,13 @@ CHROME=<chromium binary> bash docker/csp-proof/run.sh # §5.5 (playwright-core
## 7. What stays hypothetical after R0
- Follow-ups from the R0 security audit, owned by R1 unless stated: base
images pinned by digest in the three Dockerfiles (today by tag, as the
existing `Dockerfile`); a verification decode of the child's output in a
second sandboxed child (the RIFF check validates the container, not the
bitstream); the shared BuildKit cache mounts of the CI builds (the
release workflow already uses its own builder); `actions/*@v4` tags in
`ci.yml` (pre-existing practice) to pin by commit at Step 27.
- The browser-side fresh-instance mechanism (static glue URL with a
cache-busting query under Vite, or a Worker per instance) is designed, not
built: R2 builds and tests it.