pub struct NetworkPolicy { /* private fields */ }Expand description
Outbound-address policy. The default (enforce == false) permits every
address — the interpreter library and submilli run stay unrestricted. The
submilli-server binary opts into NetworkPolicy::deny_private.
Implementations§
Source§impl NetworkPolicy
impl NetworkPolicy
Sourcepub fn with_denial_observer(
self,
observer: Arc<dyn Fn(&str) + Send + Sync>,
) -> Self
pub fn with_denial_observer( self, observer: Arc<dyn Fn(&str) + Send + Sync>, ) -> Self
Observe refused destinations without changing the network policy.
Sourcepub fn client_builder(self: &Arc<Self>) -> ClientBuilder
pub fn client_builder(self: &Arc<Self>) -> ClientBuilder
A reqwest client builder whose DNS resolution is filtered by this policy:
a name resolving only to forbidden addresses fails to resolve. Every
outbound client the runtime builds — submilli:http, model providers,
MCP servers — starts from this, so one policy governs them all. Literal
IP hosts never reach a resolver; refuse those with
Self::check_literal_host before sending.
Sourcepub fn check_literal_host(&self, url: &str) -> Result<(), String>
pub fn check_literal_host(&self, url: &str) -> Result<(), String>
Refuse a URL whose host is a literal IP the policy forbids. Host names pass here and are judged at resolution.
Sourcepub fn deny_private() -> Self
pub fn deny_private() -> Self
Block private, loopback, link-local and other special-purpose IP space. The secure base the server layers opt-outs onto.
Sourcepub fn allow_localhost(self, yes: bool) -> Self
pub fn allow_localhost(self, yes: bool) -> Self
Allow IPv4 + IPv6 loopback (127.0.0.0/8, ::1).
Sourcepub fn allow_private(self, yes: bool) -> Self
pub fn allow_private(self, yes: bool) -> Self
Allow all RFC1918 / CGNAT / IPv6-ULA private ranges.
Sourcepub fn allow_cidr(self, net: IpNet) -> Self
pub fn allow_cidr(self, net: IpNet) -> Self
Allow a specific address or CIDR range, overriding every block.
Source§impl NetworkPolicy
impl NetworkPolicy
Sourcepub async fn resolve_permitted(
&self,
host: &str,
) -> Result<Vec<SocketAddr>, ResolveFailure>
pub async fn resolve_permitted( &self, host: &str, ) -> Result<Vec<SocketAddr>, ResolveFailure>
Resolve host and keep the addresses the policy permits. The resolver
installed on every outbound client runs this; a caller whose transport
hides the resolver’s error (rmcp wraps it as text) runs it first via
Self::check_url so the refusal is reported in its own words.
Sourcepub async fn check_url(&self, url: &str) -> Result<(), String>
pub async fn check_url(&self, url: &str) -> Result<(), String>
Refuse a URL the policy forbids, whether its host is a literal IP or a name that resolves only to forbidden addresses. A name that fails to resolve at all passes: that failure belongs to the connection attempt, which reports it in its own terms. Skips DNS entirely when the policy permits everything.