From 8dcdce879b51b19603d8163d8a9bfb5f61ff1558 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 15:45:38 +0000 Subject: sandbox: agent-sandbox is a backend now, and nerdctl is gone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `sandbox_backend` was a string and `backend_for` matched it with `_ => loopback`, so the documented Kata backend was unreachable from configuration: a hub told to use agent-sandbox would have quietly built untrusted PKGBUILDs as its own user. The kind now parses, validates, and produces a real `KataBackend` over `K8sSandboxProvisioner`, with the CR's `runtimeClass`, `activeDeadlineSeconds`, nonce, image and cluster coordinates all traced back to the config that produced them. Kata shares a *backend* per configuration rather than only a listener: it routes each dial-in by the nonce in its `Hello` into a map that belongs to it, so two backends on one address would each see half the dial-ins and neither could complete a rendezvous. The cache key is a digest of the distinguishing fields so the token and bearer are not copied into a second place. The containerd/`nerdctl` payload builder is deleted rather than left unused. It was a second deployment shape with no provisioner, no config path and no live tier — a builder that advertises a route the configuration refuses is worse than no builder, because someone will eventually assume the route exists. DESIGN.md now names one provisioning shape, which is the one that exists. --- src/sandbox/remote.rs | 64 +++++---------------------------------------------- 1 file changed, 6 insertions(+), 58 deletions(-) (limited to 'src/sandbox/remote.rs') diff --git a/src/sandbox/remote.rs b/src/sandbox/remote.rs index 96b1ee6..d02335c 100644 --- a/src/sandbox/remote.rs +++ b/src/sandbox/remote.rs @@ -19,11 +19,9 @@ //! manifest/tar sync from the design sketch; that is deliberately not here //! yet, and nothing should pretend otherwise. -use std::collections::HashMap; use std::io::BufReader; -use std::net::TcpListener; use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::{Arc, Mutex, OnceLock}; +use std::sync::{Arc, Mutex}; use crossbeam_channel::Receiver; @@ -41,64 +39,14 @@ pub struct RemoteBackend { queue: Receiver, } -/// A listener shared by every backend built from the same `(addr, token)`. -struct Bound { - local: String, - rx: Receiver, -} - -/// One bound listener per `(address, token)` per process. -/// -/// The listener is a property of the *process*, not of a build. Binding it per -/// build — which is what happened while `Ctx::new` constructed a backend for -/// every build — meant a second concurrent build hit `EADDRINUSE` on a fixed -/// `listen` and failed for a reason that had nothing to do with its package. -/// Sharing the queue is also exactly the semantics `remote` already has: an -/// agent dials in when the operator boots one, and whichever build is waiting -/// takes it. -/// -/// The token is part of the key on purpose. Two different tokens cannot share a -/// listener, and reusing the first one's listener for a second, different token -/// would be a fail-open surprise; forcing a real bind makes the mistake loud. -fn registry() -> &'static Mutex> { - static REGISTRY: OnceLock>> = OnceLock::new(); - REGISTRY.get_or_init(|| Mutex::new(HashMap::new())) -} - -fn bound_listener(addr: &str, token: &str) -> Result { - let key = (addr.to_string(), token.to_string()); - // A poisoned registry means a panic in some other thread's bind; the map - // itself is still sound, so recover rather than wedge every later build — - // the same posture as the publish lock. - let mut reg = registry().lock().unwrap_or_else(|p| p.into_inner()); - if let Some(b) = reg.get(&key) { - return Ok(Bound { local: b.local.clone(), rx: b.rx.clone() }); - } - let listener = TcpListener::bind(addr)?; - let local = listener.local_addr()?.to_string(); - let (tx, rx) = crossbeam_channel::unbounded(); - std::thread::spawn(move || { - for stream in listener.incoming() { - match stream { - Ok(s) => { - let _ = tx.send(s); - } - Err(_) => break, - } - } - }); - let bound = Bound { local, rx }; - reg.insert(key, Bound { local: bound.local.clone(), rx: bound.rx.clone() }); - Ok(bound) -} - impl RemoteBackend { /// Bind the agent listener — or share the one this process already bound for - /// the same `(addr, token)`. `addr` may name port 0; [`Self::local_addr`] - /// reports what actually got bound, which is how a test (or a supervisor) - /// hands the address to the agent without a port negotiation dance. + /// the same `(addr, token)`; see [`crate::sandbox::bound_listener`]. `addr` + /// may name port 0; [`Self::local_addr`] reports what actually got bound, + /// which is how a test (or a supervisor) hands the address to the agent + /// without a port negotiation dance. pub fn bind(cfg: &Config, addr: &str, token: &str) -> Result { - let bound = bound_listener(addr, token)?; + let bound = super::bound_listener(addr, token)?; Ok(Self { cfg: cfg.clone(), token: token.to_string(), addr: bound.local, queue: bound.rx }) } -- cgit v1.2.3