fix(#6): connect/read timeouts on every HTTP agent

No ureq call had a timeout, so a silent registry hung pull forever. One
oci::agent() builder (30 s connect + per-read) now backs registry agents,
local ones included, and the kernel downloads.
This commit is contained in:
2026-10-22 19:54:09 +02:00
parent 2231e4efe1
commit 56762648e3
3 changed files with 12 additions and 4 deletions
+1
View File
@@ -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 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: (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. `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 - **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. 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, - **exec**: sessions run as root before dropping to the user, so the guest helper accepts them only from the host's vsock CID,
+3 -2
View File
@@ -34,7 +34,8 @@ pub fn kernel(h: &Path, update: bool, version: Option<String>) -> Result<PathBuf
Some(v) => format!("https://api.github.com/repos/{KATA_REPO}/releases/tags/{v}"), Some(v) => format!("https://api.github.com/repos/{KATA_REPO}/releases/tags/{v}"),
None => format!("https://api.github.com/repos/{KATA_REPO}/releases/latest"), 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}"))?; let tag = rel["tag_name"].as_str().ok_or_else(|| anyhow!("no tag in {api}"))?;
if k.exists() && installed.as_deref() == Some(tag) { if k.exists() && installed.as_deref() == Some(tag) {
eprintln!("wsbx: kernel already at Kata {tag}"); eprintln!("wsbx: kernel already at Kata {tag}");
@@ -62,7 +63,7 @@ pub fn kernel(h: &Path, update: bool, version: Option<String>) -> Result<PathBuf
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.spawn()?; .spawn()?;
let mut w = oci::HashWriter(tar.stdin.take().unwrap(), Sha256::new()); let mut w = oci::HashWriter(tar.stdin.take().unwrap(), Sha256::new());
std::io::copy(&mut ureq::get(url).call()?.into_reader(), &mut w)?; std::io::copy(&mut agent.get(url).call()?.into_reader(), &mut w)?;
let oci::HashWriter(stdin, hasher) = w; let oci::HashWriter(stdin, hasher) = w;
drop(stdin); drop(stdin);
if !tar.wait()?.success() { if !tar.wait()?.success() {
+8 -2
View File
@@ -73,6 +73,12 @@ pub fn is_public(ip: IpAddr) -> 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 -- /// 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. /// 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 { 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. /// (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 { fn agent_for(registry: &str) -> ureq::Agent {
if explicit_local(registry) { if explicit_local(registry) {
return ureq::agent(); return agent().build();
} }
ureq::AgentBuilder::new() agent()
.resolver(|addr: &str| -> std::io::Result<Vec<SocketAddr>> { .resolver(|addr: &str| -> std::io::Result<Vec<SocketAddr>> {
let ok: Vec<SocketAddr> = addr.to_socket_addrs()?.filter(|a| is_public(a.ip())).collect(); let ok: Vec<SocketAddr> = addr.to_socket_addrs()?.filter(|a| is_public(a.ip())).collect();
if ok.is_empty() { if ok.is_empty() {