feat(worker): sandboxed decode child skeleton — rlimits, traced seccomp allowlist, pure-Rust decoders, libwebp in the child, parent RIFF check, musl image with test stage

This commit is contained in:
bchanot committed 2026-10-13 00:01:26 +02:00
1 parent 2a38fa37b5
commit 3970cdca52
13 files changed
+1435

No files matched your search

+113
View File
@@ -0,0 +1,113 @@
//! `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`.
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();
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") => run(&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")
}
/// `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
.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
}