mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Add opt-in transparent TCP routing for Linux sandboxes (#61372)
## Why Native TCP clients need to reach managed network destinations without implementing proxy support themselves. ## What changed - Add `--transparent-tcp` to the Linux sandbox command, using a bundled TCP stack, private TUN interface, and DNS stub to route native IPv4 and IPv6 connections through the attributed managed SOCKS proxy. - Preserve original hostnames for proxy policy checks and cancel pending approval connections when their native sockets close. - Expose `--linux-sandbox-transparent-tcp` and `--tcp-upstream-proxy` on `codex exec-server` for transparent routing and a mandatory HTTP CONNECT next hop without direct fallback. - Require private network and PID namespaces, private procfs, system `bwrap`, and access to `/dev/net/tun`; reject incompatible launcher options and untrusted proxy ports. ## Testing Add integration coverage for native hostname and IPv6 connections, SOCKS attribution, pending connection cancellation, policy denials, and filesystem and host-loopback isolation. Extend launcher and executor tests for option validation and managed-policy propagation. GitOrigin-RevId: 96bd7726e5369efceb65320face56aa85ae3deb8
This commit is contained in:
@@ -101,6 +101,7 @@ pub async fn run_command_under_landlock(
|
||||
loader_overrides: LoaderOverrides,
|
||||
) -> anyhow::Result<()> {
|
||||
let LandlockCommand {
|
||||
transparent_tcp,
|
||||
sandbox_state,
|
||||
permissions_profile,
|
||||
config_profile: _,
|
||||
@@ -124,7 +125,7 @@ pub async fn run_command_under_landlock(
|
||||
command,
|
||||
config_overrides,
|
||||
codex_linux_sandbox_exe,
|
||||
SandboxType::Landlock,
|
||||
SandboxType::Landlock { transparent_tcp },
|
||||
/*log_denials*/ false,
|
||||
&[],
|
||||
)
|
||||
@@ -170,7 +171,9 @@ pub async fn run_command_under_windows_sandbox(
|
||||
enum SandboxType {
|
||||
#[cfg(target_os = "macos")]
|
||||
Seatbelt,
|
||||
Landlock,
|
||||
Landlock {
|
||||
transparent_tcp: bool,
|
||||
},
|
||||
Windows,
|
||||
}
|
||||
|
||||
@@ -304,12 +307,21 @@ async fn run_command_under_sandbox(
|
||||
config.effective_local_windows_sandbox_type()
|
||||
};
|
||||
|
||||
let transparent_tcp = matches!(
|
||||
sandbox_type,
|
||||
SandboxType::Landlock {
|
||||
transparent_tcp: true
|
||||
}
|
||||
);
|
||||
let sandbox = match permission_profile.enforcement() {
|
||||
SandboxEnforcement::Disabled | SandboxEnforcement::External if transparent_tcp => {
|
||||
anyhow::bail!("--transparent-tcp requires a managed Linux sandbox");
|
||||
}
|
||||
SandboxEnforcement::Disabled | SandboxEnforcement::External => SandboxBackend::None,
|
||||
SandboxEnforcement::Managed => match sandbox_type {
|
||||
#[cfg(target_os = "macos")]
|
||||
SandboxType::Seatbelt => SandboxBackend::MacosSeatbelt,
|
||||
SandboxType::Landlock => SandboxBackend::LinuxSeccomp,
|
||||
SandboxType::Landlock { .. } => SandboxBackend::LinuxSeccomp,
|
||||
#[cfg(windows)]
|
||||
SandboxType::Windows if windows_sandbox_type == WindowsMxc => WindowsMxc,
|
||||
#[cfg(windows)]
|
||||
@@ -386,6 +398,10 @@ async fn run_command_under_sandbox(
|
||||
let manager = SandboxManager::for_inherited_terminal(allow_unix_sockets);
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
let manager = SandboxManager::new();
|
||||
if transparent_tcp && network.is_none() {
|
||||
anyhow::bail!("--transparent-tcp requires a managed network proxy");
|
||||
}
|
||||
let manager = manager.with_linux_sandbox_transparent_tcp(transparent_tcp);
|
||||
let workspace_roots = sandbox_state.is_none().then(|| {
|
||||
config
|
||||
.permissions
|
||||
|
||||
@@ -109,6 +109,10 @@ fn parse_absolute_path(raw: &str) -> Result<AbsolutePathBuf, String> {
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct LandlockCommand {
|
||||
/// Route outbound TCP through the managed SOCKS proxy.
|
||||
#[arg(long)]
|
||||
pub transparent_tcp: bool,
|
||||
|
||||
#[command(flatten)]
|
||||
pub sandbox_state: SandboxStateArgs,
|
||||
|
||||
|
||||
+7
@@ -39,6 +39,13 @@ Options:
|
||||
|
||||
[default: isolate]
|
||||
|
||||
--linux-sandbox-transparent-tcp
|
||||
Route managed Linux sandbox TCP through the SOCKS proxy
|
||||
|
||||
--tcp-upstream-proxy <HOST:PORT>
|
||||
Require this HTTP CONNECT proxy for raw TCP from the managed SOCKS
|
||||
listener
|
||||
|
||||
--proxy-private-ips-via-upstream
|
||||
Allow permitted private IP destinations to use the configured upstream
|
||||
proxy. If no valid upstream proxy applies to the request protocol,
|
||||
|
||||
Reference in New Issue
Block a user