Simplify legacy Windows sandbox ACL persistence (#22569)

## Why

The legacy Windows sandbox still carried a `persist_aces` mode switch,
even though the only path that meaningfully applies filesystem ACEs
today is `workspace-write`, which already uses the persistent behavior.
Legacy read-only sessions rely on the read-only capability SID rather
than per-command filesystem ACE mutation, so the temporary cleanup
branch had become conceptual overhead without a corresponding behavioral
need.

Removing that split makes the ACL lifecycle match the current sandbox
model more directly and trims the guard/revocation plumbing from the
legacy launcher paths.

## What changed

- Removed the `persist_aces` parameter from legacy ACL preparation.
- Made legacy deny-read handling always use the persistent
reconciliation path.
- Dropped guard tracking and post-exit ACE revocation from both capture
and unified-exec legacy flows.
- Kept workspace `.codex` / `.agents` protection tied directly to
`WorkspaceWrite` instead of an intermediate persistence flag.

## Verification

- `cargo fmt -p codex-windows-sandbox`
- `git diff --check`
- `cargo test -p codex-windows-sandbox`
  - 85 passed, 2 ignored, 2 (unrelated) failed locally.
This commit is contained in:
iceweasel-oai authored and GitHub committed 2026-05-18 11:00:03 -07:00
1 parent 9286ff2805
commit b1c13b6fe5
3 files changed
+21 -103

No files matched your search

+2 -23
View File
@@ -279,7 +279,6 @@ pub use stub::run_windows_sandbox_legacy_preflight;
#[cfg(target_os = "windows")]
mod windows_impl {
use super::acl::revoke_ace;
use super::logging::log_failure;
use super::logging::log_success;
use super::policy::SandboxPolicy;
@@ -292,7 +291,6 @@ mod windows_impl {
use super::spawn_prep::prepare_legacy_session_security;
use super::spawn_prep::prepare_legacy_spawn_context;
use super::spawn_prep::root_capability_sids;
use super::token::LocalSid;
use anyhow::Result;
use codex_utils_absolute_path::AbsolutePathBuf;
use std::collections::HashMap;
@@ -424,8 +422,7 @@ mod windows_impl {
);
let security = prepare_legacy_session_security(&policy, codex_home, cwd, capability_roots)?;
allow_null_device_for_workspace_write(is_workspace_write);
let persist_aces = is_workspace_write;
let guards = apply_legacy_session_acl_rules(
apply_legacy_session_acl_rules(
&policy,
sandbox_policy_cwd,
codex_home,
@@ -438,7 +435,6 @@ mod windows_impl {
readonly_sid_str: security.readonly_sid_str.as_deref(),
write_root_sids: &security.write_root_sids,
},
persist_aces,
)?;
let (stdin_pair, stdout_pair, stderr_pair) = unsafe { setup_stdio_pipes()? };
let ((in_r, in_w), (out_r, out_w), (err_r, err_w)) = (stdin_pair, stdout_pair, stderr_pair);
@@ -463,13 +459,6 @@ mod windows_impl {
CloseHandle(out_w);
CloseHandle(err_r);
CloseHandle(err_w);
if !persist_aces {
for (p, sid_str) in &guards {
if let Ok(sid) = LocalSid::from_string(sid_str) {
revoke_ace(p, sid.as_ptr());
}
}
}
CloseHandle(security.h_token);
}
return Err(err);
@@ -570,15 +559,6 @@ mod windows_impl {
log_failure(&command, &format!("exit code {exit_code}"), logs_base_dir);
}
if !persist_aces {
unsafe {
for (p, sid_str) in guards {
if let Ok(sid) = LocalSid::from_string(&sid_str) {
revoke_ace(&p, sid.as_ptr());
}
}
}
}
Ok(CaptureResult {
exit_code,
stdout,
@@ -609,7 +589,7 @@ mod windows_impl {
codex_home,
);
let write_root_sids = root_capability_sids(codex_home, cwd, capability_roots)?;
let _guards = apply_legacy_session_acl_rules(
apply_legacy_session_acl_rules(
sandbox_policy,
sandbox_policy_cwd,
codex_home,
@@ -622,7 +602,6 @@ mod windows_impl {
readonly_sid_str: None,
write_root_sids: &write_root_sids,
},
/*persist_aces*/ true,
)?;
Ok(())