mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Normalize managed network requirements before merging (#61391)
## Why Managed network requirements support both legacy tables and `permissions.network`. Equivalent declarations in one source should be accepted, while older runtime clients still need the top-level network field. ## What changed - Normalize `network_proxy` and `experimental_network` into `permissions.network` before merging requirements, preserving source attribution and explicit empty allowlist replacements. - Accept legacy and nested declarations in one source when they describe the same policy, comparing domain and review selectors by their canonical identities. Continue rejecting mixed surfaces across sources. - Populate the legacy output field for compatibility and preserve legacy selector text when both forms are supplied. - Include contributing requirement sources in cloud bundle errors without exposing submitted TOML. ## Testing Add coverage for equivalent and conflicting declarations, empty allowlist overrides, loader compatibility, and debug output. Add a proxy regression test verifying that a saved grant cannot bypass managed loopback restrictions. GitOrigin-RevId: e0d2a600f5c7c6c07a665ccc0e18a72ff172fd6d
This commit is contained in:
@@ -146,7 +146,7 @@ action = ['redact']
|
||||
"[unix_sockets]\n'relative.sock' = 'allow'",
|
||||
"[unix_sockets]\n'~/allowed.sock' = 'allow'",
|
||||
"[unix_sockets]\n\"/tmp/\\u0000allowed.sock\" = 'allow'",
|
||||
"[domains]\n'[' = 'allow'",
|
||||
"[domains]\n'api[12].example' = 'allow'",
|
||||
] {
|
||||
let network: NetworkToml = toml::from_str(raw).unwrap();
|
||||
let projected = project_environment_profile_network(Some(network.clone()))
|
||||
@@ -154,6 +154,14 @@ action = ['redact']
|
||||
.unwrap();
|
||||
assert_eq!(projected, network);
|
||||
let configured_proxy = projected.to_network_proxy_config();
|
||||
assert!(
|
||||
PreparedNetworkConfig {
|
||||
configured_proxy: configured_proxy.clone()
|
||||
}
|
||||
.build(/*requirements*/ None, &PermissionProfile::read_only())
|
||||
.expect("a disabled unmanaged profile can load unused selectors")
|
||||
.is_none()
|
||||
);
|
||||
let policy = EnvironmentNetworkPolicy::from_config(
|
||||
&configured_proxy,
|
||||
/*managed_allowed_domains_only*/ false,
|
||||
|
||||
@@ -27,6 +27,72 @@ fn domain_permissions(
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_grant_cannot_open_loopback_under_fixed_allowlist() -> anyhow::Result<()> {
|
||||
let profile = PermissionProfile::workspace_write();
|
||||
let spec = NetworkProxySpec::from_config_and_constraints(
|
||||
NetworkProxyConfig {
|
||||
proxy_url: "http://127.0.0.1:0".into(),
|
||||
enable_socks5: false,
|
||||
allow_upstream_proxy: false,
|
||||
..Default::default()
|
||||
},
|
||||
Some(NetworkConstraints {
|
||||
enabled: Some(true),
|
||||
managed_allowed_domains_only: Some(true),
|
||||
allow_local_binding: Some(false),
|
||||
domains: Some(domain_permissions([(
|
||||
"127.0.0.1:*",
|
||||
NetworkDomainPermissionToml::Allow,
|
||||
)])),
|
||||
..Default::default()
|
||||
}),
|
||||
&profile,
|
||||
)?;
|
||||
let mut saved = Policy::empty();
|
||||
saved.add_network_rule(
|
||||
"127.0.0.1",
|
||||
codex_execpolicy::NetworkRuleProtocol::Http,
|
||||
Allow,
|
||||
/*justification*/ None,
|
||||
)?;
|
||||
let spec = spec.with_exec_policy_network_rules(&saved)?;
|
||||
assert_eq!(
|
||||
spec.config.allowed_domains(),
|
||||
Some(vec!["127.0.0.1:*".to_owned()])
|
||||
);
|
||||
|
||||
core_test_support::skip_if_no_network!(Ok(()));
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
|
||||
let proxy = spec
|
||||
.start_proxy(
|
||||
&profile,
|
||||
ManagedProxyRouting::DedicatedListeners,
|
||||
DefaultFalse,
|
||||
/*policy_decider*/ None,
|
||||
/*blocked_request_observer*/ None,
|
||||
/*enable_network_approval_flow*/ false,
|
||||
NetworkProxyAuditMetadata::default(),
|
||||
)
|
||||
.await?;
|
||||
let request = codex_http_client::HttpClientBuilder::new()
|
||||
.build_direct()?
|
||||
.get(format!("http://{}/", proxy.proxy().http_addr()))
|
||||
.header(http::header::HOST, listener.local_addr()?.to_string())
|
||||
.timeout(std::time::Duration::from_secs(5))
|
||||
.send();
|
||||
tokio::select! {
|
||||
biased;
|
||||
connection = listener.accept() => anyhow::bail!("loopback destination reached: {:?}", connection?.1),
|
||||
response = request => {
|
||||
let response = response?;
|
||||
assert_eq!(response.status(), http::StatusCode::FORBIDDEN);
|
||||
assert_eq!(response.json::<serde_json::Value>().await?["reason"], "not_allowed_local");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn attachment_socket_grants_respect_configured_restrictions_at_remote_launch()
|
||||
-> anyhow::Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user