mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Allow network policy to enable transparent TCP capture (#61851)
## What changed - Add `transparent_tcp` to network configuration and managed requirements, defaulting to off. When enabled, route outbound TCP from managed Linux sandbox commands through the managed SOCKS5 proxy without requiring an executor startup flag. - Propagate the setting through local and remote execution, require an enabled SOCKS5 proxy, and check the executor's `networkProxyTransparentTcp` capability before remote launches. - Refresh the live proxy when switching between permission profiles with different network settings. ## Testing Add coverage for configuration-driven sandbox capture, rejection of unsupported launch contexts, execution parameter propagation, and live permission profile changes. GitOrigin-RevId: c4db87056de116f433a128806bef673802f35397
This commit is contained in:
@@ -137,6 +137,9 @@ pub struct NetworkProxyConfig {
|
||||
#[serde(default = "default_proxy_url")]
|
||||
pub proxy_url: String,
|
||||
pub enable_socks5: bool,
|
||||
/// Route outbound TCP from managed Linux sandbox commands through the managed SOCKS5 proxy.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub transparent_tcp: bool,
|
||||
#[serde(default = "default_socks_url")]
|
||||
pub socks_url: String,
|
||||
pub enable_socks5_udp: bool,
|
||||
@@ -188,6 +191,7 @@ impl Default for NetworkProxyConfig {
|
||||
enabled: false,
|
||||
proxy_url: default_proxy_url(),
|
||||
enable_socks5: true,
|
||||
transparent_tcp: false,
|
||||
socks_url: default_socks_url(),
|
||||
enable_socks5_udp: true,
|
||||
allow_upstream_proxy: true,
|
||||
@@ -750,6 +754,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
NetworkProxyConfig::default(),
|
||||
NetworkProxyConfig {
|
||||
transparent_tcp: false,
|
||||
enabled: false,
|
||||
proxy_url: "http://127.0.0.1:3128".to_string(),
|
||||
enable_socks5: true,
|
||||
|
||||
@@ -16,6 +16,9 @@ pub struct EnvironmentNetworkPolicy {
|
||||
/// False or omission leaves activation to the controller and command permissions.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub requires_proxy: bool,
|
||||
/// Route outbound TCP from managed Linux sandbox commands through the managed SOCKS5 proxy.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub transparent_tcp: bool,
|
||||
pub domains: Option<NetworkDomainPermissions>,
|
||||
/// Managed host selectors inherited by every execution in this environment.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
@@ -33,6 +36,7 @@ impl EnvironmentNetworkPolicy {
|
||||
pub fn from_config(config: &NetworkProxyConfig, managed_allowed_domains_only: bool) -> Self {
|
||||
Self {
|
||||
requires_proxy: config.enabled,
|
||||
transparent_tcp: config.transparent_tcp,
|
||||
domains: config.domains.clone(),
|
||||
review_domains: config.review_domains.clone(),
|
||||
unix_sockets: config.unix_sockets.clone(),
|
||||
@@ -47,6 +51,7 @@ impl EnvironmentNetworkPolicy {
|
||||
|
||||
/// Applies attachment-owned traffic settings while preserving inherited denials and proxy setup.
|
||||
pub fn apply_to(&self, config: &mut NetworkProxyConfig) {
|
||||
config.transparent_tcp |= self.transparent_tcp;
|
||||
// Neither owner nor controller may remove the other's review selectors.
|
||||
for pattern in &self.review_domains {
|
||||
if !config
|
||||
|
||||
@@ -442,6 +442,7 @@ fn reserve_loopback_ephemeral_listener() -> Result<StdTcpListener> {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct NetworkProxyRuntimeSettings {
|
||||
transparent_tcp: bool,
|
||||
allow_local_binding: bool,
|
||||
allow_unix_sockets: Arc<[String]>,
|
||||
dangerously_allow_all_unix_sockets: bool,
|
||||
@@ -463,6 +464,7 @@ impl NetworkProxyRuntimeSettings {
|
||||
None
|
||||
};
|
||||
Ok(Self {
|
||||
transparent_tcp: config.transparent_tcp,
|
||||
allow_local_binding: config.allow_local_binding(),
|
||||
allow_unix_sockets: if cfg!(target_os = "windows") {
|
||||
Arc::default()
|
||||
@@ -486,6 +488,9 @@ struct EnvironmentProxyAddrs {
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ManagedNetworkSandboxContext {
|
||||
/// Route outbound TCP from managed Linux sandbox commands through the managed SOCKS5 proxy.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub transparent_tcp: bool,
|
||||
/// Loopback proxy ports that sandboxed commands may connect to.
|
||||
#[serde(default)]
|
||||
pub loopback_ports: Vec<u16>,
|
||||
@@ -1272,6 +1277,7 @@ impl NetworkProxy {
|
||||
env,
|
||||
sandbox_context: ManagedNetworkSandboxContext {
|
||||
loopback_ports,
|
||||
transparent_tcp: runtime_settings.transparent_tcp,
|
||||
allow_local_binding: runtime_settings.allow_local_binding,
|
||||
allow_unix_sockets: runtime_settings.allow_unix_sockets.to_vec(),
|
||||
dangerously_allow_all_unix_sockets: runtime_settings
|
||||
@@ -2383,6 +2389,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
prepared.sandbox_context,
|
||||
ManagedNetworkSandboxContext {
|
||||
transparent_tcp: false,
|
||||
loopback_ports: vec![43128, 48081],
|
||||
allow_local_binding: true,
|
||||
allow_unix_sockets: if cfg!(target_os = "windows") {
|
||||
|
||||
@@ -179,6 +179,9 @@ pub struct RemoteNetworkProxyConfig {
|
||||
)]
|
||||
credential_masking: CredentialMaskingConfig,
|
||||
pub enable_socks5: bool,
|
||||
/// Route outbound TCP from managed Linux sandbox commands through the managed SOCKS5 proxy.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub transparent_tcp: bool,
|
||||
pub enable_socks5_udp: bool,
|
||||
pub allow_upstream_proxy: bool,
|
||||
pub dangerously_allow_all_unix_sockets: bool,
|
||||
@@ -206,6 +209,7 @@ impl RemoteNetworkProxyConfig {
|
||||
enabled: config.enabled,
|
||||
credential_masking: CredentialMaskingConfig::default(),
|
||||
enable_socks5: config.enable_socks5,
|
||||
transparent_tcp: config.transparent_tcp,
|
||||
enable_socks5_udp: config.enable_socks5_udp,
|
||||
allow_upstream_proxy: config.allow_upstream_proxy,
|
||||
dangerously_allow_all_unix_sockets: config
|
||||
@@ -239,6 +243,7 @@ impl RemoteNetworkProxyConfig {
|
||||
let mut config = NetworkProxyConfig {
|
||||
enabled: self.enabled,
|
||||
enable_socks5: self.enable_socks5,
|
||||
transparent_tcp: self.transparent_tcp,
|
||||
enable_socks5_udp: self.enable_socks5_udp,
|
||||
allow_upstream_proxy: self.allow_upstream_proxy,
|
||||
dangerously_allow_all_unix_sockets: Some(self.dangerously_allow_all_unix_sockets),
|
||||
|
||||
@@ -78,6 +78,10 @@ pub fn build_config_state(
|
||||
if brokerage_created_default_allowlist {
|
||||
config.set_allowed_domains(vec!["*".to_string()]);
|
||||
}
|
||||
anyhow::ensure!(
|
||||
!config.transparent_tcp || (config.enabled && config.enable_socks5),
|
||||
"transparent_tcp requires an enabled managed SOCKS5 proxy"
|
||||
);
|
||||
crate::config::validate_unix_socket_allowlist_paths(&config, executor_os)?;
|
||||
anyhow::ensure!(
|
||||
!config.credential_broker || config.mitm,
|
||||
|
||||
Reference in New Issue
Block a user