diff --git a/.claude/tasks/contracts/2026-10-13-rust-r0-verify.md b/.claude/tasks/contracts/2026-10-13-rust-r0-verify.md index 498639fe..c7ecd32c 100644 --- a/.claude/tasks/contracts/2026-10-13-rust-r0-verify.md +++ b/.claude/tasks/contracts/2026-10-13-rust-r0-verify.md @@ -33,7 +33,7 @@ Implement R0 per Annex B: Cargo workspace with crates core, wasm, worker; pinned CHECK: grep -c "tokio" crates/worker/Cargo.toml; grep -n "vars_os().next().is_some()\|sandbox::apply(\|read_to_end(&mut input)" crates/worker/src/decode.rs | head -3; grep -n "ensure_single_thread()?;\|set_rlimits(limits)?;\|install_seccomp()?;" crates/worker/src/sandbox.rs | head -3 EXPECT: 0 ; the three lines appear in that order (env check line < sandbox line < read line) ; the three calls appear in that order 9. seccomp allowlist is the traced set plus the abort path, denies every file and process syscall, and was derived and proven on the musl binary. - CHECK: sed -n '/^pub const ALLOWED_SYSCALLS/,/^];/p' crates/worker/src/sandbox.rs | grep -c '("'; sed -n '/^pub const ABORT_PATH_SYSCALLS/,/^];/p' crates/worker/src/sandbox.rs | grep -c '("'; grep -c "open\|execve\|clone\|socket" <(sed -n '/^pub const ALLOWED_SYSCALLS/,/^];/p' crates/worker/src/sandbox.rs); grep -E "test result: ok. 13 passed|allowlist covers the trace" /tmp/claude-1000/-home-bchanot-Documents-faunosteo/2fbc125b-9811-4458-8ebc-489c2f9255be/scratchpad/worker-test-build-5.log | sed -E 's/^#[0-9]+ [0-9.]+ //' | sort -u + CHECK: sed -n '/^pub const ALLOWED_SYSCALLS/,/^];/p' crates/worker/src/sandbox.rs | grep -c '("'; sed -n '/^pub const ABORT_PATH_SYSCALLS/,/^];/p' crates/worker/src/sandbox.rs | grep -c '("'; grep -c "open\|execve\|clone\|socket" <(sed -n '/^pub const ALLOWED_SYSCALLS/,/^];/p' crates/worker/src/sandbox.rs); grep -E "test result: ok. 16 passed|allowlist covers the trace" /tmp/claude-1000/-home-bchanot-Documents-faunosteo/2fbc125b-9811-4458-8ebc-489c2f9255be/scratchpad/worker-test-build-11.log | sed -E 's/^#[0-9]+ [0-9.]+ //' | sort -u EXPECT: 7 ; 7 ; 0 ; both lines present 10. The keyed parent never decodes: spawn.rs and webp_check.rs use no image decoder; output capped at 512 KiB; the RIFF check allowlists four chunk types and refuses the rest. CHECK: grep -c "image::" crates/worker/src/spawn.rs crates/worker/src/webp_check.rs; grep -c "MAX_OUTPUT_BYTES: usize = 512 \* 1024" crates/worker/src/limits.rs; grep -c 'b"VP8X", b"VP8 ", b"VP8L", b"ALPH"' crates/worker/src/webp_check.rs; grep -c "return Err(WebpIssue::ForbiddenChunk(fourcc))" crates/worker/src/webp_check.rs @@ -42,7 +42,7 @@ Implement R0 per Annex B: Cargo workspace with crates core, wasm, worker; pinned CHECK: grep -l "libwebp_sys::" crates/worker/src/*.rs; grep -c "// SAFETY:" crates/worker/src/decode.rs; grep -c "MIN_LIBWEBP_VERSION: (u8, u8, u8) = (1, 6, 0)" crates/worker/src/limits.rs; grep -c "the_linked_libwebp_is_recent_enough" crates/worker/tests/sandbox.rs EXPECT: crates/worker/src/decode.rs only ; >= 4 ; 1 ; 1 12. Test hooks never ship: release build without features; the runtime image is distroless static, non-root, with `run --check` as its command. - CHECK: grep -n "cargo build -p faunosteo-worker --release --locked" crates/worker/Dockerfile | grep -c "features"; grep -c "FROM gcr.io/distroless/static-debian12:nonroot" crates/worker/Dockerfile; grep -c "^USER nonroot" crates/worker/Dockerfile; grep -c 'CMD \["run", "--check"\]' crates/worker/Dockerfile; tail -1 /tmp/claude-1000/-home-bchanot-Documents-faunosteo/2fbc125b-9811-4458-8ebc-489c2f9255be/scratchpad/worker-image-build-2.log + CHECK: grep -n "cargo build -p faunosteo-worker --release --locked" crates/worker/Dockerfile | grep -c "features"; grep -c "FROM gcr.io/distroless/static-debian12:nonroot" crates/worker/Dockerfile; grep -c "^USER nonroot" crates/worker/Dockerfile; grep -c 'CMD \["run", "--check"\]' crates/worker/Dockerfile; tail -1 /tmp/claude-1000/-home-bchanot-Documents-faunosteo/2fbc125b-9811-4458-8ebc-489c2f9255be/scratchpad/worker-image-build-6.log EXPECT: 0 ; 1 ; 1 ; 1 ; exit=0 13. Frontend, live deployment and database untouched; the existing suites still pass. CHECK: git diff --stat 5fec065..HEAD -- apps/app Dockerfile docker-compose.yml docker/nginx.conf docker/entrypoint.sh supabase packages/domain packages/anatomy packages/pdf packages/supabase | wc -l; tail -1 /tmp/claude-1000/-home-bchanot-Documents-faunosteo/2fbc125b-9811-4458-8ebc-489c2f9255be/scratchpad/pnpm-check.log; grep -E "apps/app test:run:\s+Tests|packages/pdf test:run:\s+Tests|packages/anatomy test:run:\s+Tests" /tmp/claude-1000/-home-bchanot-Documents-faunosteo/2fbc125b-9811-4458-8ebc-489c2f9255be/scratchpad/pnpm-check.log diff --git a/crates/worker/tests/sandbox.rs b/crates/worker/tests/sandbox.rs index 7c7910a5..6fa19fc0 100644 --- a/crates/worker/tests/sandbox.rs +++ b/crates/worker/tests/sandbox.rs @@ -86,10 +86,18 @@ fn oversized_headers_are_refused_before_decoding() { #[test] fn an_iccp_bomb_is_a_content_rejection_not_a_broken_environment() { - expect_rejected( - &fixtures::png_iccp_bomb(300 << 20), - exit_codes::RESOURCE_LIMIT, - ); + // The png crate reports the inflated profile as a decoding error; the property proven + // here is that content can only ever be rejected, never classified as a broken + // environment (the outcome R1 alerts on). + let run = spawner().decode(&fixtures::png_iccp_bomb(300 << 20)); + match run.outcome { + ChildOutcome::Rejected { code, .. } + if code == exit_codes::DECODE_FAILED || code == exit_codes::RESOURCE_LIMIT => {} + other => panic!( + "expected a content rejection, got {other:?} ({})", + run.stderr + ), + } } #[test] diff --git a/docs/development/RUST.md b/docs/development/RUST.md index 10fec644..19c4bb03 100644 --- a/docs/development/RUST.md +++ b/docs/development/RUST.md @@ -100,18 +100,25 @@ sandbox in a single-threaded process: `image::Limits` (sides ≤ 4096, alloc 256 MiB), applies the EXIF orientation, `resize_to_fill` 512 × 512, encodes lossy WebP (q 82) through `libwebp-sys` (C, this process only), writes stdout. Exit codes in - `exit_codes.rs` (10–18, never 1, 101 or a signal number). + `exit_codes.rs` (10–19, never 1, 101 or a signal number); every decode-time + error maps to a content code (`unsupported_type`, `decode_failed`, + `dimensions`, `resource_limit`), so no upload can produce a broken-environment + code. - 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}` 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 + (`Produced`, `Rejected{code}` for the content codes + (`exit_codes::is_content_rejection`, an explicit list), `Broken{code}` when + the child could not run properly (usage, non-empty environment, sandbox + failure, encode or output failure, internal: R1 alerts instead of blaming + the upload; no content can produce it), `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 + only (chunk allowlist `VP8X`, `VP8 `, `VP8L`, `ALPH`; the encoder's structure + enforced: optional `VP8X` first, optional `ALPH` only in an extended file, + exactly one frame; 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 @@ -145,15 +152,18 @@ 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, 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:` and `faunosteo_worker:` and prints their - digests. Deploys nothing (DEPLOY.md "Image deploy by digest"). +- `release-images.yml`: manual only; the dispatch input is a typed choice + re-validated through an environment variable; the RustSec and npm + (`pnpm audit --prod`) advisories gates run first; a named ephemeral + `buildx` builder (`--builder`, no silent fallback) with its own cache + builds the images; the registry token reaches the login step only, into + a per-job `DOCKER_CONFIG` under `RUNNER_TEMP` created before any step and + removed by a literal path; digests read from the build metadata; + `actions/checkout` pinned to a commit. The `if: github.ref` line is not a + boundary (push access and the token's scope are; a dedicated release + runner label is the Step 27 operation). It pushes `faunosteo_app:` + and `faunosteo_worker:` 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 @@ -214,12 +224,15 @@ static binary. allowlist is that set plus the abort path (`rt_sigaction`, `rt_sigprocmask`, `getpid`, `gettid`, `tkill`, `tgkill`, `exit`). - 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`, + Docker's default seccomp profile: 16 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, `--alloc-gib 2` → SIGABRT 6 under `RLIMIT_AS`, `--spin` → parent deadline, - `--spin` → SIGXCPU 24 at the CPU soft limit, libwebp ≥ 1.6.0). + `--spin` → SIGXCPU 24 at the CPU soft limit, libwebp ≥ 1.6.0; negative + proofs of the argument filters: `--signal-parent` (`tkill` to the parent) + and `--mmap-exec` → SIGSYS; an `iCCP` bomb of 300 MB inflated → a content + rejection, never a broken-environment outcome). - Findings: with `RLIMIT_CPU` soft = hard the kernel sends SIGKILL (hard limit checked first), indistinguishable from the parent's deadline kill; the soft limit is now two seconds below the hard one. The 4096² decode