mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Preserve filesystem denials when preparing approved commands (#48155)
## Why Approved commands need broader write access while retaining explicit read denials. On Linux, binding the filesystem root writable can shadow standard devices, and additional root-metadata mounts can reopen denied symlink targets. ## What changed - Add `FileSystemSandboxPolicy::for_approved_command` to grant root and root-metadata writes while retaining path and glob denials. Keep the original policy when denials cannot be resolved or deny the root. - Restore standard devices after Linux writable root binds, then apply explicit deny masks. Avoid redundant root-alias binds and inherit root-metadata writes from the root mount so denied targets stay masked. - Preserve literal deny paths alongside resolved targets so Linux can reject denials that cross writable symlinks. - Advertise Linux device and approved-root restriction support through two opt-in exec-server capabilities, omitted from serialization when false. ## Testing Add regression coverage for approval policy materialization across Unix, Windows drive, and UNC paths; Windows volume expansion; Linux device access and metadata symlink restrictions; and capability serialization compatibility. GitOrigin-RevId: 40584473da98a15e606bb1a8934308f69528850f
This commit is contained in:
@@ -160,6 +160,12 @@ pub struct EnvironmentCapabilities {
|
||||
/// Whether requests may explicitly select the MXC Windows sandbox backend.
|
||||
#[serde(default)]
|
||||
pub windows_mxc: bool,
|
||||
/// Whether a Linux filesystem sandbox preserves standard devices when `/` is writable.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub linux_root_write_preserves_devices: bool,
|
||||
/// Whether approved Linux root writes preserve devices and denied root-metadata symlink targets.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub linux_approved_root_write_preserves_restrictions: bool,
|
||||
}
|
||||
|
||||
/// Status returned by an initialized exec-server connection.
|
||||
@@ -257,6 +263,8 @@ impl EnvironmentInfo {
|
||||
sandboxed_file_streaming: true,
|
||||
shell_snapshot_v2: cfg!(unix),
|
||||
windows_mxc,
|
||||
linux_root_write_preserves_devices: cfg!(target_os = "linux"),
|
||||
linux_approved_root_write_preserves_restrictions: cfg!(target_os = "linux"),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1390,10 +1398,46 @@ mod tests {
|
||||
sandboxed_file_streaming: false,
|
||||
shell_snapshot_v2: false,
|
||||
windows_mxc: false,
|
||||
linux_root_write_preserves_devices: false,
|
||||
linux_approved_root_write_preserves_restrictions: false,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linux_approved_root_write_support_is_opt_in_on_the_wire() {
|
||||
let mut capabilities = EnvironmentCapabilities::default();
|
||||
let legacy = serde_json::to_value(&capabilities).unwrap();
|
||||
assert!(legacy.get("linuxRootWritePreservesDevices").is_none());
|
||||
assert!(
|
||||
legacy
|
||||
.get("linuxApprovedRootWritePreservesRestrictions")
|
||||
.is_none()
|
||||
);
|
||||
capabilities.linux_root_write_preserves_devices = true;
|
||||
let device_only = serde_json::from_value::<EnvironmentCapabilities>(
|
||||
serde_json::to_value(&capabilities).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!device_only.linux_approved_root_write_preserves_restrictions);
|
||||
capabilities.linux_approved_root_write_preserves_restrictions = true;
|
||||
assert_eq!(
|
||||
serde_json::from_value::<EnvironmentCapabilities>(
|
||||
serde_json::to_value(&capabilities).unwrap()
|
||||
)
|
||||
.unwrap(),
|
||||
capabilities
|
||||
);
|
||||
let local = EnvironmentInfo::local().capabilities;
|
||||
assert_eq!(
|
||||
(
|
||||
local.linux_root_write_preserves_devices,
|
||||
local.linux_approved_root_write_preserves_restrictions,
|
||||
),
|
||||
(cfg!(target_os = "linux"), cfg!(target_os = "linux"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn environment_info_preserves_executor_metadata() {
|
||||
let expected = serde_json::json!({
|
||||
|
||||
Reference in New Issue
Block a user