Trust managed MITM CA in Linux sandboxes

This commit is contained in:
Winston Howes
2026-05-26 15:44:40 -07:00
parent e910c8c788
commit 595d035fbc
9 changed files with 194 additions and 31 deletions
+20
View File
@@ -27,6 +27,7 @@ pub fn create_linux_sandbox_command_args_for_permission_profile(
sandbox_policy_cwd: &Path,
use_legacy_landlock: bool,
allow_network_for_proxy: bool,
mitm_ca_trust_bundle_path: Option<&Path>,
) -> Vec<String> {
let permission_profile_json = serde_json::to_string(permission_profile)
.unwrap_or_else(|err| panic!("failed to serialize permission profile: {err}"));
@@ -53,6 +54,15 @@ pub fn create_linux_sandbox_command_args_for_permission_profile(
if allow_network_for_proxy {
linux_cmd.push("--allow-network-for-proxy".to_string());
}
if let Some(mitm_ca_trust_bundle_path) = mitm_ca_trust_bundle_path {
linux_cmd.push("--mitm-ca-trust-bundle".to_string());
linux_cmd.push(
mitm_ca_trust_bundle_path
.to_str()
.unwrap_or_else(|| panic!("MITM CA trust bundle path must be valid UTF-8"))
.to_string(),
);
}
linux_cmd.push("--".to_string());
linux_cmd.extend(command);
linux_cmd
@@ -67,6 +77,7 @@ fn create_linux_sandbox_command_args(
sandbox_policy_cwd: &Path,
use_legacy_landlock: bool,
allow_network_for_proxy: bool,
mitm_ca_trust_bundle_path: Option<&Path>,
) -> Vec<String> {
let command_cwd = command_cwd
.to_str()
@@ -89,6 +100,15 @@ fn create_linux_sandbox_command_args(
if allow_network_for_proxy {
linux_cmd.push("--allow-network-for-proxy".to_string());
}
if let Some(mitm_ca_trust_bundle_path) = mitm_ca_trust_bundle_path {
linux_cmd.push("--mitm-ca-trust-bundle".to_string());
linux_cmd.push(
mitm_ca_trust_bundle_path
.to_str()
.unwrap_or_else(|| panic!("MITM CA trust bundle path must be valid UTF-8"))
.to_string(),
);
}
// Separator so that command arguments starting with `-` are not parsed as
// options of the helper itself.
+25
View File
@@ -13,6 +13,7 @@ fn legacy_landlock_flag_is_included_when_requested() {
cwd,
/*use_legacy_landlock*/ false,
/*allow_network_for_proxy*/ false,
/*mitm_ca_trust_bundle_path*/ None,
);
assert_eq!(
default_bwrap.contains(&"--use-legacy-landlock".to_string()),
@@ -25,6 +26,7 @@ fn legacy_landlock_flag_is_included_when_requested() {
cwd,
/*use_legacy_landlock*/ true,
/*allow_network_for_proxy*/ false,
/*mitm_ca_trust_bundle_path*/ None,
);
assert_eq!(
legacy_landlock.contains(&"--use-legacy-landlock".to_string()),
@@ -44,6 +46,7 @@ fn proxy_flag_is_included_when_requested() {
cwd,
/*use_legacy_landlock*/ true,
/*allow_network_for_proxy*/ true,
/*mitm_ca_trust_bundle_path*/ None,
);
assert_eq!(
args.contains(&"--allow-network-for-proxy".to_string()),
@@ -65,6 +68,7 @@ fn permission_profile_flag_is_included() {
cwd,
/*use_legacy_landlock*/ true,
/*allow_network_for_proxy*/ false,
/*mitm_ca_trust_bundle_path*/ None,
);
assert_eq!(
@@ -79,6 +83,27 @@ fn permission_profile_flag_is_included() {
);
}
#[test]
fn mitm_ca_trust_bundle_flag_is_included_when_requested() {
let command = vec!["/bin/true".to_string()];
let command_cwd = Path::new("/tmp/link");
let cwd = Path::new("/tmp");
let trust_bundle_path = Path::new("/tmp/ca-bundle.pem");
let args = create_linux_sandbox_command_args(
command,
command_cwd,
cwd,
/*use_legacy_landlock*/ false,
/*allow_network_for_proxy*/ true,
Some(trust_bundle_path),
);
assert!(args.windows(2).any(|window| {
window[0] == "--mitm-ca-trust-bundle" && window[1] == "/tmp/ca-bundle.pem"
}));
}
#[test]
fn proxy_network_requires_managed_requirements() {
assert_eq!(
+3
View File
@@ -218,6 +218,8 @@ impl SandboxManager {
let exe = codex_linux_sandbox_exe
.ok_or(SandboxTransformError::MissingLinuxSandboxExecutable)?;
let allow_proxy_network = allow_network_for_proxy(enforce_managed_network);
let mitm_ca_trust_bundle_path =
network.and_then(NetworkProxy::mitm_ca_trust_bundle_path);
#[cfg(target_os = "linux")]
ensure_linux_bubblewrap_is_supported(
&effective_file_system_policy,
@@ -232,6 +234,7 @@ impl SandboxManager {
sandbox_policy_cwd,
use_legacy_landlock,
allow_proxy_network,
mitm_ca_trust_bundle_path.as_deref(),
);
let mut full_command = Vec::with_capacity(1 + args.len());
full_command.push(os_string_to_command_component(exe.as_os_str().to_owned()));