mirror of
https://github.com/openai/codex.git
synced 2026-11-28 23:34:06 +00:00
Add opt-in registered package execution to the Windows sandbox (#45550)
## What changed - Capture `CODEX_WINDOWS_REGISTERED_CORE=1` at startup and propagate the selected runtime to sandbox wrappers. - Launch registered runners through service-recorded execution aliases, validating ownership, OS package identity, and the staged runner image before sending commands. Require service provisioning without falling back to copied helpers or `PATH` lookup. - Preserve package context for sandboxed child processes and descendants so they can launch executables from the protected package directory. - Refresh stale package registrations during readiness checks without blocking unrelated RPCs, and reconcile effective proxy settings through the service. - Resolve setup ownership from the process token and avoid treating the server directory as a writable workspace when setup omits `cwd`. - Record startup and command outcomes by runtime. ## Testing Add coverage for runtime selection, package query validation, helper resolution, setup roots, proxy reconciliation, and command result reporting. Add an ignored integration test for environment forwarding, output, and exit status that requires an installed test MSIX and service provisioning in a Windows VM. GitOrigin-RevId: 976d64039d611be4406c3d0e354820775f8eb6e4
This commit is contained in:
1 parent
529bcb2fdf
commit
4199fda578
30 files changed
+1110
-205
No files matched your search
@@ -1,10 +1,14 @@
|
||||
use super::*;
|
||||
#[cfg(target_os = "windows")]
|
||||
use anyhow::Context as _;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct WindowsSandboxRequestProcessor {
|
||||
outgoing: Arc<OutgoingMessageSender>,
|
||||
config: Arc<Config>,
|
||||
config_manager: ConfigManager,
|
||||
#[cfg(target_os = "windows")]
|
||||
registration_refresh: Arc<tokio::sync::OnceCell<()>>,
|
||||
}
|
||||
|
||||
impl WindowsSandboxRequestProcessor {
|
||||
@@ -17,13 +21,67 @@ impl WindowsSandboxRequestProcessor {
|
||||
outgoing,
|
||||
config,
|
||||
config_manager,
|
||||
#[cfg(target_os = "windows")]
|
||||
registration_refresh: Arc::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn windows_sandbox_readiness(
|
||||
&self,
|
||||
) -> Result<WindowsSandboxReadinessResponse, JSONRPCErrorError> {
|
||||
Ok(determine_windows_sandbox_readiness(&self.config))
|
||||
request_id: &ConnectionRequestId,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
#[cfg(target_os = "windows")]
|
||||
if codex_windows_sandbox::registered_core_requested()
|
||||
&& matches!(
|
||||
WindowsSandboxLevel::from_config(&self.config),
|
||||
WindowsSandboxLevel::Elevated
|
||||
)
|
||||
&& !codex_login::is_workload_identity_selected()
|
||||
{
|
||||
let processor = self.clone();
|
||||
let request_id = request_id.clone();
|
||||
// Deployment must not hold up unrelated RPCs in the serial dispatcher.
|
||||
tokio::spawn(async move {
|
||||
// Coalesce readiness requests. A failed refresh leaves manual setup available.
|
||||
processor.registration_refresh.get_or_init(|| async {
|
||||
let config = Arc::clone(&processor.config);
|
||||
let result = tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
|
||||
if !codex_windows_sandbox::registered_core_needs_refresh(&config.codex_home)? {
|
||||
return Ok(());
|
||||
}
|
||||
let env_map = std::env::vars().collect();
|
||||
let policy = config.permissions.effective_permission_profile();
|
||||
let (settings, listeners) = match config.permissions.network.as_ref() {
|
||||
Some(network) => network.windows_sandbox_proxy_listeners()?,
|
||||
None => (
|
||||
codex_windows_sandbox::WindowsSandboxProvisioningSettings::from_environment(&policy, &env_map),
|
||||
codex_windows_sandbox::WindowsSandboxProxyListeners::from_environment(&policy, &env_map),
|
||||
),
|
||||
};
|
||||
codex_windows_sandbox::refresh_registered_core_via_service(
|
||||
&config.codex_home, settings, listeners,
|
||||
)?;
|
||||
Ok(())
|
||||
}).await.map_err(anyhow::Error::from).and_then(std::convert::identity);
|
||||
if let Err(error) = result {
|
||||
warn!("Registered Core startup refresh requires manual setup: {error:#}");
|
||||
}
|
||||
}).await;
|
||||
processor
|
||||
.outgoing
|
||||
.send_response(
|
||||
request_id,
|
||||
determine_windows_sandbox_readiness(&processor.config),
|
||||
)
|
||||
.await;
|
||||
});
|
||||
return Ok(None);
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let _ = request_id;
|
||||
Ok(Some(
|
||||
determine_windows_sandbox_readiness(&self.config).into(),
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) async fn windows_sandbox_setup_start(
|
||||
@@ -79,7 +137,8 @@ impl WindowsSandboxRequestProcessor {
|
||||
// the caller's resolved configuration instead of loading auth in the service.
|
||||
#[cfg(target_os = "windows")]
|
||||
if setup_mode == CoreWindowsSandboxSetupMode::Elevated
|
||||
&& config.features.enabled(Feature::WindowsSandboxService)
|
||||
&& (codex_windows_sandbox::registered_core_requested()
|
||||
|| config.features.enabled(Feature::WindowsSandboxService))
|
||||
&& !codex_login::is_workload_identity_selected()
|
||||
{
|
||||
let provisioning = match config
|
||||
@@ -104,6 +163,9 @@ impl WindowsSandboxRequestProcessor {
|
||||
{
|
||||
Ok(provisioning) => Some(provisioning),
|
||||
Err(error) => {
|
||||
if codex_windows_sandbox::registered_core_requested() {
|
||||
return Err(error).context("registered Core requires service-compatible proxy settings");
|
||||
}
|
||||
warn!(
|
||||
"Windows sandbox service does not support the configured proxy listeners; falling back to elevated setup: {error}"
|
||||
);
|
||||
@@ -118,6 +180,8 @@ impl WindowsSandboxRequestProcessor {
|
||||
&service_setup_request.permission_profile,
|
||||
&service_setup_request.workspace_roots,
|
||||
) else {
|
||||
anyhow::ensure!(!codex_windows_sandbox::registered_core_requested(),
|
||||
"registered Core requires a service-compatible sandbox policy");
|
||||
// The existing setup path can still succeed for completed
|
||||
// provisioning without resolving the current profile.
|
||||
return Ok(());
|
||||
@@ -177,12 +241,15 @@ async fn load_setup_config(
|
||||
fallback_cwd: &std::path::Path,
|
||||
requested_cwd: Option<PathBuf>,
|
||||
) -> std::io::Result<(Config, PathBuf)> {
|
||||
// Setup without a project must not grant writes to the app's install directory.
|
||||
let workspace_roots = requested_cwd.is_none().then(Vec::new);
|
||||
let cwd = requested_cwd.unwrap_or_else(|| fallback_cwd.to_path_buf());
|
||||
let config = manager
|
||||
.load_for_cwd(
|
||||
/*request_overrides*/ None,
|
||||
ConfigOverrides {
|
||||
cwd: Some(cwd.clone()),
|
||||
workspace_roots,
|
||||
..Default::default()
|
||||
},
|
||||
Some(cwd.clone()),
|
||||
|
||||
@@ -5,6 +5,21 @@ use super::load_setup_config;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn omitted_cwd_does_not_make_the_server_directory_a_workspace() -> anyhow::Result<()> {
|
||||
let home = tempfile::tempdir()?;
|
||||
let install = tempfile::tempdir()?;
|
||||
let manager = ConfigManager::without_managed_config_for_tests(home.path().to_path_buf());
|
||||
let (config, command_cwd) =
|
||||
load_setup_config(&manager, install.path(), /*requested_cwd*/ None).await?;
|
||||
|
||||
assert_eq!(
|
||||
(command_cwd, config.effective_workspace_roots()),
|
||||
(install.path().to_path_buf(), Vec::new()),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn explicit_cwd_remains_the_setup_workspace() -> anyhow::Result<()> {
|
||||
let home = tempfile::tempdir()?;
|
||||
|
||||
Reference in new issue
Block a user