diff --git a/README.md b/README.md index 5254ee2..d8afc66 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ The VM is the boundary. The guest (including a prompt-injected agent or a malici Auth realms must be https. For public registries, connections to loopback/private/link-local addresses are refused (token realms and redirects included, IPv6 forms like NAT64/6to4 too). A registry counts as local only by name: `localhost` or a private IP literal (`192.168.1.5:5000`). LAN registries addressed by a DNS name are refused; use the IP. + All downloads (registries, kernel) time out after 30 s without progress (connect or any single read). - **pi config**: allowlisted items only. Symlinks are followed only into `~/.pi/agent` or `~/.agents/skills`, with no cycles and no special files, capped at 256 MB. - **exec**: sessions run as root before dropping to the user, so the guest helper accepts them only from the host's vsock CID, diff --git a/src/kernel.rs b/src/kernel.rs index 2e20355..de6958f 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -34,7 +34,8 @@ pub fn kernel(h: &Path, update: bool, version: Option) -> Result format!("https://api.github.com/repos/{KATA_REPO}/releases/tags/{v}"), None => format!("https://api.github.com/repos/{KATA_REPO}/releases/latest"), }; - let rel: Value = serde_json::from_reader(ureq::get(&api).call().with_context(|| format!("GET {api}"))?.into_reader())?; + let agent = oci::agent().build(); + let rel: Value = serde_json::from_reader(agent.get(&api).call().with_context(|| format!("GET {api}"))?.into_reader())?; let tag = rel["tag_name"].as_str().ok_or_else(|| anyhow!("no tag in {api}"))?; if k.exists() && installed.as_deref() == Some(tag) { eprintln!("wsbx: kernel already at Kata {tag}"); @@ -62,7 +63,7 @@ pub fn kernel(h: &Path, update: bool, version: Option) -> Result bool { } } +/// Every HTTP agent: a silent server (connect or any single read, TLS handshake included) fails after 30 s instead of hanging. +pub fn agent() -> ureq::AgentBuilder { + let t = std::time::Duration::from_secs(30); + ureq::AgentBuilder::new().timeout_connect(t).timeout_read(t) +} + /// Registry the user named as local: `localhost` or a non-public IP literal. Decided by name only -- /// a DNS name pointing at loopback (e.g. *.127.0.0.1.nip.io) is controlled by whoever owns the zone. fn explicit_local(registry: &str) -> bool { @@ -85,9 +91,9 @@ fn explicit_local(registry: &str) -> bool { /// (e.g. localhost:5000, 192.168.1.5:5000) was chosen by the user and keeps the default agent. fn agent_for(registry: &str) -> ureq::Agent { if explicit_local(registry) { - return ureq::agent(); + return agent().build(); } - ureq::AgentBuilder::new() + agent() .resolver(|addr: &str| -> std::io::Result> { let ok: Vec = addr.to_socket_addrs()?.filter(|a| is_public(a.ip())).collect(); if ok.is_empty() {