mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Select process sandboxes during launch preparation (#62183)
## Why Workspace-relative permission rules need to resolve against the execution host's workspace roots so a grant applies to the intended directory. Restricted launches also need to check that the host can provide the required sandbox. ## What changed - Select the platform sandbox while preparing a launch, using the permission profile, network requirements, and Windows sandbox settings. - Pass workspace roots into policy resolution for local commands and shell snapshots. Already-bound command profiles validate their concrete paths without resolving Windows launcher hints on hosts that do not use them. - Share local launch preparation between tool commands and shell snapshots, and require a platform sandbox for exec-server launches that request one. ## Testing Cover network-only restrictions and verify that a `:workspace_roots` write grant allows writes to the configured subdirectory under the command's working directory while denying writes to a sibling file and the corresponding subdirectory under the parent. Exercise the path grant through both app-server command execution and WebSocket exec-server execution. GitOrigin-RevId: 492fe7ab8deddf30cfd2e2bdabf28d02d67e00c5
This commit is contained in:
@@ -22,6 +22,7 @@ use crate::permissions::FileSystemSpecialPath;
|
||||
use crate::permissions::LegacySandboxPolicyProjection;
|
||||
use crate::permissions::NetworkSandboxPolicy;
|
||||
use crate::permissions::RawFileSystemSandboxEntry;
|
||||
use crate::permissions::has_workspace_root_rules;
|
||||
use crate::protocol::SandboxPolicy;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_image::ImageProcessingError;
|
||||
@@ -700,6 +701,17 @@ impl PermissionProfile {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether this profile has filesystem rules relative to the execution host's workspace roots.
|
||||
pub fn has_workspace_root_rules(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::Managed {
|
||||
file_system: ManagedFileSystemPermissions::Restricted { entries, .. },
|
||||
..
|
||||
} if has_workspace_root_rules(entries)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn network_sandbox_policy(&self) -> NetworkSandboxPolicy {
|
||||
match self {
|
||||
Self::Managed { network, .. } | Self::External { network } => *network,
|
||||
|
||||
@@ -595,6 +595,18 @@ pub fn project_roots_glob_pattern(subpath: &Path) -> String {
|
||||
format!("{PROJECT_ROOTS_GLOB_PATTERN_PREFIX}{}", subpath.display())
|
||||
}
|
||||
|
||||
pub(crate) fn has_workspace_root_rules(entries: &[FileSystemSandboxEntry]) -> bool {
|
||||
entries.iter().any(|entry| match &entry.path {
|
||||
FileSystemPath::Special { value } => {
|
||||
matches!(value, FileSystemSpecialPath::ProjectRoots { .. })
|
||||
}
|
||||
FileSystemPath::GlobPattern { pattern } => {
|
||||
pattern.starts_with(PROJECT_ROOTS_GLOB_PATTERN_PREFIX)
|
||||
}
|
||||
FileSystemPath::Path { .. } => false,
|
||||
})
|
||||
}
|
||||
|
||||
fn read_only_file_system_entries() -> Vec<FileSystemSandboxEntry> {
|
||||
vec![FileSystemSandboxEntry::new(
|
||||
FileSystemPath::Special {
|
||||
|
||||
@@ -8,12 +8,12 @@ use super::FileSystemSandboxPolicy;
|
||||
use super::FileSystemSandboxPolicyContext;
|
||||
use super::FileSystemSpecialPath;
|
||||
use super::InvalidDenyReadGlobBehavior;
|
||||
use super::PROJECT_ROOTS_GLOB_PATTERN_PREFIX;
|
||||
use super::PROTECTED_METADATA_PATH_NAMES;
|
||||
use super::ReadDenyMatcher;
|
||||
use super::deny_read_validator::DenyReadValidator;
|
||||
use super::deny_read_validator::has_context_read_denials;
|
||||
use super::file_system_root;
|
||||
use super::has_workspace_root_rules;
|
||||
use codex_utils_path_uri::PathConvention;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use std::collections::HashSet;
|
||||
@@ -56,20 +56,7 @@ impl FileSystemSandboxPolicy {
|
||||
FileSystemAccessMode::Write,
|
||||
)]);
|
||||
approved.preserve_deny_read_restrictions_from(self);
|
||||
if context.workspace_roots.is_empty()
|
||||
&& approved.entries.iter().any(|entry| {
|
||||
matches!(
|
||||
&entry.path,
|
||||
FileSystemPath::Special {
|
||||
value: FileSystemSpecialPath::ProjectRoots { .. }
|
||||
}
|
||||
) || matches!(
|
||||
&entry.path,
|
||||
FileSystemPath::GlobPattern { pattern }
|
||||
if pattern.starts_with(PROJECT_ROOTS_GLOB_PATTERN_PREFIX)
|
||||
)
|
||||
})
|
||||
{
|
||||
if context.workspace_roots.is_empty() && has_workspace_root_rules(&approved.entries) {
|
||||
return self.clone();
|
||||
}
|
||||
let Some(mut approved) =
|
||||
|
||||
Reference in New Issue
Block a user