From 7f32e20da8bac8ae09da71f93148d3e68ce8d5a7 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Thu, 30 Apr 2026 05:12:40 -0700 Subject: [PATCH] windows read grants: accept permission profiles --- codex-rs/core/src/windows_sandbox_read_grants.rs | 14 +++++++++++--- .../core/src/windows_sandbox_read_grants_tests.rs | 12 ++++++------ codex-rs/tui/src/app/event_dispatch.rs | 7 ++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/codex-rs/core/src/windows_sandbox_read_grants.rs b/codex-rs/core/src/windows_sandbox_read_grants.rs index b0891ec6a6..00cb3cec99 100644 --- a/codex-rs/core/src/windows_sandbox_read_grants.rs +++ b/codex-rs/core/src/windows_sandbox_read_grants.rs @@ -1,12 +1,13 @@ use crate::windows_sandbox::run_setup_refresh_with_extra_read_roots; use anyhow::Result; -use codex_protocol::protocol::SandboxPolicy; +use codex_protocol::models::PermissionProfile; +use codex_sandboxing::compatibility_sandbox_policy_for_permission_profile; use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; pub fn grant_read_root_non_elevated( - policy: &SandboxPolicy, + permission_profile: &PermissionProfile, policy_cwd: &Path, command_cwd: &Path, env_map: &HashMap, @@ -24,8 +25,15 @@ pub fn grant_read_root_non_elevated( } let canonical_root = dunce::canonicalize(read_root)?; + let file_system_sandbox_policy = permission_profile.file_system_sandbox_policy(); + let policy = compatibility_sandbox_policy_for_permission_profile( + permission_profile, + &file_system_sandbox_policy, + permission_profile.network_sandbox_policy(), + policy_cwd, + ); run_setup_refresh_with_extra_read_roots( - policy, + &policy, policy_cwd, command_cwd, env_map, diff --git a/codex-rs/core/src/windows_sandbox_read_grants_tests.rs b/codex-rs/core/src/windows_sandbox_read_grants_tests.rs index bffa840ede..93cbcddfe3 100644 --- a/codex-rs/core/src/windows_sandbox_read_grants_tests.rs +++ b/codex-rs/core/src/windows_sandbox_read_grants_tests.rs @@ -1,18 +1,18 @@ use super::grant_read_root_non_elevated; -use codex_protocol::protocol::SandboxPolicy; +use codex_protocol::models::PermissionProfile; use std::collections::HashMap; use std::path::Path; use tempfile::TempDir; -fn policy() -> SandboxPolicy { - SandboxPolicy::new_workspace_write_policy() +fn permission_profile() -> PermissionProfile { + PermissionProfile::workspace_write() } #[test] fn rejects_relative_path() { let tmp = TempDir::new().expect("tempdir"); let err = grant_read_root_non_elevated( - &policy(), + &permission_profile(), tmp.path(), tmp.path(), &HashMap::new(), @@ -28,7 +28,7 @@ fn rejects_missing_path() { let tmp = TempDir::new().expect("tempdir"); let missing = tmp.path().join("does-not-exist"); let err = grant_read_root_non_elevated( - &policy(), + &permission_profile(), tmp.path(), tmp.path(), &HashMap::new(), @@ -45,7 +45,7 @@ fn rejects_file_path() { let file_path = tmp.path().join("file.txt"); std::fs::write(&file_path, "hello").expect("write file"); let err = grant_read_root_non_elevated( - &policy(), + &permission_profile(), tmp.path(), tmp.path(), &HashMap::new(), diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rs index 62cb727159..545c9bd6d8 100644 --- a/codex-rs/tui/src/app/event_dispatch.rs +++ b/codex-rs/tui/src/app/event_dispatch.rs @@ -883,10 +883,7 @@ impl App { /*hint*/ None, )); - let policy = self - .config - .permissions - .legacy_sandbox_policy(self.config.cwd.as_path()); + let permission_profile = self.config.permissions.permission_profile(); let policy_cwd = self.config.cwd.clone(); let command_cwd = self.config.cwd.clone(); let env_map: std::collections::HashMap = @@ -897,7 +894,7 @@ impl App { tokio::task::spawn_blocking(move || { let requested_path = PathBuf::from(path); let event = match crate::legacy_core::grant_read_root_non_elevated( - &policy, + &permission_profile, policy_cwd.as_path(), command_cwd.as_path(), &env_map,