mirror of
https://github.com/openai/codex.git
synced 2026-11-13 21:30:47 +00:00
## 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
94 lines
3.8 KiB
Rust
94 lines
3.8 KiB
Rust
//! Executor-local paths and trusted startup settings used when preparing execution.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use codex_sandboxing::LinuxSandboxPidNamespace;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
|
|
/// Paths and sandbox settings initialized when creating an executor.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct ExecServerRuntimeOptions {
|
|
/// Stable path to the Codex executable used to launch hidden helper modes.
|
|
pub codex_self_exe: AbsolutePathBuf,
|
|
/// Path to the Linux sandbox helper alias used when the platform sandbox
|
|
/// needs to re-enter Codex by argv0.
|
|
pub codex_linux_sandbox_exe: Option<AbsolutePathBuf>,
|
|
/// Trusted startup policy; requests and repository config cannot change PID isolation.
|
|
pub linux_sandbox_pid_namespace: LinuxSandboxPidNamespace,
|
|
/// Enable transparent TCP for managed Linux command launches.
|
|
pub linux_sandbox_transparent_tcp: bool,
|
|
/// Trusted startup routing; request policy still controls destination access.
|
|
pub proxy_private_ips_via_upstream: bool,
|
|
/// Mandatory next hop for opaque SOCKS TCP when set by provisioning.
|
|
pub tcp_upstream_proxy: Option<codex_network_proxy::TcpUpstreamProxy>,
|
|
/// Only the sandbox preference from CLI flags, never other startup config or secrets.
|
|
pub prefer_mxc: Option<bool>,
|
|
/// User-config opt-out of writable-root symlink checks beneath this host's home.
|
|
#[cfg(target_os = "macos")]
|
|
pub allowed_symlinked_codex_home: Option<AbsolutePathBuf>,
|
|
}
|
|
|
|
impl ExecServerRuntimeOptions {
|
|
pub fn from_optional_paths(
|
|
codex_self_exe: Option<PathBuf>,
|
|
codex_linux_sandbox_exe: Option<PathBuf>,
|
|
) -> std::io::Result<Self> {
|
|
let codex_self_exe = codex_self_exe.ok_or_else(|| {
|
|
std::io::Error::new(
|
|
std::io::ErrorKind::InvalidInput,
|
|
"Codex executable path is not configured",
|
|
)
|
|
})?;
|
|
Self::new(codex_self_exe, codex_linux_sandbox_exe)
|
|
}
|
|
|
|
pub fn new(
|
|
codex_self_exe: PathBuf,
|
|
codex_linux_sandbox_exe: Option<PathBuf>,
|
|
) -> std::io::Result<Self> {
|
|
Ok(Self {
|
|
linux_sandbox_pid_namespace: LinuxSandboxPidNamespace::default(),
|
|
linux_sandbox_transparent_tcp: false,
|
|
proxy_private_ips_via_upstream: false,
|
|
tcp_upstream_proxy: None,
|
|
prefer_mxc: None,
|
|
codex_self_exe: absolute_path(codex_self_exe)?,
|
|
codex_linux_sandbox_exe: codex_linux_sandbox_exe.map(absolute_path).transpose()?,
|
|
#[cfg(target_os = "macos")]
|
|
allowed_symlinked_codex_home: None,
|
|
})
|
|
}
|
|
|
|
/// Applies the PID namespace policy chosen by trusted executor provisioning.
|
|
pub fn with_linux_sandbox_pid_namespace(mut self, mode: LinuxSandboxPidNamespace) -> Self {
|
|
self.linux_sandbox_pid_namespace = mode;
|
|
self
|
|
}
|
|
|
|
pub fn with_linux_sandbox_transparent_tcp(mut self, enabled: bool) -> Self {
|
|
self.linux_sandbox_transparent_tcp = enabled;
|
|
self
|
|
}
|
|
|
|
/// Routes permitted private IPs through the executor's configured upstream proxy.
|
|
pub fn with_proxy_private_ips_via_upstream(mut self, enabled: bool) -> Self {
|
|
self.proxy_private_ips_via_upstream = enabled;
|
|
self
|
|
}
|
|
|
|
/// Applies the symlink opt-in resolved by the execution host's config loader.
|
|
#[cfg(target_os = "macos")]
|
|
pub fn with_allowed_symlinked_codex_home(
|
|
mut self,
|
|
allowed_symlinked_codex_home: Option<AbsolutePathBuf>,
|
|
) -> Self {
|
|
self.allowed_symlinked_codex_home = allowed_symlinked_codex_home;
|
|
self
|
|
}
|
|
}
|
|
|
|
fn absolute_path(path: PathBuf) -> std::io::Result<AbsolutePathBuf> {
|
|
AbsolutePathBuf::from_absolute_path(path.as_path())
|
|
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err))
|
|
}
|