feat(linux-sandbox): add policy-checked DNS relay

Co-authored-by: Codex noreply@openai.com
This commit is contained in:
viyatb-oai
2026-07-08 14:19:33 -07:00
co-authored by Codex noreply@openai.com
parent 9f584f07e9
commit 7084fde2ad
9 changed files with 443 additions and 2 deletions
+1
View File
@@ -47,6 +47,7 @@ pub use network_policy::NetworkPolicyDecision;
pub use network_policy::NetworkPolicyRequest;
pub use network_policy::NetworkPolicyRequestArgs;
pub use network_policy::NetworkProtocol;
pub use policy::NetworkDomainMatcher;
pub use policy::normalize_host;
pub use proxy::ALL_PROXY_ENV_KEYS;
pub use proxy::ALLOW_LOCAL_BINDING_ENV_KEY;
+19
View File
@@ -13,6 +13,8 @@ use std::net::Ipv4Addr;
use std::net::Ipv6Addr;
use url::Host as UrlHost;
use crate::proxy::ManagedNetworkDomainPolicy;
/// A normalized host string for policy evaluation.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Host(String);
@@ -190,6 +192,23 @@ pub(crate) fn compile_denylist_globset(patterns: &[String]) -> Result<GlobSet> {
compile_globset_with_policy(patterns, GlobalWildcard::Reject)
}
/// Compiled managed domain policy for sandbox-side name resolution.
pub struct NetworkDomainMatcher(GlobSet, GlobSet);
impl NetworkDomainMatcher {
pub fn new(policy: &ManagedNetworkDomainPolicy) -> Result<Self> {
Ok(Self(
compile_allowlist_globset(&policy.allowed_domains)?,
compile_denylist_globset(&policy.denied_domains)?,
))
}
pub fn is_allowed(&self, host: &str) -> bool {
let host = normalize_host(host);
!host.is_empty() && !self.1.is_match(&host) && self.0.is_match(&host)
}
}
fn compile_globset_with_policy(
patterns: &[String],
global_wildcard: GlobalWildcard,