Enforce managed MXC requirements on Windows (#52193)

## What changed

Add `windows.require_mxc` to managed requirements. When set to `true` on Windows, reject configurations whose effective local sandbox backend is not MXC without changing the selected backend.

Validate after cloud configuration loads and outside startup recovery fallbacks. Apply the check to app-server startup and configuration loads, in-process bootstrap, session creation, sandbox debugging, and runtime configuration refreshes.

## Testing

Extend configuration tests to cover required and optional MXC selection, separately loaded policy requirements, and runtime refresh validation. Expand app-server startup tests to cover local and cloud MXC requirements, cloud preference selection, and failures without default-config recovery.

GitOrigin-RevId: 16456611bfd9df77e7f959b52515f1885b59ac75
This commit is contained in:
iceweasel-oai
2026-10-08 17:48:32 +00:00
committed by copyberry
parent 5fe2152b60
commit f90a578f76
12 changed files with 146 additions and 12 deletions
+44 -3
View File
@@ -11094,8 +11094,12 @@ async fn explicit_sandbox_mode_falls_back_when_disallowed_by_requirements() -> s
Ok(())
}
#[test_case::test_case(false; "optional")]
#[test_case::test_case(true; "required")]
#[tokio::test]
async fn local_mxc_preference_preserves_configured_backend() -> anyhow::Result<()> {
async fn local_mxc_preference_preserves_configured_backend(
require_mxc: bool,
) -> anyhow::Result<()> {
use codex_sandboxing::SandboxType::WindowsMxc;
use codex_sandboxing::SandboxType::WindowsRestrictedToken as RestrictedToken;
@@ -11122,16 +11126,53 @@ async fn local_mxc_preference_preserves_configured_backend() -> anyhow::Result<(
codex_home.path().join(CONFIG_TOML_FILE),
toml::to_string(&cfg)?,
)?;
let mut config = ConfigBuilder::without_managed_config_for_tests()
let loaded = ConfigBuilder::without_managed_config_for_tests()
.codex_home(codex_home.path().to_path_buf())
.fallback_cwd(Some(codex_home.path().to_path_buf()))
.cloud_config_bundle(
CloudConfigBundleFixture::loader_with_enterprise_requirement(format!(
"[windows]\nallow_mxc = {allow_mxc}\n"
"[windows]\nallow_mxc = {allow_mxc}\nrequire_mxc = {require_mxc}\n"
)),
)
.build()
.await?;
let mut config = Config::rebuild_with_session_layers(
&loaded.config_layer_stack,
loaded.cwd.to_path_buf(),
&loaded.config_layer_stack,
loaded.codex_home.clone(),
/*default_zsh_path*/ None,
)
.await?;
let mut caller_config = config.clone();
caller_config.config_layer_stack = ConfigLayerStack::default();
caller_config.prefer_mxc = false;
caller_config.permissions.windows_sandbox_type = RestrictedToken;
assert_eq!(
caller_config
.validate_windows_mxc_requirement_from(&config)
.is_err(),
cfg!(windows) && require_mxc,
);
let result = config.validate_windows_mxc_requirement();
caller_config.config_layer_stack = config.config_layer_stack.clone();
assert_eq!(
config
.resolve_runtime_refresh(&caller_config, RuntimeConfigRefresh::Mcp)
.is_err(),
result.is_err(),
);
if cfg!(windows)
&& require_mxc
&& mode != "mxc"
&& !(prefer && binding && allow_mxc && codex_sandboxing::windows_mxc_available())
{
let error = result.expect_err("MXC must already be selected");
assert_eq!(error.kind(), std::io::ErrorKind::InvalidInput);
assert!(error.to_string().contains("windows.require_mxc = true"));
continue;
}
result?;
assert_eq!(
config_allows_mxc(
&config
@@ -1,5 +1,6 @@
//! Resolves refreshable MCP inputs without rebuilding unrelated session configuration.
//! Existing sessions refresh ordinary MCP state without gaining enterprise authority.
//! Validate the retained backend after applying the refreshable requirements.
use crate::config::Config;
use crate::config::ManagedFeatures;
@@ -168,6 +169,7 @@ impl Config {
if enterprise_retired {
config.disable_mcp_enterprise_auth();
}
config.validate_windows_mxc_requirement()?;
Ok(config)
}
@@ -1,6 +1,7 @@
//! Configured Windows sandbox modes and the effective local backend.
//! Keep the configured backend for remote inheritance; apply the local rollout
//! using the preference resolved during config loading.
//! Validate MXC requirements only after bootstrap has loaded the complete config.
use super::Config;
use super::EffectivePermissionSelection;
@@ -19,6 +20,35 @@ use codex_protocol::models::PermissionProfile;
use codex_sandboxing::SandboxType;
impl Config {
/// Reject a non-MXC selection without changing the final configuration.
/// Call after cloud configuration loads and outside config-recovery fallbacks.
pub fn validate_windows_mxc_requirement(&self) -> std::io::Result<()> {
self.validate_windows_mxc_requirement_from(self)
}
/// Check this execution config against separately loaded managed requirements.
pub fn validate_windows_mxc_requirement_from(
&self,
policy_config: &Self,
) -> std::io::Result<()> {
if cfg!(windows)
&& policy_config
.config_layer_stack
.requirements_toml()
.windows
.as_ref()
.and_then(|windows| windows.require_mxc)
== Some(true)
&& self.effective_local_windows_sandbox_type() != SandboxType::WindowsMxc
{
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"windows.require_mxc = true requires MXC to be selected on this Windows host",
));
}
Ok(())
}
/// Configured backend, without the local rollout preference. Remote executors inherit this.
pub fn windows_sandbox_type_from_config(&self) -> SandboxType {
self.permissions.windows_sandbox_type
+1
View File
@@ -553,6 +553,7 @@ impl Session {
}
async fn spawn_internal(args: SessionSpawnArgs) -> CodexResult<(Arc<Self>, SessionIo)> {
args.config.validate_windows_mxc_requirement()?;
let SessionSpawnArgs {
startup,
config,