mirror of
https://github.com/openai/codex.git
synced 2026-11-27 15:30:27 +00:00
Use permission profiles throughout sandbox execution (#36183)
## What changed - Pass the canonical `PermissionProfile` through execution requests, sandbox selection, escalation, and the exec server instead of carrying separate derived filesystem and network policies. - Derive runtime sandbox policies from the effective profile at their points of use, including after applying additional permissions. - Update sandbox and escalation tests to inspect policies through the profile. GitOrigin-RevId: 695b82ea94f5289516b0933bb23074cb2dcce8ac
This commit is contained in:
1 parent
ceb4bc72c4
commit
0dcad0c972
15 files changed
+74
-166
No files matched your search
@@ -120,8 +120,6 @@ pub struct SandboxExecRequest {
|
||||
pub windows_sandbox_level: WindowsSandboxLevel,
|
||||
pub windows_sandbox_private_desktop: bool,
|
||||
pub permission_profile: PermissionProfile,
|
||||
pub file_system_sandbox_policy: FileSystemSandboxPolicy,
|
||||
pub network_sandbox_policy: NetworkSandboxPolicy,
|
||||
pub arg0: Option<String>,
|
||||
}
|
||||
|
||||
@@ -160,8 +158,6 @@ struct PendingSandboxedExecRequest {
|
||||
native_command_cwd: AbsolutePathBuf,
|
||||
native_sandbox_policy_cwd: AbsolutePathBuf,
|
||||
effective_permission_profile: PermissionProfile,
|
||||
effective_file_system_policy: FileSystemSandboxPolicy,
|
||||
effective_network_policy: NetworkSandboxPolicy,
|
||||
}
|
||||
|
||||
impl PendingSandboxedExecRequest {
|
||||
@@ -189,14 +185,10 @@ impl PendingSandboxedExecRequest {
|
||||
managed_mitm_ca_trust_bundle_path,
|
||||
native_sandbox_policy_cwd.as_path(),
|
||||
);
|
||||
let (effective_file_system_policy, effective_network_policy) =
|
||||
effective_permission_profile.to_runtime_permissions();
|
||||
Ok(Self {
|
||||
native_command_cwd,
|
||||
native_sandbox_policy_cwd,
|
||||
effective_permission_profile,
|
||||
effective_file_system_policy,
|
||||
effective_network_policy,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -279,18 +271,12 @@ impl SandboxManager {
|
||||
|
||||
pub fn select_initial(
|
||||
&self,
|
||||
file_system_policy: &FileSystemSandboxPolicy,
|
||||
network_policy: NetworkSandboxPolicy,
|
||||
permission_profile: &PermissionProfile,
|
||||
pref: SandboxablePreference,
|
||||
windows_sandbox_level: WindowsSandboxLevel,
|
||||
has_managed_network_requirements: bool,
|
||||
) -> SandboxType {
|
||||
if self.should_sandbox(
|
||||
file_system_policy,
|
||||
network_policy,
|
||||
pref,
|
||||
has_managed_network_requirements,
|
||||
) {
|
||||
if self.should_sandbox(permission_profile, pref, has_managed_network_requirements) {
|
||||
get_platform_sandbox(windows_sandbox_level != WindowsSandboxLevel::Disabled)
|
||||
.unwrap_or(SandboxType::None)
|
||||
} else {
|
||||
@@ -302,19 +288,22 @@ impl SandboxManager {
|
||||
/// this host can provide a concrete sandbox implementation.
|
||||
pub fn should_sandbox(
|
||||
&self,
|
||||
file_system_policy: &FileSystemSandboxPolicy,
|
||||
network_policy: NetworkSandboxPolicy,
|
||||
permission_profile: &PermissionProfile,
|
||||
pref: SandboxablePreference,
|
||||
has_managed_network_requirements: bool,
|
||||
) -> bool {
|
||||
match pref {
|
||||
SandboxablePreference::Forbid => false,
|
||||
SandboxablePreference::Require => true,
|
||||
SandboxablePreference::Auto => should_require_platform_sandbox(
|
||||
file_system_policy,
|
||||
network_policy,
|
||||
has_managed_network_requirements,
|
||||
),
|
||||
SandboxablePreference::Auto => {
|
||||
let (file_system_policy, network_policy) =
|
||||
permission_profile.to_runtime_permissions();
|
||||
should_require_platform_sandbox(
|
||||
&file_system_policy,
|
||||
network_policy,
|
||||
has_managed_network_requirements,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,8 +337,6 @@ impl SandboxManager {
|
||||
base_effective_permission_profile.clone(),
|
||||
managed_mitm_ca_trust_bundle_path.as_ref(),
|
||||
);
|
||||
let (base_file_system_policy, base_network_policy) =
|
||||
base_effective_permission_profile.to_runtime_permissions();
|
||||
let mut argv = Vec::with_capacity(1 + command.args.len());
|
||||
argv.push(command.program);
|
||||
argv.extend(command.args.into_iter().map(OsString::from));
|
||||
@@ -363,10 +350,13 @@ impl SandboxManager {
|
||||
use crate::seatbelt::create_seatbelt_command_args;
|
||||
|
||||
let pending = pending_sandboxed_request?;
|
||||
let (file_system_sandbox_policy, network_sandbox_policy) = pending
|
||||
.effective_permission_profile
|
||||
.to_runtime_permissions();
|
||||
let mut args = create_seatbelt_command_args(CreateSeatbeltCommandArgsParams {
|
||||
command: os_argv_to_strings(argv),
|
||||
file_system_sandbox_policy: &pending.effective_file_system_policy,
|
||||
network_sandbox_policy: pending.effective_network_policy,
|
||||
file_system_sandbox_policy: &file_system_sandbox_policy,
|
||||
network_sandbox_policy,
|
||||
sandbox_policy_cwd: pending.native_sandbox_policy_cwd.as_path(),
|
||||
enforce_managed_network,
|
||||
managed_network,
|
||||
@@ -389,7 +379,9 @@ impl SandboxManager {
|
||||
let allow_proxy_network = allow_network_for_proxy(enforce_managed_network);
|
||||
#[cfg(target_os = "linux")]
|
||||
ensure_linux_bubblewrap_is_supported(
|
||||
&pending.effective_file_system_policy,
|
||||
&pending
|
||||
.effective_permission_profile
|
||||
.file_system_sandbox_policy(),
|
||||
use_legacy_landlock,
|
||||
allow_proxy_network,
|
||||
is_wsl1(),
|
||||
@@ -427,22 +419,11 @@ impl SandboxManager {
|
||||
|
||||
// Unsandboxed exec-server requests may have foreign cwd values that cannot be prepared
|
||||
// locally, but their effective permissions must still be preserved. In that case, carry
|
||||
// forward the base profile and its derived runtime policies.
|
||||
let (permission_profile, file_system_sandbox_policy, network_sandbox_policy) =
|
||||
pending_sandboxed_request.map_or(
|
||||
(
|
||||
base_effective_permission_profile,
|
||||
base_file_system_policy,
|
||||
base_network_policy,
|
||||
),
|
||||
|pending| {
|
||||
(
|
||||
pending.effective_permission_profile,
|
||||
pending.effective_file_system_policy,
|
||||
pending.effective_network_policy,
|
||||
)
|
||||
},
|
||||
);
|
||||
// forward the base profile.
|
||||
let permission_profile = pending_sandboxed_request
|
||||
.map_or(base_effective_permission_profile, |pending| {
|
||||
pending.effective_permission_profile
|
||||
});
|
||||
|
||||
Ok(SandboxExecRequest {
|
||||
command: argv,
|
||||
@@ -455,8 +436,6 @@ impl SandboxManager {
|
||||
windows_sandbox_level,
|
||||
windows_sandbox_private_desktop,
|
||||
permission_profile,
|
||||
file_system_sandbox_policy,
|
||||
network_sandbox_policy,
|
||||
arg0: arg0_override,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user