Compose managed domain rules across network config layers (#62882)

## Why

Managed requirements from different sources could not be combined when one
used `[permissions.network]` and another used `[network_proxy]` or
`[experimental_network]`.

## What changed

Allow these tables to compose across sources. The highest-priority list of
each kind replaces lower lists of that kind, while keyed `domains` entries
update individual selectors by source priority. A deny wins when a selector
appears in both surviving lists. A surviving `allowed_domains = []` clears
lower-priority grants, while an empty `domains` map contributes no updates.

Require mirrored domain declarations to agree on how they compose with other
domain sources. Unix socket path rules still require a single network table
spelling across sources.

Carry equivalent denied selector spellings into the effective proxy policy.
When local binding is disabled, an attached executor's explicit local grant
must also satisfy the controller's allowlist constraints. The standalone
proxy can still narrow a wildcard to an explicit local grant.

## Testing

Cover mixed table spellings, list replacement and clearing, conflicting
mirrors, equivalent IPv6 spellings, and local grants in standalone and
attached proxy modes.

GitOrigin-RevId: b3d550d9f462564c89663ea4b15e723f0ea76881
This commit is contained in:
viyatb-oai
2026-11-21 01:28:12 +00:00
committed by copyberry
parent 566020b724
commit bb1037ba04
9 changed files with 548 additions and 93 deletions
+15 -1
View File
@@ -26,6 +26,7 @@ use codex_network_proxy::validate_policy_against_constraints;
use codex_protocol::models::PermissionProfile;
use codex_protocol::protocol::AskForApproval;
use codex_utils_path_uri::Platform;
use std::collections::HashSet;
use std::net::IpAddr;
use std::sync::Arc;
@@ -605,7 +606,20 @@ impl NetworkProxySpec {
.domains
.as_ref()
.and_then(codex_config::NetworkDomainPermissionsToml::denied_domains);
if let Some(managed_denied_domains) = managed_denied_domains {
if let Some(mut managed_denied_domains) = managed_denied_domains {
// The managed allowlist can contain a shadowed spelling of a denied
// selector. Explicitly deny that spelling for text-based executors.
let denied: HashSet<_> = managed_denied_domains
.iter()
.filter_map(|pattern| codex_network_proxy::canonical_deny_pattern(pattern).ok())
.collect();
for pattern in constraints.allowed_domains.iter().flatten() {
if codex_network_proxy::canonical_review_pattern(pattern)
.is_ok_and(|selector| denied.contains(&selector))
{
managed_denied_domains.push(pattern.clone());
}
}
let effective_denied_domains = if denylist_expansion_enabled {
Self::merge_domain_lists(
managed_denied_domains.clone(),
@@ -767,10 +767,10 @@ fn requirements_denied_domains_are_a_baseline_for_default_mode() {
let mut config = NetworkProxyConfig::default();
config.set_denied_domains(vec!["blocked.example.com".to_string()]);
let requirements = NetworkConstraints {
domains: Some(domain_permissions([(
"managed-blocked.example.com",
NetworkDomainPermissionToml::Deny,
)])),
domains: Some(domain_permissions([
("2001:DB8::1", NetworkDomainPermissionToml::Allow),
("2001:0db8::1", NetworkDomainPermissionToml::Deny),
])),
..Default::default()
};
@@ -784,13 +784,14 @@ fn requirements_denied_domains_are_a_baseline_for_default_mode() {
assert_eq!(
spec.config.denied_domains(),
Some(vec![
"managed-blocked.example.com".to_string(),
"2001:DB8::1".to_string(),
"2001:0db8::1".to_string(),
"blocked.example.com".to_string()
])
);
assert_eq!(
spec.constraints.denied_domains,
Some(vec!["managed-blocked.example.com".to_string()])
Some(vec!["2001:0db8::1".to_string(), "2001:DB8::1".to_string()])
);
assert_eq!(spec.constraints.denylist_expansion_enabled, Some(true));
}