From 2eb4500f089154b982f7c5dbbc7f1efbfd702ed5 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 11:49:50 +0000 Subject: =?UTF-8?q?sandbox:=20kata=20backend=20=E2=80=94=20ad-hoc=20TTL=20?= =?UTF-8?q?sandboxes=20over=20the=20agent=20protocol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The kata lease path is composition, not a new protocol: acquire mints a rendezvous nonce, asks a Provisioner for a sandbox pointed at this hub, and leases only the dial-in whose hello carries that nonce back. A box that never dials in is a TTL expiry — the same vocabulary every other failure here speaks (I5) — and a stray box that greets with a nonce nobody ordered is dropped unread, never leased. Two payload shapes are constructed as pure, unit-tested functions because both are real targets: an agent-sandbox-style Kubernetes CR (runtimeClass kata, activeDeadlineSeconds so the orchestrator enforces the TTL even if the hub dies) and a nerdctl/containerd argv for hosts without a cluster. The K8s provisioner is real ureq code exercised only by the gated live tier, which skips with a printed note wherever /dev/kvm or AUR_KATA_API is absent — the recorded-skip convention, not a silent pass. The rendezvous and TTL logic runs for real on any machine via LocalAgentProvisioner: a real sandbox-agent process, real frames, real nonce matching, no VM. That is the same honesty as the loopback backend — the interface is under test, not a mock of it. --- src/sandbox/remote.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/sandbox/remote.rs') diff --git a/src/sandbox/remote.rs b/src/sandbox/remote.rs index c1ad998..e68ea0f 100644 --- a/src/sandbox/remote.rs +++ b/src/sandbox/remote.rs @@ -98,14 +98,9 @@ impl SandboxBackend for RemoteBackend { }; wire::write_frame(&mut stream.try_clone()?, &Frame::HelloAck { ttl_secs: spec.ttl.as_secs().max(1) })?; let _ = stream.set_read_timeout(None); - Ok(Arc::new(RemoteSandbox { - cfg: self.cfg.clone(), - id: agent_id, - ttl: spec.ttl, - reader: Mutex::new(reader), - writer: Mutex::new(stream), - req: AtomicU64::new(1), - })) + Ok(Arc::new(RemoteSandbox::after_hello( + &self.cfg, stream, agent_id, spec.ttl, + ))) } fn status(&self) -> Result> { @@ -127,6 +122,23 @@ pub struct RemoteSandbox { } impl RemoteSandbox { + /// Wrap a stream whose `Hello` has been verified and answered. Split out + /// so the kata backend can lease a rendezvoused connection with its own + /// accept loop without duplicating the sandbox half. + pub(crate) fn after_hello(cfg: &Config, stream: std::net::TcpStream, agent_id: String, ttl: std::time::Duration) -> Self { + let reader = BufReader::new( + stream.try_clone().expect("cloning a connected tcp stream cannot fail"), + ); + Self { + cfg: cfg.clone(), + id: agent_id, + ttl, + reader: Mutex::new(reader), + writer: Mutex::new(stream), + req: AtomicU64::new(1), + } + } + fn send(&self, frame: &Frame) -> Result<()> { wire::write_frame(&mut *self.writer.lock().unwrap(), frame).map_err(Into::into) } -- cgit v1.2.3