-
Notifications
You must be signed in to change notification settings - Fork 14k
Apply sandbox intent inside remote exec servers #29113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a494f4d
Carry sandbox intent to remote exec servers
jif-oai 67b2819
Carry symbolic sandbox intent to exec servers
jif-oai e6169bc
Apply sandbox intent inside remote exec servers
jif-oai 4c6ef01
Preserve executor sandbox type for remote processes
jif-oai 1692611
Report remote sandbox denials semantically
jif-oai 971e0f8
Merge branch 'main' into jif/remote-exec-server-sandbox-enforcement
jif-oai f4288f8
Document Windows remote sandbox follow-up
jif-oai 4eab617
Let executors derive remote workspace roots
jif-oai 673e787
Revert "Report remote sandbox denials semantically"
jif-oai 30fa651
Revert "Preserve executor sandbox type for remote processes"
jif-oai e9c548f
Document remote sandbox portability follow-ups
jif-oai 6534b0a
Fix argument comments for runtime paths
jif-oai 9c303c6
Pass runtime paths to local exec backend
jif-oai 4b31996
Gate sandbox test imports on Unix
jif-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| use std::collections::HashMap; | ||
|
|
||
| use codex_app_server_protocol::JSONRPCErrorError; | ||
| use codex_protocol::models::PermissionProfile; | ||
| use codex_sandboxing::SandboxCommand; | ||
| use codex_sandboxing::SandboxDirectSpawnTransformRequest; | ||
| use codex_sandboxing::SandboxManager; | ||
| use codex_sandboxing::SandboxTransformRequest; | ||
| use codex_sandboxing::SandboxType; | ||
| use codex_sandboxing::SandboxablePreference; | ||
| use codex_utils_absolute_path::AbsolutePathBuf; | ||
| use codex_utils_path_uri::PathUri; | ||
|
|
||
| use crate::ExecServerRuntimePaths; | ||
| use crate::protocol::ExecParams; | ||
| use crate::rpc::invalid_params; | ||
|
|
||
| pub(crate) struct PreparedExecRequest { | ||
| pub(crate) command: Vec<String>, | ||
| pub(crate) cwd: AbsolutePathBuf, | ||
| pub(crate) env: HashMap<String, String>, | ||
| pub(crate) arg0: Option<String>, | ||
| } | ||
|
|
||
| pub(crate) fn prepare_exec_request( | ||
| params: &ExecParams, | ||
| env: HashMap<String, String>, | ||
| runtime_paths: Option<&ExecServerRuntimePaths>, | ||
| ) -> Result<PreparedExecRequest, JSONRPCErrorError> { | ||
| let Some(sandbox_context) = params.sandbox.as_ref() else { | ||
| return Ok(PreparedExecRequest { | ||
| command: params.argv.clone(), | ||
| cwd: native_path(¶ms.cwd, "cwd")?, | ||
| env, | ||
| arg0: params.arg0.clone(), | ||
| }); | ||
| }; | ||
| let runtime_paths = runtime_paths | ||
| .ok_or_else(|| invalid_params("sandbox runtime paths are not configured".to_string()))?; | ||
| // TODO(jif): Transport permissions before orchestrator-local paths are materialized, | ||
| // then resolve executor-local helper and workspace paths here. | ||
| let permissions: PermissionProfile = sandbox_context | ||
| .permissions | ||
| .clone() | ||
| .try_into() | ||
| .map_err(|err| invalid_params(format!("invalid sandbox permission path URI: {err}")))?; | ||
| let sandbox_policy_cwd = sandbox_context.cwd.as_ref().unwrap_or(¶ms.cwd); | ||
| let native_sandbox_policy_cwd = native_path(sandbox_policy_cwd, "sandbox cwd")?; | ||
| let native_workspace_roots = sandbox_context | ||
| .workspace_roots | ||
|
jif-oai marked this conversation as resolved.
|
||
| .iter() | ||
| .map(|root| native_path(root, "sandbox workspace root")) | ||
| .collect::<Result<Vec<_>, _>>()?; | ||
| let workspace_roots = if native_workspace_roots.is_empty() { | ||
| std::slice::from_ref(&native_sandbox_policy_cwd) | ||
| } else { | ||
| native_workspace_roots.as_slice() | ||
| }; | ||
|
jif-oai marked this conversation as resolved.
|
||
| let permissions = permissions.materialize_project_roots_with_workspace_roots(workspace_roots); | ||
| let (file_system_policy, network_policy) = permissions.to_runtime_permissions(); | ||
| let sandbox_manager = SandboxManager::new(); | ||
| let sandbox = sandbox_manager.select_initial( | ||
| &file_system_policy, | ||
| network_policy, | ||
| SandboxablePreference::Require, | ||
| sandbox_context.windows_sandbox_level, | ||
| params.enforce_managed_network, | ||
| ); | ||
| match sandbox { | ||
| SandboxType::None => { | ||
| return Err(invalid_params( | ||
| "sandbox intent cannot be enforced on this executor".to_string(), | ||
| )); | ||
| } | ||
| SandboxType::WindowsRestrictedToken => { | ||
| // TODO(jif): Launch generic remote commands through the Windows sandbox session API | ||
| // while preserving argv and TTY behavior and passing the child environment out of band. | ||
| return Err(invalid_params( | ||
| "sandboxed remote process launch is not supported on Windows".to_string(), | ||
|
jif-oai marked this conversation as resolved.
|
||
| )); | ||
| } | ||
| SandboxType::MacosSeatbelt | SandboxType::LinuxSeccomp => {} | ||
| } | ||
| let (program, args) = params | ||
| .argv | ||
| .split_first() | ||
| .ok_or_else(|| invalid_params("argv must not be empty".to_string()))?; | ||
| let request = sandbox_manager | ||
| .transform_for_direct_spawn(SandboxDirectSpawnTransformRequest { | ||
| workspace_roots, | ||
| transform: SandboxTransformRequest { | ||
| // TODO(jif): Preserve params.arg0 for the inner command across the sandbox | ||
| // wrapper, or reject sandboxed requests with a custom arg0. | ||
| command: SandboxCommand { | ||
| program: program.into(), | ||
| args: args.to_vec(), | ||
| cwd: params.cwd.clone(), | ||
| env, | ||
| additional_permissions: None, | ||
|
jif-oai marked this conversation as resolved.
|
||
| }, | ||
| permissions: &permissions, | ||
| sandbox, | ||
| enforce_managed_network: params.enforce_managed_network, | ||
| environment_id: None, | ||
| network: None, | ||
|
jif-oai marked this conversation as resolved.
jif-oai marked this conversation as resolved.
|
||
| sandbox_policy_cwd, | ||
| codex_linux_sandbox_exe: runtime_paths.codex_linux_sandbox_exe.as_deref(), | ||
| use_legacy_landlock: sandbox_context.use_legacy_landlock, | ||
| windows_sandbox_level: sandbox_context.windows_sandbox_level, | ||
| windows_sandbox_private_desktop: sandbox_context.windows_sandbox_private_desktop, | ||
| }, | ||
| }) | ||
| .map_err(|err| invalid_params(format!("failed to prepare process sandbox: {err}")))?; | ||
| Ok(PreparedExecRequest { | ||
| command: request.command, | ||
| cwd: native_path(&request.cwd, "cwd")?, | ||
| env: request.env, | ||
|
jif-oai marked this conversation as resolved.
jif-oai marked this conversation as resolved.
|
||
| arg0: request.arg0, | ||
| }) | ||
|
jif-oai marked this conversation as resolved.
|
||
| } | ||
|
|
||
| fn native_path(path: &PathUri, label: &str) -> Result<AbsolutePathBuf, JSONRPCErrorError> { | ||
| path.to_abs_path().map_err(|err| { | ||
| invalid_params(format!( | ||
| "{label} URI `{path}` is not valid on this exec-server host: {err}" | ||
| )) | ||
| }) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[path = "process_sandbox_tests.rs"] | ||
| mod tests; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.