mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Align Linux sandbox names and docs with bubblewrap and seccomp (#52610)
## Why The Linux sandbox uses bubblewrap for filesystem isolation and seccomp for syscall filtering, but its command type, syscall-filter module, and integration test suite still used Landlock names. ## What changed - Rename `LandlockCommand` to `LinuxSandboxCommand`, `src/landlock.rs` to `src/seccomp.rs`, and `tests/suite/landlock.rs` to `tests/suite/sandbox.rs`, updating imports and existing tests. - Clarify the retained legacy Landlock implementation and its filesystem-policy limitations. - Update the README to describe existing network filtering, `AF_VSOCK` and `io_uring` restrictions, and managed-proxy Unix socket behavior, including allowed Unix socket pairs. Sandbox enforcement behavior is unchanged. GitOrigin-RevId: be4769d5a10b90605990eb58451e83fdf1c31222
This commit is contained in:
@@ -7,6 +7,12 @@ This crate is responsible for producing:
|
||||
- the `codex-exec` CLI can check if its arg0 is `codex-linux-sandbox` and, if so, execute as if it were `codex-linux-sandbox`
|
||||
- this should also be true of the `codex` multitool CLI
|
||||
|
||||
The helper uses bubblewrap for filesystem and namespace isolation, and seccomp
|
||||
for syscall filtering. `src/seccomp.rs` installs `PR_SET_NO_NEW_PRIVS` and the
|
||||
seccomp filters; it also retains the legacy Landlock filesystem implementation.
|
||||
`src/linux_run_main.rs` coordinates these stages through `LinuxSandboxCommand`.
|
||||
End-to-end coverage lives in `tests/suite/sandbox.rs` and the other suite modules.
|
||||
|
||||
On Linux, Codex prefers the first `bwrap` found on `PATH`
|
||||
outside the current working directory whenever it is available. If `bwrap` is
|
||||
present but too old to support
|
||||
@@ -45,7 +51,10 @@ commands that would enter the bubblewrap path.
|
||||
`SandboxPolicy` model stay on bubblewrap so nested read-only or denied
|
||||
carveouts are preserved.
|
||||
- When bubblewrap is active, the helper applies `PR_SET_NO_NEW_PRIVS` and a
|
||||
seccomp network filter in-process.
|
||||
seccomp filter in-process after establishing the filesystem view. Restricted
|
||||
network policies block network syscalls; filesystem-restricted policies with
|
||||
otherwise unrestricted networking still block `AF_VSOCK` sockets. All filter
|
||||
modes block `io_uring` to prevent bypassing socket-family restrictions.
|
||||
- When bubblewrap is active, the filesystem is read-only by default via `--ro-bind / /`.
|
||||
- When bubblewrap is active, writable roots are layered with `--bind <root> <root>`.
|
||||
- When bubblewrap is active, protected subpaths under writable roots (for
|
||||
@@ -86,8 +95,10 @@ commands that would enter the bubblewrap path.
|
||||
- In managed proxy mode, the helper uses `--unshare-net` plus an internal
|
||||
TCP->UDS->TCP routing bridge so tool traffic reaches only configured proxy
|
||||
endpoints.
|
||||
- In managed proxy mode, after the bridge is live, seccomp blocks new
|
||||
AF_UNIX/socketpair creation for the user command.
|
||||
- In managed proxy mode, after the bridge is live, seccomp allows IP sockets
|
||||
inside the isolated network namespace and blocks new standalone `AF_UNIX`
|
||||
sockets unless `dangerously_allow_all_unix_sockets` is granted. Unix socket
|
||||
pairs remain allowed for communication between related processes.
|
||||
- When bubblewrap is active, it mounts a fresh `/proc` via `--proc /proc` by default.
|
||||
If that mount is denied, it retains the inherited `/proc` and still creates a
|
||||
PID namespace, preserving the existing fallback. `--no-proc` also retains the
|
||||
|
||||
@@ -16,8 +16,6 @@ mod exec_util;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod fd_mount;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod landlock;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod launcher;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod linux_run_main;
|
||||
@@ -26,6 +24,8 @@ mod proxy_lifecycle;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod proxy_routing;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod seccomp;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod wslg;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
||||
@@ -25,12 +25,12 @@ use crate::bwrap::BwrapOptions;
|
||||
use crate::bwrap::WSL_INTEROP_DIR;
|
||||
use crate::bwrap::WSLG_DISTRO_ROOT;
|
||||
use crate::bwrap::create_bwrap_command_args;
|
||||
use crate::landlock::apply_permission_profile_to_current_thread;
|
||||
use crate::launcher::exec_bwrap;
|
||||
use crate::launcher::initialize_bwrap_launcher;
|
||||
use crate::launcher::preferred_bwrap_supports_argv0;
|
||||
use crate::proxy_routing::activate_proxy_routes_in_netns;
|
||||
use crate::proxy_routing::prepare_host_proxy_route_spec;
|
||||
use crate::seccomp::apply_permission_profile_to_current_thread;
|
||||
use codex_network_proxy::ManagedNetworkSandboxContext;
|
||||
use codex_protocol::error::Result as CodexResult;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
@@ -86,10 +86,8 @@ enum ProtectedCreateRemoval {
|
||||
#[derive(Debug, Parser)]
|
||||
/// CLI surface for the Linux sandbox helper.
|
||||
///
|
||||
/// The type name remains `LandlockCommand` for compatibility with existing
|
||||
/// wiring, but bubblewrap is now the default filesystem sandbox and Landlock
|
||||
/// is the legacy fallback.
|
||||
pub struct LandlockCommand {
|
||||
/// Uses bubblewrap for filesystem isolation and seccomp for syscall filtering.
|
||||
pub struct LinuxSandboxCommand {
|
||||
/// It is possible that the cwd used in the context of the sandbox policy
|
||||
/// is different from the cwd of the process to spawn.
|
||||
#[arg(long = "sandbox-policy-cwd")]
|
||||
@@ -166,7 +164,7 @@ pub struct LandlockCommand {
|
||||
/// 2. Apply in-process restrictions (no_new_privs + seccomp).
|
||||
/// 3. `execvp` into the final command.
|
||||
pub fn run_main() -> ! {
|
||||
let LandlockCommand {
|
||||
let LinuxSandboxCommand {
|
||||
sandbox_policy_cwd,
|
||||
command_cwd,
|
||||
permission_profile,
|
||||
@@ -178,7 +176,7 @@ pub fn run_main() -> ! {
|
||||
no_proc,
|
||||
inherit_pid_namespace,
|
||||
command,
|
||||
} = LandlockCommand::parse();
|
||||
} = LinuxSandboxCommand::parse();
|
||||
let allow_network_for_proxy = managed_network.is_some();
|
||||
|
||||
if command.is_empty() {
|
||||
@@ -348,7 +346,7 @@ pub fn run_main() -> ! {
|
||||
);
|
||||
}
|
||||
|
||||
// Legacy path: Landlock enforcement only, when bwrap sandboxing is not enabled.
|
||||
// Legacy pipeline: apply in-process restrictions without bubblewrap.
|
||||
if let Err(e) = apply_permission_profile_to_current_thread(
|
||||
&permission_profile,
|
||||
&sandbox_policy_cwd,
|
||||
|
||||
@@ -587,7 +587,7 @@ fn managed_proxy_inner_command_includes_route_spec() {
|
||||
|
||||
assert!(args.iter().any(|arg| arg == "--proxy-route-spec"));
|
||||
assert!(args.iter().any(|arg| arg == "{\"routes\":[]}"));
|
||||
let parsed = LandlockCommand::try_parse_from(args)
|
||||
let parsed = LinuxSandboxCommand::try_parse_from(args)
|
||||
.expect("inner command should preserve the managed network policy");
|
||||
assert_eq!(parsed.managed_network, Some(managed_network));
|
||||
}
|
||||
@@ -595,7 +595,7 @@ fn managed_proxy_inner_command_includes_route_spec() {
|
||||
|
||||
#[test]
|
||||
fn managed_network_policy_alone_enables_proxy_mode() {
|
||||
let parsed = LandlockCommand::try_parse_from([
|
||||
let parsed = LinuxSandboxCommand::try_parse_from([
|
||||
"codex-linux-sandbox",
|
||||
"--sandbox-policy-cwd",
|
||||
"/tmp",
|
||||
@@ -613,7 +613,7 @@ fn managed_network_policy_alone_enables_proxy_mode() {
|
||||
|
||||
#[test]
|
||||
fn malformed_managed_network_policy_is_rejected() {
|
||||
let error = LandlockCommand::try_parse_from([
|
||||
let error = LinuxSandboxCommand::try_parse_from([
|
||||
"codex-linux-sandbox",
|
||||
"--sandbox-policy-cwd",
|
||||
"/tmp",
|
||||
@@ -658,7 +658,7 @@ fn non_managed_inner_command_omits_route_spec() {
|
||||
});
|
||||
|
||||
assert!(!args.iter().any(|arg| arg == "--proxy-route-spec"));
|
||||
let parsed = LandlockCommand::try_parse_from(args)
|
||||
let parsed = LinuxSandboxCommand::try_parse_from(args)
|
||||
.expect("unmanaged inner command should preserve ordinary sandbox mode");
|
||||
assert_eq!(parsed.managed_network, None);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! In-process Linux sandbox primitives: `no_new_privs` and seccomp.
|
||||
//!
|
||||
//! Filesystem restrictions are enforced by bubblewrap in `linux_run_main`.
|
||||
//! Landlock helpers remain available here as legacy/backup utilities.
|
||||
//! The legacy Landlock filesystem implementation is retained here, but the
|
||||
//! helper rejects legacy mode for filesystem-restricted policies.
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -39,7 +40,8 @@ use seccompiler::apply_filter;
|
||||
/// - enabling `PR_SET_NO_NEW_PRIVS` when restrictions apply, and
|
||||
/// - installing seccomp restrictions for network isolation and VM sockets.
|
||||
///
|
||||
/// Filesystem restrictions are intentionally handled by bubblewrap.
|
||||
/// Filesystem restrictions are normally handled by bubblewrap. The legacy
|
||||
/// Landlock implementation is only selected by `apply_landlock_fs`.
|
||||
pub(crate) fn apply_permission_profile_to_current_thread(
|
||||
permission_profile: &PermissionProfile,
|
||||
cwd: &Path,
|
||||
@@ -142,8 +144,8 @@ fn set_no_new_privs() -> Result<()> {
|
||||
/// # Errors
|
||||
/// Returns [`CodexErr::Sandbox`] variants when the ruleset fails to apply.
|
||||
///
|
||||
/// Note: this is currently unused because filesystem sandboxing is performed
|
||||
/// via bubblewrap. It is kept for reference and potential fallback use.
|
||||
/// Retained for the legacy pipeline. The helper currently rejects legacy mode
|
||||
/// for filesystem-restricted policies, so filesystem sandboxing uses bubblewrap.
|
||||
fn install_filesystem_landlock_rules_on_current_thread(
|
||||
writable_roots: Vec<AbsolutePathBuf>,
|
||||
) -> Result<()> {
|
||||
@@ -1,5 +1,5 @@
|
||||
// Aggregates all former standalone integration tests as modules.
|
||||
mod bundled_bwrap;
|
||||
mod bwrap_path;
|
||||
mod landlock;
|
||||
mod managed_proxy;
|
||||
mod sandbox;
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
//! End-to-end Linux sandbox coverage for filesystem isolation and syscall filtering.
|
||||
|
||||
#![cfg(target_os = "linux")]
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use codex_core::exec::ExecCapturePolicy;
|
||||
Reference in New Issue
Block a user