windows read grants: accept permission profiles

This commit is contained in:
Michael Bolin
2026-04-30 05:12:40 -07:00
parent a13a59a565
commit 7f32e20da8
3 changed files with 19 additions and 14 deletions

View File

@@ -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<String, String>,
@@ -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,

View File

@@ -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(),

View File

@@ -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<String, String> =
@@ -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,