|
1 | 1 | use anyhow::{anyhow, Result}; |
2 | 2 | use bytes::Bytes; |
3 | 3 | use cap_primitives::net::Pool; |
4 | | -use cap_std::ipnet::IpNet; |
| 4 | +use cap_std::ipnet::{IpNet, Ipv4Net, Ipv6Net}; |
5 | 5 | use std::{ |
6 | 6 | io::{Read, Write}, |
7 | 7 | mem, |
| 8 | + net::{Ipv4Addr, Ipv6Addr}, |
8 | 9 | path::{Path, PathBuf}, |
9 | 10 | sync::{Arc, Mutex}, |
10 | 11 | time::{Duration, Instant}, |
@@ -201,17 +202,27 @@ impl StoreBuilder { |
201 | 202 | ); |
202 | 203 | } |
203 | 204 |
|
204 | | - /// Inherit the host network with a few hardcoded caveats |
205 | | - pub fn inherit_limited_network(&mut self) { |
| 205 | + /// Allow unrestricted outbound access to the host network. |
| 206 | + pub fn inherit_network(&mut self) { |
206 | 207 | self.with_wasi(|wasi| match wasi { |
207 | 208 | WasiCtxBuilder::Preview1(_) => { |
208 | 209 | panic!("Enabling network only allowed in preview2") |
209 | 210 | } |
210 | | - WasiCtxBuilder::Preview2(ctx) => { |
| 211 | + WasiCtxBuilder::Preview2(_) => { |
211 | 212 | // TODO: ctx.allow_udp(false); |
212 | | - ctx.inherit_network(); |
213 | 213 | } |
214 | 214 | }); |
| 215 | + |
| 216 | + // Allow access to 0.0.0.0/0, i.e. all IPv4 addresses |
| 217 | + self.net_pool.insert_ip_net_port_any( |
| 218 | + IpNet::V4(Ipv4Net::new(Ipv4Addr::new(0, 0, 0, 0), 0).unwrap()), |
| 219 | + cap_primitives::ambient_authority(), |
| 220 | + ); |
| 221 | + // Allow access to 0:/0, i.e. all IPv6 addresses |
| 222 | + self.net_pool.insert_ip_net_port_any( |
| 223 | + IpNet::V6(Ipv6Net::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0), 0).unwrap()), |
| 224 | + cap_primitives::ambient_authority(), |
| 225 | + ); |
215 | 226 | } |
216 | 227 |
|
217 | 228 | /// Sets the WASI `stdin` descriptor to the given [`Read`]er. |
|
0 commit comments