mirror of
https://github.com/openai/codex.git
synced 2026-11-07 20:30:33 +00:00
Remove the legacy sandbox policy constructor (#59772)
## What changed Remove `FileSystemSandboxContext::from_legacy_sandbox_policy` and migrate its test callers to `from_permission_profile`. Construct read-only, disabled, and externally enforced sandbox contexts directly with `PermissionProfile`. GitOrigin-RevId: e330b89d060061eda106232eab554be5ccd06149
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
use super::*;
|
||||
use crate::discover_v2::capability_locations::tests::request;
|
||||
use crate::discover_v2::capability_locations::tests::write;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -69,10 +69,10 @@ async fn discovery_responses_are_cached_by_sandbox_context() -> anyhow::Result<(
|
||||
for index in 0..MAX_CACHED_SANDBOX_CONTEXTS {
|
||||
let sandbox_cwd = cwd.join(&format!("context-{index}"))?;
|
||||
let sandbox = DiscoverV2CapabilitiesRequest {
|
||||
sandbox: Some(FileSystemSandboxContext::from_legacy_sandbox_policy(
|
||||
SandboxPolicy::DangerFullAccess,
|
||||
sandbox: Some(FileSystemSandboxContext::from_permission_profile(
|
||||
PermissionProfile::Disabled,
|
||||
sandbox_cwd,
|
||||
)?),
|
||||
)),
|
||||
..params.clone()
|
||||
};
|
||||
let response = manager.get_or_refresh_discovery(sandbox.clone()).await?;
|
||||
|
||||
@@ -136,10 +136,10 @@ async fn watch_events_invalidate_discovery_and_no_subscription_disables_caching(
|
||||
.any(|skill| skill.path == demo_skill && skill.description == "ready")
|
||||
);
|
||||
let sandbox_params = DiscoverV2CapabilitiesRequest {
|
||||
sandbox: Some(crate::FileSystemSandboxContext::from_legacy_sandbox_policy(
|
||||
codex_protocol::protocol::SandboxPolicy::DangerFullAccess,
|
||||
sandbox: Some(crate::FileSystemSandboxContext::from_permission_profile(
|
||||
codex_protocol::models::PermissionProfile::Disabled,
|
||||
params.cwd.clone(),
|
||||
)?),
|
||||
)),
|
||||
..params.clone()
|
||||
};
|
||||
manager.get_or_refresh_discovery(sandbox_params).await?;
|
||||
|
||||
@@ -369,8 +369,8 @@ fn map_fs_error(err: io::Error) -> JSONRPCErrorError {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use codex_protocol::protocol::NetworkAccess;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -389,20 +389,16 @@ mod tests {
|
||||
.expect("runtime paths");
|
||||
let handler = FileSystemHandler::new(runtime_paths);
|
||||
let sandbox_cwd = PathUri::from_host_native_path(temp_dir.path()).expect("tempdir URI");
|
||||
let sandbox_context = |sandbox_policy| {
|
||||
FileSystemSandboxContext::from_legacy_sandbox_policy(
|
||||
sandbox_policy,
|
||||
sandbox_cwd.clone(),
|
||||
)
|
||||
.expect("sandbox context")
|
||||
let sandbox_context = |permissions| {
|
||||
FileSystemSandboxContext::from_permission_profile(permissions, sandbox_cwd.clone())
|
||||
};
|
||||
|
||||
for (file_name, sandbox_policy) in [
|
||||
("danger.txt", SandboxPolicy::DangerFullAccess),
|
||||
for (file_name, permission_profile) in [
|
||||
("danger.txt", PermissionProfile::Disabled),
|
||||
(
|
||||
"external.txt",
|
||||
SandboxPolicy::ExternalSandbox {
|
||||
network_access: NetworkAccess::Restricted,
|
||||
PermissionProfile::External {
|
||||
network: NetworkSandboxPolicy::Restricted,
|
||||
},
|
||||
),
|
||||
] {
|
||||
@@ -414,7 +410,7 @@ mod tests {
|
||||
path: path.clone(),
|
||||
follow_symlinks: None,
|
||||
data_base64: STANDARD.encode("ok"),
|
||||
sandbox: Some(sandbox_context(sandbox_policy.clone())),
|
||||
sandbox: Some(sandbox_context(permission_profile.clone())),
|
||||
})
|
||||
.await
|
||||
.expect("write file");
|
||||
@@ -422,7 +418,7 @@ mod tests {
|
||||
let canonicalized = handler
|
||||
.canonicalize(FsCanonicalizeParams {
|
||||
path: path.clone(),
|
||||
sandbox: Some(sandbox_context(sandbox_policy.clone())),
|
||||
sandbox: Some(sandbox_context(permission_profile.clone())),
|
||||
})
|
||||
.await
|
||||
.expect("canonicalize file");
|
||||
@@ -438,7 +434,7 @@ mod tests {
|
||||
.read_file(FsReadFileParams {
|
||||
path,
|
||||
follow_symlinks: None,
|
||||
sandbox: Some(sandbox_context(sandbox_policy)),
|
||||
sandbox: Some(sandbox_context(permission_profile)),
|
||||
})
|
||||
.await
|
||||
.expect("read file");
|
||||
|
||||
@@ -407,9 +407,10 @@ fn exported_sandbox_denial_keeps_launch_identity_and_separate_exit_outcome() {
|
||||
let private_file = directory.path().join(PRIVATE_PAYLOAD);
|
||||
std::fs::write(&private_file, PRIVATE_PAYLOAD).expect("write test file");
|
||||
let cwd = PathUri::from_host_native_path(directory.path()).expect("cwd URI");
|
||||
let sandbox = crate::FileSystemSandboxContext::from_legacy_sandbox_policy(
|
||||
codex_protocol::protocol::SandboxPolicy::new_read_only_policy(), cwd.clone(),
|
||||
).expect("read-only sandbox");
|
||||
let sandbox = crate::FileSystemSandboxContext::from_permission_profile(
|
||||
codex_protocol::models::PermissionProfile::read_only(),
|
||||
cwd.clone(),
|
||||
);
|
||||
for (index, span) in LAUNCH_SPANS.into_iter().enumerate() {
|
||||
let process_id = format!("{PRIVATE_PAYLOAD}-{index}");
|
||||
let launch = format!("00-{TRACE_ID}-{span}-00");
|
||||
|
||||
@@ -169,10 +169,10 @@ async fn v2_rpc_refreshes_metadata_and_enforces_sandbox() -> anyhow::Result<()>
|
||||
.contains("cannot enforce split filesystem read restrictions")),
|
||||
"{error:#}"
|
||||
);
|
||||
let mut sandbox = FileSystemSandboxContext::from_legacy_sandbox_policy(
|
||||
codex_protocol::protocol::SandboxPolicy::new_read_only_policy(),
|
||||
let mut sandbox = FileSystemSandboxContext::from_permission_profile(
|
||||
PermissionProfile::read_only(),
|
||||
cwd.clone(),
|
||||
)?;
|
||||
);
|
||||
sandbox.windows_sandbox_selection =
|
||||
codex_exec_server::WindowsSandboxSelection::RestrictedToken;
|
||||
let permitted = DiscoverV2CapabilitiesRequest {
|
||||
|
||||
@@ -59,7 +59,6 @@ use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::FileSystemSpecialPath;
|
||||
#[cfg(unix)]
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
@@ -1904,10 +1903,10 @@ async fn assert_remote_windows_sandbox_process_write(
|
||||
let workspace = TempDir::new()?;
|
||||
let blocked_file = workspace.path().join("blocked.txt");
|
||||
let cwd = PathUri::from_host_native_path(workspace.path())?;
|
||||
let mut sandbox = FileSystemSandboxContext::from_legacy_sandbox_policy(
|
||||
SandboxPolicy::new_read_only_policy(),
|
||||
let mut sandbox = FileSystemSandboxContext::from_permission_profile(
|
||||
codex_protocol::models::PermissionProfile::read_only(),
|
||||
cwd.clone(),
|
||||
)?;
|
||||
);
|
||||
match expected_sandbox_type {
|
||||
codex_sandboxing::SandboxType::WindowsRestrictedToken => {
|
||||
sandbox.windows_sandbox_selection = WindowsSandboxSelection::RestrictedToken;
|
||||
|
||||
@@ -30,7 +30,6 @@ use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::FileSystemSpecialPath;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_sandboxing::SandboxType;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use codex_windows_sandbox_test_support::WindowsSandboxAccountTestGuard;
|
||||
@@ -746,8 +745,8 @@ fn process_private_desktops() -> Result<BTreeSet<String>> {
|
||||
}
|
||||
|
||||
fn read_only_sandbox_for_cwd(cwd: std::path::PathBuf) -> Result<FileSystemSandboxContext> {
|
||||
Ok(FileSystemSandboxContext::from_legacy_sandbox_policy(
|
||||
SandboxPolicy::new_read_only_policy(),
|
||||
Ok(FileSystemSandboxContext::from_permission_profile(
|
||||
PermissionProfile::read_only(),
|
||||
PathUri::from_host_native_path(cwd)?,
|
||||
)?)
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user