Files
faunosteo/crates/worker/src/main.rs
T
bchanot 0410af0c35 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.
2026-10-13 19:32:38 +02:00

80 lines
2.5 KiB
Rust

//! `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).
//!
//! 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;
fn main() {
let args: Vec<String> = std::env::args().collect();
let code = match args.get(1).map(String::as_str) {
Some("decode") => {
let stdin = std::io::stdin();
let stdout = std::io::stdout();
let stderr = std::io::stderr();
decode::main(
&args[2..],
&mut stdin.lock(),
&mut stdout.lock(),
&mut stderr.lock(),
)
}
Some("run") => faunosteo_worker::run::main(&args[2..]),
Some("version") => version(),
#[cfg(feature = "test-hooks")]
Some("fixture") => fixture(&args[2..]),
#[cfg(feature = "test-hooks")]
Some("print-allowlist") => {
for name in faunosteo_worker::sandbox::allowed_names() {
println!("{name}");
}
exit_codes::OK
}
_ => {
eprintln!("usage: faunosteo-worker <decode | run --check | version>");
exit_codes::USAGE
}
};
std::process::exit(code);
}
fn version() -> i32 {
let (major, minor, revision) = decode::libwebp_version();
println!(
"faunosteo-worker {} (core {}, libwebp {major}.{minor}.{revision})",
env!("CARGO_PKG_VERSION"),
faunosteo_core_version()
);
exit_codes::OK
}
fn faunosteo_core_version() -> &'static str {
// The worker links no core module before R1 (nothing to share yet); the version printed
// is the workspace version the two crates share.
env!("CARGO_PKG_VERSION")
}
#[cfg(feature = "test-hooks")]
fn fixture(args: &[String]) -> i32 {
let Some(bytes) = args
.first()
.and_then(|name| faunosteo_worker::fixtures::by_name(name))
else {
eprintln!(
"usage: faunosteo-worker fixture <png|jpeg|webp|big-jpeg|big-png|tiny|huge-header|gif|truncated>"
);
return exit_codes::USAGE;
};
let stdout = std::io::stdout();
let mut lock = stdout.lock();
if lock.write_all(&bytes).and_then(|()| lock.flush()).is_err() {
return exit_codes::OUTPUT_FAILED;
}
exit_codes::OK
}