diff options
Diffstat (limited to 'src/sandbox/agent.rs')
| -rw-r--r-- | src/sandbox/agent.rs | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/src/sandbox/agent.rs b/src/sandbox/agent.rs index d7b841c..e9626f6 100644 --- a/src/sandbox/agent.rs +++ b/src/sandbox/agent.rs @@ -11,16 +11,12 @@ use crossbeam_channel::unbounded; use crate::error::{Error, Result}; use crate::sandbox::wire::{self, Frame}; -/// CLI-shaped arguments for the `sandbox-agent` binary. #[derive(Debug, Clone)] pub struct AgentOptions { pub hub: String, pub token: String, pub profile: String, pub ttl: Duration, - /// The identity the hub knows this sandbox by. A provisioner (Kata CR, - /// containerd run, a test) passes the nonce it registered with the hub; - /// the hello frame carries it back so the rendezvous can be matched. pub agent_id: Option<String>, } @@ -50,8 +46,6 @@ pub fn serve(opts: &AgentOptions) -> Result<()> { let blobs = blob_dir(&agent_id); std::fs::create_dir_all(&blobs)?; - // Shared watchdog state: the reader thread stamps every inbound frame; - // the watchdog exits (killing the child) when the hub goes silent. let last_inbound = Arc::new(Mutex::new(Instant::now())); let child = Arc::new(Mutex::new(None::<u32>)); let alive = Arc::new(AtomicBool::new(true)); @@ -80,7 +74,7 @@ pub fn serve(opts: &AgentOptions) -> Result<()> { loop { let frame = match wire::read_frame(&mut reader) { Ok(Some(f)) => f, - Ok(None) => break, // hub hung up: the lease is over + Ok(None) => break, Err(e) => { outcome = Err(e.into()); break; @@ -99,7 +93,6 @@ pub fn serve(opts: &AgentOptions) -> Result<()> { } } alive.store(false, Ordering::Relaxed); - // Whatever we were running dies with us, always. if let Some(pid) = *child.lock().unwrap() { unsafe { libc::kill(pid as i32, libc::SIGKILL); @@ -109,7 +102,6 @@ pub fn serve(opts: &AgentOptions) -> Result<()> { outcome } -/// Returns true when the agent should stop (Destroy / fatal child loss). fn handle( frame: Frame, writer: &Arc<Mutex<TcpStream>>, @@ -121,8 +113,6 @@ fn handle( Frame::Ping {} => Ok(false), Frame::Put { req, digest, data } => { let bytes = wire::unhex(&data).map_err(io_err)?; - // The agent verifies content-addressing on its side too: a blob - // that does not hash to its name is refused, not staged. if crate::hash::hex(&bytes) != digest { reply(writer, req, Err("put: data does not hash to the claimed digest"))?; return Ok(false); @@ -159,7 +149,6 @@ fn run_child( child: &Arc<Mutex<Option<u32>>>, ) -> Result<()> { let mut argv = argv; - // Expand `blob:<digest>` argv elements, like the loopback backend does. for a in argv.iter_mut() { if let Some(digest) = a.strip_prefix("blob:") { *a = safe_blob_path(blobs, digest)?.display().to_string(); @@ -179,9 +168,6 @@ fn run_child( let mut proc = c.spawn()?; *child.lock().unwrap() = Some(proc.id()); - // Stream both pipes as they fill: readers hand chunks to the frame writer - // over a channel, so a chatty build never blocks on the socket and vice - // versa. let (tx, rx) = unbounded::<(&'static str, Vec<u8>)>(); let mut pipes = Vec::new(); let pipes_spec: [(&'static str, Option<Box<dyn std::io::Read + Send>>); 2] = [ @@ -246,14 +232,10 @@ fn connect_with_retry(hub: &str, for_long: Duration) -> std::result::Result<TcpS } } -/// Blob scratch, removed when the lease ends. fn blob_dir(agent_id: &str) -> PathBuf { std::env::temp_dir().join(format!("aur-{agent_id}-blobs")) } -/// Digests are the only blob names, and they must stay path-safe — the same -/// rule the loopback backend enforces, so a hostile frame cannot escape the -/// blob directory. fn safe_blob_path(blobs: &Path, digest: &str) -> Result<PathBuf> { if digest.is_empty() || digest.len() > 128 |
