fix(worker): V1-2.3 hostile corpus through verify, verdict and memory caps aligned
This commit is contained in:
1 parent
7043d39ae0
commit
6aa85fe7e4
7 files changed
+67
-10
No files matched your search
@@ -201,8 +201,14 @@ fn chain_reviewed(levels: usize) -> Value {
|
||||
/// The framed input of `document` drawn on `SHEET_DRAWING`, the document also as its base
|
||||
/// (the base path is traced too); empty on a framing error.
|
||||
pub fn sheet_frame(document: &Value) -> Vec<u8> {
|
||||
sheet_frame_on(document, SHEET_DRAWING.as_bytes())
|
||||
}
|
||||
|
||||
/// The same framed input with `drawing` as the main view's drawing, its row matching its
|
||||
/// bytes (size and sha256), so the core reads it.
|
||||
pub fn sheet_frame_on(document: &Value, drawing: &[u8]) -> Vec<u8> {
|
||||
let text = document.to_string();
|
||||
let sha256 = sha256_hex(SHEET_DRAWING.as_bytes());
|
||||
let sha256 = sha256_hex(drawing);
|
||||
let input = VerdictInput {
|
||||
binding: sheet_binding(),
|
||||
document: &text,
|
||||
@@ -210,8 +216,8 @@ pub fn sheet_frame(document: &Value) -> Vec<u8> {
|
||||
drawings: vec![VerdictDrawing {
|
||||
asset_id: SHEET_ASSET,
|
||||
sha256: &sha256,
|
||||
byte_size: SHEET_DRAWING.len() as u64,
|
||||
bytes: Some(SHEET_DRAWING.as_bytes()),
|
||||
byte_size: drawing.len() as u64,
|
||||
bytes: Some(drawing),
|
||||
}],
|
||||
};
|
||||
verify_frame::encode(&input).unwrap_or_default()
|
||||
|
||||
@@ -34,8 +34,10 @@ pub const MIN_LIBWEBP_VERSION: (u8, u8, u8) = (1, 6, 0);
|
||||
pub const VERIFY_MAX_INPUT_BYTES: usize = 12 * 1024 * 1024;
|
||||
/// Largest frame header (ids and drawing rows, a few KiB in practice).
|
||||
pub const VERIFY_MAX_HEADER_BYTES: usize = 64 * 1024;
|
||||
/// Largest verdict the parent reads (= SQL `sheet_verification_max_verdict_bytes`).
|
||||
pub const VERIFY_MAX_OUTPUT_BYTES: usize = 4 * 1024 * 1024;
|
||||
/// Largest verdict the parent reads: below SQL `sheet_verification_max_verdict_bytes` (4 MiB,
|
||||
/// measured on `jsonb::text`, whose separators make the same verdict longer than the compact
|
||||
/// child output), so a verdict the child may write is one SQL measures within its cap.
|
||||
pub const VERIFY_MAX_OUTPUT_BYTES: usize = 3 * 1024 * 1024;
|
||||
/// Hard address-space cap of the `verify` child (`RLIMIT_AS`).
|
||||
pub const VERIFY_ADDRESS_SPACE_BYTES: u64 = 1024 * 1024 * 1024;
|
||||
/// CPU-time cap of the `verify` child (`RLIMIT_CPU`, seconds).
|
||||
|
||||
@@ -252,6 +252,34 @@ fn a_sheet_at_every_cap_is_verified_within_the_limits() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The core's hostile SVG corpus as the drawing of a submitted sheet: each one is judged by
|
||||
/// the core inside the full sandbox (an integrity failure), never a crash or a signal.
|
||||
#[test]
|
||||
fn the_hostile_svg_corpus_fails_verification_inside_the_sandbox() {
|
||||
let dir = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../core/tests/fixtures/svg/hostile"
|
||||
);
|
||||
let mut seen = 0;
|
||||
for entry in std::fs::read_dir(dir).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
let drawing = std::fs::read(&path).unwrap();
|
||||
let verdict = expect_verdict(&fixtures::sheet_frame_on(
|
||||
&fixtures::sheet_document(),
|
||||
&drawing,
|
||||
));
|
||||
let code = verdict["failure_code"].as_str().unwrap_or_default();
|
||||
assert_eq!(verdict["outcome"], "failed", "{}", path.display());
|
||||
assert!(
|
||||
code.starts_with("verification.integrity.svg_"),
|
||||
"{}: {code}",
|
||||
path.display()
|
||||
);
|
||||
seen += 1;
|
||||
}
|
||||
assert!(seen >= 40, "hostile corpus read: {seen} files");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_verify_child_refuses_a_non_empty_environment() {
|
||||
let status = Command::new(env!("CARGO_BIN_EXE_faunosteo-worker"))
|
||||
|
||||
+3
-2
@@ -42,7 +42,8 @@ services:
|
||||
|
||||
# Sheet verification worker (V1-2.3, V1-2 contract §6.4): the same image and hardening as
|
||||
# `worker`, the verification loop only (no avatar, no sweep). Its `verify` child is capped
|
||||
# at 1 GiB of address space (crates/worker/src/limits.rs). Started only with the `worker`
|
||||
# at 1 GiB of address space (crates/worker/src/limits.rs): the container keeps room for it
|
||||
# and the parent, so the child's own limit binds first. Started only with the `worker`
|
||||
# profile: `docker compose --profile worker up -d worker-verify`; never on DEV.
|
||||
worker-verify:
|
||||
container_name: faunosteo_worker_verify
|
||||
@@ -55,7 +56,7 @@ services:
|
||||
cap_drop: [ALL]
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
mem_limit: 512m
|
||||
mem_limit: 1280m
|
||||
cpus: 1
|
||||
pids_limit: 64
|
||||
networks:
|
||||
|
||||
@@ -4465,7 +4465,7 @@ Contract `.claude/tasks/contracts/2026-11-01-v1-2-3-worker-verification.md`, pla
|
||||
|---|---|---|
|
||||
| M6 | `claim_sheet_verifications`, `get_sheet_verification_input`, `complete_sheet_verification`, `fail_sheet_verification`, service role only (claims checked too); the verdict checked for its binding (stale) and its structure (malformed), nothing written otherwise | `supabase/migrations/20261101100000_sheet_verification_jobs.sql`, pgTAP `021` (51) |
|
||||
| Link | the worker links `faunosteo-core` (default features: no PDF, no curation); `version` prints the core version | `crates/worker/Cargo.toml` |
|
||||
| Child | `verify`: framed stdin (`[u32 LE header length][header JSON][document][base][drawings]`), `compute_verdict`, verdict JSON out; same sandbox as `decode`, its own limits (12 MiB in, 4 MiB out, 1 GiB, 60 s CPU, 90 s); a frame the child cannot read is a broken parent (`frame_invalid`), never content | `verify_frame.rs`, `verify.rs`, `limits.rs` |
|
||||
| Child | `verify`: framed stdin (`[u32 LE header length][header JSON][document][base][drawings]`), `compute_verdict`, verdict JSON out; same sandbox as `decode`, its own limits (12 MiB in, 3 MiB out under the 4 MiB SQL cap, 1 GiB, 60 s CPU, 90 s; container `mem_limit` 1 280 MiB so the child limit binds first); a frame the child cannot read is a broken parent (`frame_invalid`), never content | `verify_frame.rs`, `verify.rs`, `limits.rs` |
|
||||
| Spawner | per command: `Spawner::for_decode` (unchanged values), `Spawner::for_verify`; a verify output counts only when it parses as a JSON object | `spawn.rs` |
|
||||
| Mode | `run --jobs sheet-verify`: no sweep; drawings fetched under the archive caps, anything else passed without bytes for the core to name; §6.5 rows mapped to closed worker codes; watchdog stage `VERIFY` 95 s | `run.rs`, `verify_job.rs`, `backend.rs`, `http.rs` |
|
||||
| Compose | service `worker-verify`, profile `worker`, same hardening as `worker` | `docker-compose.yml` |
|
||||
@@ -4491,6 +4491,26 @@ Proofs (2026-11-01):
|
||||
- Upgrade rehearsals on the sandbox: from the state before M6, and from the state before M4 (the DEV state, M4 to
|
||||
M6 in one `migration up`): pgTAP 1 859 PASS, `verify-e2e` 7/7, `types --check` equal.
|
||||
- Not measured: the largest input the policy allows (a 2 MiB document, its 2 MiB base and four drawings, 6 MiB).
|
||||
- Hostile corpus: the 42 SVG files of `crates/core/tests/fixtures/svg/hostile` as the drawing of a submitted sheet,
|
||||
each through the real `verify` child under the full filter (`the_hostile_svg_corpus_fails_verification_inside_the_sandbox`,
|
||||
added after the verifier's review): every one a `failed` verdict with a `verification.integrity.svg_*` code, no
|
||||
signal, no crash. `pnpm worker:test` then 24 sandbox tests.
|
||||
|
||||
Reviews (fresh, 2026-11-01, on `7043d39`):
|
||||
- Security: PASS, semgrep 0 on the pinned rulesets. MEDIUM pre-existing hygiene (the throwaway sandbox account's
|
||||
password literal in `scripts/db-sandbox.sh`). LOWs fixed: the verdict cap measured twice (child output now
|
||||
3 MiB, under the 4 MiB SQL measure of `jsonb::text`); the child's 1 GiB address space above the container's
|
||||
512 MiB (`worker-verify` and the sandbox worker now 1 280 MiB, so the child's limit binds first). LOWs open: no
|
||||
backoff between attempts (the §6.4 design « without backoff »: an outage of a few seconds can spend the five
|
||||
attempts, the round closing `unavailable`; fail-closed, availability only); a document naming several hundred
|
||||
registered drawings overflows the 64 KiB frame header and is reported `resource_limit` instead of the core's
|
||||
`caps` (wrong exit message, no security effect); SQL interpolation of generated ids in the sandbox test only.
|
||||
- Verifier: ECARTS(2). W1-W5, W7 met. W6: the hostile corpus through the child was missing (added, above); `pnpm
|
||||
e2e:avatar` « unchanged » not run: the script starts a worker against the DEV stack, which §16.11 forbids without
|
||||
the owner, so it stays the owner's decision (the avatar loop is unchanged: `job_loop` 11 tests, and the
|
||||
verification mode leaves avatar and purge rows untouched, e2e case f). W8: gates recorded below.
|
||||
|
||||
Gates on the final HEAD: see the closing line of this section.
|
||||
|
||||
Choices for the owner: worker codes, attempt limit five, lease 10 minutes, verdict cap 4 MiB, service name
|
||||
`worker-verify`, the shared `brk`, and that an object larger than the policy is passed without bytes (named
|
||||
|
||||
@@ -253,7 +253,7 @@ unchanged.
|
||||
- Child `faunosteo-worker verify`: same sandbox as `decode` (empty
|
||||
environment, one thread, no core dump, the seccomp allowlist) with its own
|
||||
limits: framed stdin input up to 12 MiB, `RLIMIT_AS` 1 GiB, `RLIMIT_CPU`
|
||||
60 s, 90 s deadline, verdict output up to 4 MiB (the SQL cap). It runs the
|
||||
60 s, 90 s deadline, verdict output up to 3 MiB (under the SQL cap of 4 MiB on `jsonb::text`). It runs the
|
||||
core's `compute_verdict` and writes the verdict JSON; a failed verdict is
|
||||
still a normal exit. The seccomp derivation of 2026-11-01 traced `brk` in
|
||||
the verify child at the caps (musl mallocng growing its heap): added to the
|
||||
|
||||
@@ -284,7 +284,7 @@ cmd_verify_e2e() {
|
||||
"$GATEWAY" "$SB_SERVICE_KEY" > "$verify_env"
|
||||
docker run -d --name "$WORKER" --network "$NET" --env-file "$verify_env" \
|
||||
--read-only --cap-drop ALL --security-opt no-new-privileges:true \
|
||||
--memory 512m --cpus 1 --pids-limit 64 --user nonroot \
|
||||
--memory 1280m --cpus 1 --pids-limit 64 --user nonroot \
|
||||
"$WORKER_IMAGE" run --jobs sheet-verify >/dev/null
|
||||
rm -f "$verify_env"; verify_env=
|
||||
for _ in $(seq 1 30); do
|
||||
|
||||
Reference in new issue
Block a user