summaryrefslogtreecommitdiffstats
path: root/src/sandbox/remote.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 11:49:50 +0000
committeraur-build <aur-build@localhost>2026-11-19 11:49:50 +0000
commit2eb4500f089154b982f7c5dbbc7f1efbfd702ed5 (patch)
tree6af449ea55d1dba0d3b8d685cf591ebec8d77eac /src/sandbox/remote.rs
parent3374ffd34921e1de414e8b07f69753113f5ba5f9 (diff)
downloadaur-build-2eb4500f089154b982f7c5dbbc7f1efbfd702ed5.tar.gz
aur-build-2eb4500f089154b982f7c5dbbc7f1efbfd702ed5.zip
sandbox: kata backend — ad-hoc TTL sandboxes over the agent protocol
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.
Diffstat (limited to 'src/sandbox/remote.rs')
-rw-r--r--src/sandbox/remote.rs28
1 files changed, 20 insertions, 8 deletions
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<Vec<SandboxInfo>> {
@@ -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)
}