mirror of
https://github.com/openai/codex.git
synced 2026-11-10 21:00:47 +00:00
Wire managed child MITM CA environments
This commit is contained in:
@@ -17,13 +17,15 @@ use codex_core::spawn::CODEX_SANDBOX_ENV_VAR;
|
||||
use codex_core::spawn::CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR;
|
||||
use codex_protocol::config_types::SandboxMode;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
#[cfg(target_os = "linux")]
|
||||
use codex_sandboxing::ensure_legacy_landlock_supports_managed_mitm;
|
||||
use codex_sandboxing::landlock::allow_network_for_proxy;
|
||||
use codex_sandboxing::landlock::create_linux_sandbox_command_args_for_permission_profile;
|
||||
use codex_sandboxing::prepare_managed_network_child;
|
||||
#[cfg(target_os = "macos")]
|
||||
use codex_sandboxing::seatbelt::CreateSeatbeltCommandArgsParams;
|
||||
#[cfg(target_os = "macos")]
|
||||
use codex_sandboxing::seatbelt::create_seatbelt_command_args;
|
||||
use codex_sandboxing::with_managed_mitm_ca_readable_root;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_cli::CliConfigOverrides;
|
||||
use tokio::process::Child;
|
||||
@@ -216,7 +218,7 @@ async fn run_command_under_sandbox(
|
||||
#[cfg(target_os = "windows")]
|
||||
let workspace_roots = config.effective_workspace_roots();
|
||||
|
||||
let env = create_env(
|
||||
let mut env = create_env(
|
||||
&config.permissions.shell_environment_policy,
|
||||
/*thread_id*/ None,
|
||||
);
|
||||
@@ -261,15 +263,36 @@ async fn run_command_under_sandbox(
|
||||
// Proxy containment depends on whether a proxy is active, not whether its
|
||||
// policy came from managed requirements.
|
||||
let enforce_managed_network = network.is_some();
|
||||
let managed_mitm_ca_trust_bundle_path = match network.as_ref() {
|
||||
Some(network) => network.managed_mitm_ca_trust_bundle_path(),
|
||||
None => None,
|
||||
};
|
||||
let runtime_permission_profile = with_managed_mitm_ca_readable_root(
|
||||
config.permissions.effective_permission_profile(),
|
||||
managed_mitm_ca_trust_bundle_path.as_ref(),
|
||||
#[expect(
|
||||
clippy::redundant_closure_for_method_calls,
|
||||
reason = "the concrete proxy type is not a direct dependency of codex-cli"
|
||||
)]
|
||||
let network_child_env = network.as_ref().map(|network| network.child_env_snapshot());
|
||||
let effective_permission_profile = config.permissions.effective_permission_profile();
|
||||
#[cfg(target_os = "linux")]
|
||||
if matches!(&sandbox_type, SandboxType::Landlock) {
|
||||
let file_system_sandbox_policy = effective_permission_profile.file_system_sandbox_policy();
|
||||
#[expect(
|
||||
clippy::redundant_closure_for_method_calls,
|
||||
reason = "the concrete snapshot type is not a direct dependency of codex-cli"
|
||||
)]
|
||||
let managed_mitm_ca_active = network_child_env
|
||||
.as_ref()
|
||||
.is_some_and(|snapshot| snapshot.has_managed_mitm_ca());
|
||||
ensure_legacy_landlock_supports_managed_mitm(
|
||||
&file_system_sandbox_policy,
|
||||
config.features.use_legacy_landlock(),
|
||||
managed_mitm_ca_active,
|
||||
)?;
|
||||
}
|
||||
let runtime_permission_profile = prepare_managed_network_child(
|
||||
network_child_env.as_ref(),
|
||||
&mut env,
|
||||
cwd.as_path(),
|
||||
effective_permission_profile,
|
||||
sandbox_policy_cwd.as_path(),
|
||||
);
|
||||
cfg!(target_os = "windows") && matches!(sandbox_type, SandboxType::Windows),
|
||||
)?;
|
||||
|
||||
let mut child = match sandbox_type {
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -294,9 +317,6 @@ async fn run_command_under_sandbox(
|
||||
env,
|
||||
|env_map| {
|
||||
env_map.insert(CODEX_SANDBOX_ENV_VAR.to_string(), "seatbelt".to_string());
|
||||
if let Some(network) = network.as_ref() {
|
||||
network.apply_to_env(env_map);
|
||||
}
|
||||
},
|
||||
)
|
||||
.await?
|
||||
@@ -323,11 +343,7 @@ async fn run_command_under_sandbox(
|
||||
cwd.to_path_buf(),
|
||||
network_sandbox_policy,
|
||||
env,
|
||||
|env_map| {
|
||||
if let Some(network) = network.as_ref() {
|
||||
network.apply_to_env(env_map);
|
||||
}
|
||||
},
|
||||
|_env_map| {},
|
||||
)
|
||||
.await?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user