mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Preserve attachment Unix socket grants when controller policy is omitted (#46004)
## Why An omitted controller socket policy was treated as an explicit denial, preventing execution environments from supplying their own Unix socket grants. ## What changed - Preserve omission of `dangerously_allow_all_unix_sockets` separately from `false`, and retain explicitly empty `unix_sockets` maps. - Defer to attachment socket permissions when the controller supplies neither setting. Continue enforcing explicit restrictions, socket denials, and managed requirements. - Resolve omitted values to `false` for ordinary execution and remote configuration, preserving the default for commands without attachment grants. - Add debug logging for effective environment and remote execution network policies. ## Testing Add regression coverage for omitted, explicit, finite, empty, and managed socket policies through remote launch configuration, including live policy replacement and serialization round trips. Adjust remote environment tests to tolerate child-completion ordering and box large cold-resume test futures to reduce Windows stack usage. GitOrigin-RevId: 98a88d01cbb91aea1faaa03b3c414ef3be7af398
This commit is contained in:
@@ -266,7 +266,7 @@ impl NetworkProxySpec {
|
||||
NetworkProxyConfig {
|
||||
enabled: true,
|
||||
// Without a controller, the owner supplies the entire permission ceiling.
|
||||
dangerously_allow_all_unix_sockets: true,
|
||||
dangerously_allow_all_unix_sockets: Some(true),
|
||||
allow_local_binding: true,
|
||||
..NetworkProxyConfig::default()
|
||||
},
|
||||
@@ -308,6 +308,13 @@ impl NetworkProxySpec {
|
||||
format!("environment network policy violates managed requirements: {error}"),
|
||||
)
|
||||
})?;
|
||||
tracing::debug!(
|
||||
controller_policy = ?controller.map(Self::environment_policy),
|
||||
controller_allow_all_unix_sockets = ?controller.and_then(|spec| spec.config.dangerously_allow_all_unix_sockets),
|
||||
attachment_policy = ?policy,
|
||||
effective_policy = ?spec.environment_policy(),
|
||||
"resolved environment network policy"
|
||||
);
|
||||
Ok(spec)
|
||||
}
|
||||
|
||||
@@ -394,7 +401,7 @@ impl NetworkProxySpec {
|
||||
if let Some(dangerously_allow_all_unix_sockets) =
|
||||
requirements.dangerously_allow_all_unix_sockets
|
||||
{
|
||||
config.dangerously_allow_all_unix_sockets = dangerously_allow_all_unix_sockets;
|
||||
config.dangerously_allow_all_unix_sockets = Some(dangerously_allow_all_unix_sockets);
|
||||
constraints.dangerously_allow_all_unix_sockets =
|
||||
Some(dangerously_allow_all_unix_sockets);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,134 @@ fn domain_permissions(
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn attachment_socket_grants_respect_configured_restrictions_at_remote_launch()
|
||||
-> anyhow::Result<()> {
|
||||
let profile = PermissionProfile::workspace_write();
|
||||
let owner = EnvironmentNetworkPolicy::from_config(
|
||||
&NetworkProxyConfig {
|
||||
dangerously_allow_all_unix_sockets: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
/*managed_allowed_domains_only*/ false,
|
||||
);
|
||||
for (name, toml, required, expected) in [
|
||||
("omitted", "", None, true),
|
||||
(
|
||||
"explicit_deny",
|
||||
"dangerously_allow_all_unix_sockets = false",
|
||||
None,
|
||||
false,
|
||||
),
|
||||
(
|
||||
"explicit_allow",
|
||||
"dangerously_allow_all_unix_sockets = true",
|
||||
None,
|
||||
true,
|
||||
),
|
||||
(
|
||||
"finite",
|
||||
"unix_sockets = { '/tmp/allowed.sock' = 'allow', '/tmp/denied.sock' = 'deny' }",
|
||||
None,
|
||||
false,
|
||||
),
|
||||
("empty", "unix_sockets = {}", None, false),
|
||||
(
|
||||
"managed_deny",
|
||||
"dangerously_allow_all_unix_sockets = true",
|
||||
Some(false),
|
||||
false,
|
||||
),
|
||||
] {
|
||||
let configured: codex_config::permissions_toml::NetworkToml = toml::from_str(toml)?;
|
||||
let controller = NetworkProxySpec::from_config_and_constraints(
|
||||
configured.to_network_proxy_config(),
|
||||
Some(NetworkConstraints {
|
||||
enabled: Some(true),
|
||||
dangerously_allow_all_unix_sockets: required,
|
||||
..Default::default()
|
||||
}),
|
||||
&profile,
|
||||
)?;
|
||||
let composed = NetworkProxySpec::for_environment(
|
||||
Some(&controller),
|
||||
&owner,
|
||||
&profile,
|
||||
&Policy::empty(),
|
||||
)?;
|
||||
assert_eq!(
|
||||
composed.config.dangerously_allow_all_unix_sockets,
|
||||
Some(expected),
|
||||
"{name}"
|
||||
);
|
||||
let state = Arc::new(controller.build_state_with_audit_metadata(Default::default())?);
|
||||
let proxy = NetworkProxy::builder()
|
||||
.state(Arc::clone(&state))
|
||||
.managed_by_codex(false)
|
||||
.build()
|
||||
.await?;
|
||||
let scoped = proxy.for_execution(
|
||||
"socket-test",
|
||||
name,
|
||||
format!("socket-{name}"),
|
||||
Some(composed.environment_policy()),
|
||||
/*fallback_policy_decider*/ None,
|
||||
)?;
|
||||
let launch = scoped.remote_launch_config().await?;
|
||||
assert_eq!(
|
||||
launch.proxy.dangerously_allow_all_unix_sockets, expected,
|
||||
"{name}"
|
||||
);
|
||||
assert_eq!(
|
||||
launch.proxy.unix_sockets, composed.config.unix_sockets,
|
||||
"{name}"
|
||||
);
|
||||
if name == "finite" {
|
||||
assert_eq!(launch.proxy.unix_sockets, controller.config.unix_sockets);
|
||||
}
|
||||
if name == "omitted" {
|
||||
// Inheritance must not grant sockets to ordinary controller-only commands.
|
||||
assert!(
|
||||
!proxy
|
||||
.remote_launch_config()
|
||||
.await?
|
||||
.proxy
|
||||
.dangerously_allow_all_unix_sockets
|
||||
);
|
||||
state.add_allowed_domain("granted.example").await?;
|
||||
assert!(
|
||||
scoped
|
||||
.remote_launch_config()
|
||||
.await?
|
||||
.proxy
|
||||
.dangerously_allow_all_unix_sockets
|
||||
);
|
||||
|
||||
// A live handle must also honor a subsequently installed explicit restriction.
|
||||
let restricted = NetworkProxySpec::from_config_and_constraints(
|
||||
NetworkProxyConfig {
|
||||
enabled: true,
|
||||
dangerously_allow_all_unix_sockets: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
/*requirements*/ None,
|
||||
&profile,
|
||||
)?;
|
||||
proxy
|
||||
.replace_config_state(restricted.build_config_state_for_spec()?)
|
||||
.await?;
|
||||
assert!(
|
||||
!scoped
|
||||
.remote_launch_config()
|
||||
.await?
|
||||
.proxy
|
||||
.dangerously_allow_all_unix_sockets
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_state_with_audit_metadata_threads_metadata_to_state() {
|
||||
let spec = NetworkProxySpec {
|
||||
@@ -119,7 +247,7 @@ fn environment_policy_replaces_soft_controller_allowlist_and_preserves_denials()
|
||||
"/private/tmp/controller.sock".to_string(),
|
||||
"/tmp/allowed.sock".to_string(),
|
||||
]);
|
||||
owner.dangerously_allow_all_unix_sockets = true;
|
||||
owner.dangerously_allow_all_unix_sockets = Some(true);
|
||||
owner.allow_local_binding = true;
|
||||
let owner_policy =
|
||||
EnvironmentNetworkPolicy::from_config(&owner, /*managed_allowed_domains_only*/ false);
|
||||
@@ -162,7 +290,7 @@ fn environment_policy_replaces_soft_controller_allowlist_and_preserves_denials()
|
||||
);
|
||||
owner.unix_sockets.clone_from(&spec.config.unix_sockets);
|
||||
owner.allow_upstream_proxy = false;
|
||||
owner.dangerously_allow_all_unix_sockets = false;
|
||||
owner.dangerously_allow_all_unix_sockets = Some(false);
|
||||
owner.allow_local_binding = false;
|
||||
assert_eq!(
|
||||
restricted.environment_policy(),
|
||||
|
||||
Reference in New Issue
Block a user