mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:16:05 +00:00
Honor explicit Unix socket grants in the Linux managed sandbox (#45534)
## Why Linux proxy-routed sandboxing denied standalone Unix sockets even when the effective network policy enabled `dangerously_allow_all_unix_sockets`. ## What changed - Carry Unix socket permissions in `ManagedNetworkSandboxContext` and pass the prepared context through Linux sandbox launches with `--managed-network`. - Allow `AF_UNIX` socket creation in proxy-routed mode when `dangerously_allow_all_unix_sockets` is enabled, while preserving network namespace isolation and restrictions on other socket families. - Keep standalone Unix sockets denied by default and for path-only grants. Default missing fields in older serialized contexts to restrictive values. ## Testing Add coverage for policy preparation and transport, legacy deserialization, and malformed policy rejection. Add a Linux integration test covering default denial, path-only denial, and explicit allow-all access, while checking that direct TCP access and `AF_NETLINK`/`AF_VSOCK` sockets remain blocked. GitOrigin-RevId: 2695b945ad3e59fcb3faf7662d852a26650af16c
This commit is contained in:
1 parent
d39cfa8a2d
commit
99914f4950
18 files changed
+599
-68
No files matched your search
@@ -29,6 +29,7 @@ use crate::launcher::exec_bwrap;
|
||||
use crate::launcher::preferred_bwrap_supports_argv0;
|
||||
use crate::proxy_routing::activate_proxy_routes_in_netns;
|
||||
use crate::proxy_routing::prepare_host_proxy_route_spec;
|
||||
use codex_network_proxy::ManagedNetworkSandboxContext;
|
||||
use codex_protocol::error::Result as CodexResult;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::protocol::FileSystemAccessMode;
|
||||
@@ -123,13 +124,13 @@ pub struct LandlockCommand {
|
||||
#[arg(long = "apply-seccomp-then-exec", hide = true, default_value_t = false)]
|
||||
pub apply_seccomp_then_exec: bool,
|
||||
|
||||
/// Internal compatibility flag.
|
||||
///
|
||||
/// By default, restricted-network sandboxing uses isolated networking.
|
||||
/// If set, sandbox setup switches to proxy-only network mode with
|
||||
/// managed routing bridges.
|
||||
#[arg(long = "allow-network-for-proxy", hide = true, default_value_t = false)]
|
||||
pub allow_network_for_proxy: bool,
|
||||
/// Effective managed-network policy prepared for this command launch.
|
||||
#[arg(
|
||||
long,
|
||||
hide = true,
|
||||
value_parser = parse_managed_network
|
||||
)]
|
||||
pub managed_network: Option<ManagedNetworkSandboxContext>,
|
||||
|
||||
/// Internal route spec used for managed proxy routing in bwrap mode.
|
||||
#[arg(long = "proxy-route-spec", hide = true)]
|
||||
@@ -164,12 +165,13 @@ pub fn run_main() -> ! {
|
||||
permission_profile,
|
||||
use_legacy_landlock,
|
||||
apply_seccomp_then_exec,
|
||||
allow_network_for_proxy,
|
||||
managed_network,
|
||||
proxy_route_spec,
|
||||
verify_fd_mounts,
|
||||
no_proc,
|
||||
command,
|
||||
} = LandlockCommand::parse();
|
||||
let allow_network_for_proxy = managed_network.is_some();
|
||||
|
||||
if command.is_empty() {
|
||||
panic!("No command specified to execute.");
|
||||
@@ -236,7 +238,7 @@ pub fn run_main() -> ! {
|
||||
&permission_profile,
|
||||
&sandbox_policy_cwd,
|
||||
/*apply_landlock_fs*/ false,
|
||||
allow_network_for_proxy,
|
||||
managed_network.as_ref(),
|
||||
proxy_routing_active,
|
||||
) {
|
||||
panic!("error applying Linux sandbox restrictions: {e:?}");
|
||||
@@ -282,8 +284,8 @@ pub fn run_main() -> ! {
|
||||
&permission_profile,
|
||||
&sandbox_policy_cwd,
|
||||
/*apply_landlock_fs*/ false,
|
||||
allow_network_for_proxy,
|
||||
/*proxy_routed_network*/ false,
|
||||
managed_network.as_ref(),
|
||||
/*proxy_routing_active*/ false,
|
||||
) {
|
||||
panic!("error applying Linux sandbox restrictions: {e:?}");
|
||||
}
|
||||
@@ -305,7 +307,7 @@ pub fn run_main() -> ! {
|
||||
sandbox_policy_cwd: &sandbox_policy_cwd,
|
||||
command_cwd: command_cwd.as_deref(),
|
||||
permission_profile: &permission_profile,
|
||||
allow_network_for_proxy,
|
||||
managed_network,
|
||||
proxy_route_spec,
|
||||
command,
|
||||
});
|
||||
@@ -325,8 +327,8 @@ pub fn run_main() -> ! {
|
||||
&permission_profile,
|
||||
&sandbox_policy_cwd,
|
||||
/*apply_landlock_fs*/ true,
|
||||
allow_network_for_proxy,
|
||||
/*proxy_routed_network*/ false,
|
||||
managed_network.as_ref(),
|
||||
/*proxy_routing_active*/ false,
|
||||
) {
|
||||
panic!("error applying legacy Linux sandbox restrictions: {e:?}");
|
||||
}
|
||||
@@ -357,6 +359,11 @@ fn parse_permission_profile(value: &str) -> std::result::Result<PermissionProfil
|
||||
serde_json::from_str(value).map_err(|err| format!("invalid permission profile JSON: {err}"))
|
||||
}
|
||||
|
||||
fn parse_managed_network(value: &str) -> std::result::Result<ManagedNetworkSandboxContext, String> {
|
||||
serde_json::from_str(value)
|
||||
.map_err(|err| format!("invalid managed network context JSON: {err}"))
|
||||
}
|
||||
|
||||
fn resolve_permission_profile(
|
||||
permission_profile: Option<PermissionProfile>,
|
||||
) -> Result<EffectivePermissions, ResolvePermissionProfileError> {
|
||||
@@ -1521,7 +1528,7 @@ struct InnerSeccompCommandArgs<'a> {
|
||||
sandbox_policy_cwd: &'a Path,
|
||||
command_cwd: Option<&'a Path>,
|
||||
permission_profile: &'a PermissionProfile,
|
||||
allow_network_for_proxy: bool,
|
||||
managed_network: Option<ManagedNetworkSandboxContext>,
|
||||
proxy_route_spec: Option<String>,
|
||||
command: Vec<String>,
|
||||
}
|
||||
@@ -1532,7 +1539,7 @@ fn build_inner_seccomp_command(args: InnerSeccompCommandArgs<'_>) -> Vec<String>
|
||||
sandbox_policy_cwd,
|
||||
command_cwd,
|
||||
permission_profile,
|
||||
allow_network_for_proxy,
|
||||
managed_network,
|
||||
proxy_route_spec,
|
||||
command,
|
||||
} = args;
|
||||
@@ -1559,8 +1566,12 @@ fn build_inner_seccomp_command(args: InnerSeccompCommandArgs<'_>) -> Vec<String>
|
||||
permission_profile_json,
|
||||
"--apply-seccomp-then-exec".to_string(),
|
||||
]);
|
||||
if allow_network_for_proxy {
|
||||
inner.push("--allow-network-for-proxy".to_string());
|
||||
if let Some(managed_network) = managed_network {
|
||||
inner.push("--managed-network".to_string());
|
||||
inner.push(
|
||||
serde_json::to_string(&managed_network)
|
||||
.unwrap_or_else(|err| panic!("failed to serialize managed network context: {err}")),
|
||||
);
|
||||
let proxy_route_spec = proxy_route_spec
|
||||
.unwrap_or_else(|| panic!("managed proxy mode requires a proxy route spec"));
|
||||
inner.push("--proxy-route-spec".to_string());
|
||||
|
||||
Reference in new issue
Block a user