mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve target-native paths in command approvals (#42577)
## What changed - Pass the selected executor's `PathUri` through user command approval requests instead of converting the working directory to a host-native path. - Make native-path permission helpers explicitly local and require executor-aware permission transforms to receive a `FileSystemSandboxPolicyContext`. - Cover approved remote commands to verify that the approval request reports the selected remote working directory and execution resumes after approval. GitOrigin-RevId: 0aa3042f2d7594af6c7d0abf31d7f99cf67d5556
This commit is contained in:
1 parent
0650d6d1ca
commit
7a7c188682
30 files changed
+304
-368
No files matched your search
@@ -1,7 +1,5 @@
|
||||
use super::effective_file_system_sandbox_policy;
|
||||
use super::intersect_permission_profiles;
|
||||
use super::intersect_permission_profiles_with_context;
|
||||
use super::materialize_additional_permissions;
|
||||
use super::materialize_additional_permissions_with_context;
|
||||
use super::merge_file_system_policy_with_additional_permissions;
|
||||
use super::normalize_additional_permissions;
|
||||
@@ -23,7 +21,6 @@ use codex_utils_path_uri::PathConvention;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use dunce::canonicalize;
|
||||
use pretty_assertions::assert_eq;
|
||||
#[cfg(unix)]
|
||||
use std::path::Path;
|
||||
use tempfile::TempDir;
|
||||
|
||||
@@ -32,6 +29,21 @@ fn symlink_dir(original: &Path, link: &Path) -> std::io::Result<()> {
|
||||
std::os::unix::fs::symlink(original, link)
|
||||
}
|
||||
|
||||
fn intersect_permission_profiles_with_local_cwd(
|
||||
requested: PermissionProfile,
|
||||
granted: PermissionProfile,
|
||||
cwd: &Path,
|
||||
) -> PermissionProfile {
|
||||
let cwd = PathUri::from_host_native_path(cwd).expect("cwd URI");
|
||||
let context = FileSystemSandboxPolicyContext {
|
||||
cwd: &cwd,
|
||||
workspace_roots: std::slice::from_ref(&cwd),
|
||||
user_home_dir: None,
|
||||
temporary_directories: None,
|
||||
};
|
||||
intersect_permission_profiles_with_context(requested, granted, &context)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_access_restricted_policy_skips_platform_sandbox_when_network_is_enabled() {
|
||||
let policy = FileSystemSandboxPolicy::restricted(vec![FileSystemSandboxEntry {
|
||||
@@ -303,6 +315,13 @@ fn materialize_additional_permissions_preserves_authority_and_constraints() {
|
||||
)
|
||||
.expect("absolute temp dir");
|
||||
let home = PathUri::from_host_native_path("~").expect("host home");
|
||||
let cwd_uri = PathUri::from(cwd.clone());
|
||||
let context = FileSystemSandboxPolicyContext {
|
||||
cwd: &cwd_uri,
|
||||
workspace_roots: std::slice::from_ref(&cwd_uri),
|
||||
user_home_dir: Some(&home),
|
||||
temporary_directories: None,
|
||||
};
|
||||
let project_path = |subpath: &str| FileSystemPath::Special {
|
||||
value: FileSystemSpecialPath::project_roots(Some(subpath.to_owned())),
|
||||
};
|
||||
@@ -342,7 +361,7 @@ fn materialize_additional_permissions_preserves_authority_and_constraints() {
|
||||
]);
|
||||
|
||||
assert_eq!(
|
||||
materialize_additional_permissions(requested, cwd.as_path())
|
||||
materialize_additional_permissions_with_context(requested, &context)
|
||||
.expect("materialized permissions"),
|
||||
expected
|
||||
);
|
||||
@@ -409,7 +428,7 @@ fn intersect_permission_profiles_preserves_explicit_empty_requested_reads() {
|
||||
let granted = requested.clone();
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested.clone(), granted, temp_dir.path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested.clone(), granted, temp_dir.path()),
|
||||
requested
|
||||
);
|
||||
}
|
||||
@@ -430,7 +449,11 @@ fn intersect_permission_profiles_drops_ungranted_nonempty_path_requests() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, PermissionProfile::default(), temp_dir.path()),
|
||||
intersect_permission_profiles_with_local_cwd(
|
||||
requested,
|
||||
PermissionProfile::default(),
|
||||
temp_dir.path()
|
||||
),
|
||||
PermissionProfile::default()
|
||||
);
|
||||
}
|
||||
@@ -451,7 +474,11 @@ fn intersect_permission_profiles_drops_explicit_empty_reads_without_grant() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, PermissionProfile::default(), temp_dir.path()),
|
||||
intersect_permission_profiles_with_local_cwd(
|
||||
requested,
|
||||
PermissionProfile::default(),
|
||||
temp_dir.path()
|
||||
),
|
||||
PermissionProfile::default()
|
||||
);
|
||||
}
|
||||
@@ -491,7 +518,7 @@ fn intersect_permission_profiles_preserves_parent_relative_project_root_restrict
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted, cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested, granted, cwd.as_path()),
|
||||
PermissionProfile::default()
|
||||
);
|
||||
}
|
||||
@@ -522,11 +549,11 @@ fn intersect_permission_profiles_rejects_symbolic_slash_tmp_grants() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted.clone(), cwd.path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested, granted.clone(), cwd.path()),
|
||||
PermissionProfile::default()
|
||||
);
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(granted.clone(), granted, cwd.path()),
|
||||
intersect_permission_profiles_with_local_cwd(granted.clone(), granted, cwd.path()),
|
||||
PermissionProfile::default()
|
||||
);
|
||||
}
|
||||
@@ -553,7 +580,7 @@ fn intersect_permission_profiles_preserves_deny_across_case_variant_grant() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(
|
||||
intersect_permission_profiles_with_local_cwd(
|
||||
profile(vec![requested_write, requested_deny.clone()]),
|
||||
profile(vec![granted_write.clone()]),
|
||||
requested_root.as_path(),
|
||||
@@ -698,7 +725,7 @@ fn intersect_permission_profiles_preserves_opaque_child_deny() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(
|
||||
intersect_permission_profiles_with_local_cwd(
|
||||
profile(vec![requested_write, requested_deny.clone()]),
|
||||
profile(vec![granted_write.clone()]),
|
||||
root.as_path(),
|
||||
@@ -737,7 +764,7 @@ fn intersect_permission_profiles_accepts_child_path_granted_for_requested_cwd()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted.clone(), cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested, granted.clone(), cwd.as_path()),
|
||||
granted
|
||||
);
|
||||
}
|
||||
@@ -763,7 +790,7 @@ fn intersect_permission_profiles_materializes_cwd_grant_for_reuse() {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let intersected = intersect_permission_profiles(
|
||||
let intersected = intersect_permission_profiles_with_local_cwd(
|
||||
cwd_write_permissions.clone(),
|
||||
cwd_write_permissions,
|
||||
request_cwd.as_path(),
|
||||
@@ -780,7 +807,7 @@ fn intersect_permission_profiles_materializes_cwd_grant_for_reuse() {
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(
|
||||
intersect_permission_profiles_with_local_cwd(
|
||||
PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions::from_read_write_roots(
|
||||
/*read*/ None,
|
||||
@@ -822,7 +849,11 @@ fn intersect_permission_profiles_deduplicates_materialized_grants() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(permissions.clone(), permissions, cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(
|
||||
permissions.clone(),
|
||||
permissions,
|
||||
cwd.as_path()
|
||||
),
|
||||
PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions::from_read_write_roots(
|
||||
/*read*/ None,
|
||||
@@ -862,7 +893,11 @@ fn intersect_permission_profiles_materializes_cwd_deny_entries() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(permissions.clone(), permissions, request_cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(
|
||||
permissions.clone(),
|
||||
permissions,
|
||||
request_cwd.as_path()
|
||||
),
|
||||
PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions {
|
||||
entries: vec![
|
||||
@@ -924,7 +959,7 @@ fn intersect_permission_profiles_drops_deny_entries_without_filesystem_grants()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted.clone(), cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested, granted.clone(), cwd.as_path()),
|
||||
granted
|
||||
);
|
||||
}
|
||||
@@ -968,7 +1003,7 @@ fn intersect_permission_profiles_rejects_concrete_grants_matched_by_requested_de
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted, cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested, granted, cwd.as_path()),
|
||||
PermissionProfile::default()
|
||||
);
|
||||
}
|
||||
@@ -1002,8 +1037,11 @@ fn intersect_permission_profiles_materializes_relative_deny_globs_for_reuse() {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let intersected =
|
||||
intersect_permission_profiles(permissions.clone(), permissions, request_cwd.as_path());
|
||||
let intersected = intersect_permission_profiles_with_local_cwd(
|
||||
permissions.clone(),
|
||||
permissions,
|
||||
request_cwd.as_path(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
intersected,
|
||||
@@ -1029,7 +1067,7 @@ fn intersect_permission_profiles_materializes_relative_deny_globs_for_reuse() {
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(
|
||||
intersect_permission_profiles_with_local_cwd(
|
||||
PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions::from_read_write_roots(
|
||||
/*read*/ None,
|
||||
@@ -1074,7 +1112,7 @@ fn intersect_permission_profiles_drops_broader_cwd_grant_for_requested_child_pat
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted, cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested, granted, cwd.as_path()),
|
||||
PermissionProfile::default()
|
||||
);
|
||||
}
|
||||
@@ -1112,7 +1150,7 @@ fn intersect_permission_profiles_uses_granted_bounded_glob_scan_depth() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted, cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested, granted, cwd.as_path()),
|
||||
PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions {
|
||||
entries: vec![
|
||||
@@ -1170,7 +1208,7 @@ fn intersect_permission_profiles_uses_granted_unbounded_glob_scan_depth() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
intersect_permission_profiles(requested, granted, cwd.as_path()),
|
||||
intersect_permission_profiles_with_local_cwd(requested, granted, cwd.as_path()),
|
||||
PermissionProfile {
|
||||
file_system: Some(FileSystemPermissions {
|
||||
entries: vec![
|
||||
|
||||
Reference in new issue
Block a user