mirror of
https://github.com/openai/codex.git
synced 2026-11-20 23:08:21 +00:00
Harden managed proxy listener handoff (#40999)
## Why Linux managed networking routed proxy connections through filesystem-backed Unix sockets, requiring an extra readable sandbox path and stale socket cleanup. ## What changed - Transfer loopback TCP listeners from the sandbox namespace to host bridge processes over anonymous Unix socket pairs. - Validate transferred descriptors, keep bootstrap channels private to each sandbox launch, and close them before running untrusted commands. - Tie proxy bridge lifetime to the sandbox so cancellation closes active upstream connections. ## Testing - Cover descriptor validation and interrupted handoffs. - Verify concurrent sandboxes keep proxy endpoints isolated and do not inherit privileged sockets. - Exercise managed networking end to end through `app-server`, confirming proxied access succeeds while direct host access remains blocked. GitOrigin-RevId: 6561e09c83b927c604951bf2aa00ff532d179da5
This commit is contained in:
1 parent
528fd7ace5
commit
f3741880f6
8 files changed
+839
-462
No files matched your search
@@ -179,7 +179,7 @@ pub fn run_main() -> ! {
|
||||
ensure_inner_stage_mode_is_valid(apply_seccomp_then_exec, use_legacy_landlock);
|
||||
let EffectivePermissions {
|
||||
permission_profile,
|
||||
mut file_system_sandbox_policy,
|
||||
file_system_sandbox_policy,
|
||||
network_sandbox_policy,
|
||||
} = resolve_permission_profile(permission_profile).unwrap_or_else(|err| panic!("{err}"));
|
||||
ensure_legacy_landlock_mode_supports_policy(
|
||||
@@ -291,16 +291,12 @@ pub fn run_main() -> ! {
|
||||
// Outer stage: bubblewrap first, then re-enter this binary in the
|
||||
// sandboxed environment to apply seccomp. This path never falls back
|
||||
// to legacy Landlock on failure.
|
||||
let proxy_route_spec = if allow_network_for_proxy {
|
||||
let (proxy_route_spec, socket_dir) = prepare_host_proxy_route_spec()
|
||||
let (proxy_route_spec, proxy_controls) = if allow_network_for_proxy {
|
||||
let (proxy_route_spec, controls) = prepare_host_proxy_route_spec()
|
||||
.unwrap_or_else(|err| panic!("failed to prepare host proxy routing bridge: {err}"));
|
||||
file_system_sandbox_policy = file_system_sandbox_policy.with_additional_readable_roots(
|
||||
&sandbox_policy_cwd,
|
||||
std::slice::from_ref(&socket_dir),
|
||||
);
|
||||
Some(proxy_route_spec)
|
||||
(Some(proxy_route_spec), controls)
|
||||
} else {
|
||||
None
|
||||
(None, Vec::new())
|
||||
};
|
||||
let inner = build_inner_seccomp_command(InnerSeccompCommandArgs {
|
||||
sandbox_policy_cwd: &sandbox_policy_cwd,
|
||||
@@ -314,10 +310,10 @@ pub fn run_main() -> ! {
|
||||
&sandbox_policy_cwd,
|
||||
command_cwd.as_deref(),
|
||||
&file_system_sandbox_policy,
|
||||
network_sandbox_policy,
|
||||
bwrap_network_mode(network_sandbox_policy, allow_network_for_proxy),
|
||||
inner,
|
||||
proxy_controls,
|
||||
!no_proc,
|
||||
allow_network_for_proxy,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -398,12 +394,11 @@ fn run_bwrap_with_proc_fallback(
|
||||
sandbox_policy_cwd: &Path,
|
||||
command_cwd: Option<&Path>,
|
||||
file_system_sandbox_policy: &FileSystemSandboxPolicy,
|
||||
network_sandbox_policy: NetworkSandboxPolicy,
|
||||
network_mode: BwrapNetworkMode,
|
||||
inner: Vec<String>,
|
||||
proxy_controls: Vec<File>,
|
||||
mount_proc: bool,
|
||||
allow_network_for_proxy: bool,
|
||||
) -> ! {
|
||||
let network_mode = bwrap_network_mode(network_sandbox_policy, allow_network_for_proxy);
|
||||
let mut mount_proc = mount_proc;
|
||||
let command_cwd = command_cwd.unwrap_or(sandbox_policy_cwd);
|
||||
|
||||
@@ -429,6 +424,7 @@ fn run_bwrap_with_proc_fallback(
|
||||
options,
|
||||
)
|
||||
.unwrap_or_else(|err| exit_with_bwrap_build_error(err));
|
||||
bwrap_args.preserved_files.extend(proxy_controls);
|
||||
apply_inner_command_argv0(&mut bwrap_args.args);
|
||||
run_or_exec_bwrap(bwrap_args);
|
||||
}
|
||||
@@ -597,6 +593,7 @@ fn run_bwrap_in_child_with_synthetic_mount_cleanup(bwrap_args: crate::bwrap::Bwr
|
||||
exec_bwrap(args, preserved_files);
|
||||
}
|
||||
|
||||
drop(preserved_files);
|
||||
close_child_exec_start_read(exec_start_pipe[0]);
|
||||
let protected_create_monitor = ProtectedCreateMonitor::start(&protected_create_targets);
|
||||
let signal_forwarders = install_bwrap_signal_forwarders(pid);
|
||||
|
||||
Reference in new issue
Block a user