feat(worker): R1 job loop — claim, download, sandboxed decode, clean upload, commit, purge sweeps

Keyed parent on ureq 3 (rustls + ring, bundled roots), no async runtime:
config from the environment (secret never printed, JWT expiry logged), JSON
line logs with a field allowlist (child stderr escaped and truncated), strict
key validation before any URL, Backend trait over PostgREST RPCs and Storage
objects with closed error kinds, one job per claim with the STORAGE.md §3.4
mapping (content codes, processing_error on signals / timeout / overflow,
Broken stops the loop with exit 20, a refused commit deletes nothing), sweeper
(expire pending, purge queue, quarantine leftovers), per-stage watchdog
(exit 21), WORKER_ONCE for tests, run --check extended. 11 loop tests on a
fake backend and decoder; sandbox tests and seccomp derivation unchanged
(the child still makes the same 7 syscalls); image 11.6 MB.
This commit is contained in:
bchanot committed 2026-10-13 19:32:38 +02:00
1 parent 926dd7df8c
commit 0410af0c35
18 files changed
+2921 -42

No files matched your search

+4 -38
View File
@@ -1,14 +1,14 @@
//! `faunosteo-worker` entry: a plain `main`, no async runtime, no thread, so the `decode`
//! child installs its sandbox in a single-threaded process (review Part IV.1).
//!
//! R0 subcommands: `decode` (the sandboxed child), `run --check` (prints the resolved
//! configuration, no job loop before R1), `version`.
//! Subcommands: `decode` (the sandboxed child, R0), `run` (the keyed job loop, R1),
//! `run --check` (prints the resolved configuration without secrets), `version`.
#[cfg(feature = "test-hooks")]
use std::io::Write;
use faunosteo_worker::decode;
use faunosteo_worker::exit_codes;
use faunosteo_worker::limits::MIN_LIBWEBP_VERSION;
fn main() {
let args: Vec<String> = std::env::args().collect();
@@ -24,7 +24,7 @@ fn main() {
&mut stderr.lock(),
)
}
Some("run") => run(&args[2..]),
Some("run") => faunosteo_worker::run::main(&args[2..]),
Some("version") => version(),
#[cfg(feature = "test-hooks")]
Some("fixture") => fixture(&args[2..]),
@@ -59,40 +59,6 @@ fn faunosteo_core_version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
/// `run --check`: prints what the worker would start with, without secrets. The job loop
/// arrives at R1; a plain `run` therefore refuses to pretend it works.
fn run(args: &[String]) -> i32 {
let (major, minor, revision) = decode::libwebp_version();
let libwebp_ok = (major, minor, revision) >= MIN_LIBWEBP_VERSION;
println!("faunosteo-worker run: R0 skeleton, the job loop arrives at R1");
println!(
"libwebp {major}.{minor}.{revision} ({})",
if libwebp_ok {
"accepted"
} else {
"below the minimum, refusing to start"
}
);
for name in ["SUPABASE_URL", "SUPABASE_SERVICE_ROLE_KEY", "WORKER_ID"] {
let state = if std::env::var_os(name).is_some() {
"set"
} else {
"unset"
};
println!("{name}: {state}");
}
let _ = std::io::stdout().flush();
if !libwebp_ok {
return exit_codes::INTERNAL;
}
if args.iter().any(|arg| arg == "--check") {
exit_codes::OK
} else {
eprintln!("run: nothing to do before R1 (use --check to print the configuration)");
exit_codes::USAGE
}
}
#[cfg(feature = "test-hooks")]
fn fixture(args: &[String]) -> i32 {
let Some(bytes) = args