Centralize filesystem permission resolution for sandbox enforcement (#59009)

## What changed

- Add `resolve_for_enforcement` to collect filesystem grants, denials, glob patterns, and platform defaults with backend-specific path handling.
- Use the shared result in Linux bubblewrap and macOS Seatbelt policy generation, including Seatbelt scratch access and filesystem policy equivalence checks.
- Pass already-derived filesystem and network policies to Linux seccomp setup instead of converting the permission profile again.

## Testing

Extend the Seatbelt glob test to execute sandboxed commands and verify that relative deny patterns through a symlink block reads and writes while sibling files remain editable.

GitOrigin-RevId: 748603f6b5a6db739b198a0f93a899041612370a
This commit is contained in:
viyatb-oai
2026-11-02 23:19:47 +00:00
committed by copyberry
parent 26f73fba8f
commit d92aae5501
9 changed files with 359 additions and 252 deletions
+10 -7
View File
@@ -24,7 +24,7 @@ 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 crate::seccomp::apply_sandbox_policies_to_current_thread;
use codex_network_proxy::ManagedNetworkSandboxContext;
use codex_protocol::error::Result as CodexResult;
use codex_protocol::models::PermissionProfile;
@@ -202,8 +202,9 @@ pub fn run_main() -> ! {
}
}
let proxy_routing_active = allow_network_for_proxy;
if let Err(e) = apply_permission_profile_to_current_thread(
&permission_profile,
if let Err(e) = apply_sandbox_policies_to_current_thread(
&file_system_sandbox_policy,
network_sandbox_policy,
&sandbox_policy_cwd,
/*apply_landlock_fs*/ false,
managed_network.as_ref(),
@@ -248,8 +249,9 @@ pub fn run_main() -> ! {
}
if file_system_sandbox_policy.has_full_disk_write_access() && !allow_network_for_proxy {
if let Err(e) = apply_permission_profile_to_current_thread(
&permission_profile,
if let Err(e) = apply_sandbox_policies_to_current_thread(
&file_system_sandbox_policy,
network_sandbox_policy,
&sandbox_policy_cwd,
/*apply_landlock_fs*/ false,
managed_network.as_ref(),
@@ -316,8 +318,9 @@ pub fn run_main() -> ! {
}
// Legacy pipeline: apply in-process restrictions without bubblewrap.
if let Err(e) = apply_permission_profile_to_current_thread(
&permission_profile,
if let Err(e) = apply_sandbox_policies_to_current_thread(
&file_system_sandbox_policy,
network_sandbox_policy,
&sandbox_policy_cwd,
/*apply_landlock_fs*/ true,
managed_network.as_ref(),