Wire missing Windows metadata to deny sentinel

This commit is contained in:
Eva Wong
2026-05-06 15:33:40 -07:00
parent 4c24c5ec58
commit 8177cafbbb
5 changed files with 33 additions and 28 deletions
+1 -1
View File
@@ -478,7 +478,7 @@ fn windows_debug_protected_metadata_targets(
let mode = if std::fs::symlink_metadata(path.as_path()).is_ok() {
codex_windows_sandbox::ProtectedMetadataMode::ExistingDeny
} else {
codex_windows_sandbox::ProtectedMetadataMode::MissingCreationMonitor
codex_windows_sandbox::ProtectedMetadataMode::MissingDenySentinel
};
targets.push(codex_windows_sandbox::ProtectedMetadataTarget {
path: path.as_path().to_path_buf(),
+12 -7
View File
@@ -121,13 +121,18 @@ pub(crate) struct WindowsProtectedMetadataTarget {
pub(crate) mode: WindowsProtectedMetadataMode,
}
/// Layer: Windows adapter layer. The enforcement layer needs to know why a
/// protected metadata path is absent instead of treating every missing path as
/// an existing filesystem object.
/// Layer: Windows adapter layer. The enforcement layer needs to know whether a
/// protected metadata path already exists or must be denied before the command
/// can create it.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum WindowsProtectedMetadataMode {
/// The protected metadata object exists before launch, so the Windows
/// sandbox should deny writes to the object and any canonical target.
ExistingDeny,
MissingCreationMonitor,
/// The protected metadata object is absent before launch, so the Windows
/// sandbox should create and deny-list a temporary sentinel before command
/// execution can begin.
MissingDenySentinel,
}
fn windows_sandbox_uses_elevated_backend(
@@ -666,8 +671,8 @@ async fn exec_windows_sandbox(
WindowsProtectedMetadataMode::ExistingDeny => {
codex_windows_sandbox::ProtectedMetadataMode::ExistingDeny
}
WindowsProtectedMetadataMode::MissingCreationMonitor => {
codex_windows_sandbox::ProtectedMetadataMode::MissingCreationMonitor
WindowsProtectedMetadataMode::MissingDenySentinel => {
codex_windows_sandbox::ProtectedMetadataMode::MissingDenySentinel
}
};
codex_windows_sandbox::ProtectedMetadataTarget {
@@ -1361,7 +1366,7 @@ fn windows_protected_metadata_mode(path: &AbsolutePathBuf) -> WindowsProtectedMe
return WindowsProtectedMetadataMode::ExistingDeny;
}
WindowsProtectedMetadataMode::MissingCreationMonitor
WindowsProtectedMetadataMode::MissingDenySentinel
}
fn has_reopened_writable_descendant(
+15 -15
View File
@@ -666,15 +666,15 @@ fn windows_restricted_token_supports_full_read_split_write_read_carveouts() {
protected_metadata_targets: vec![
WindowsProtectedMetadataTarget {
path: cwd.join(".agents"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: cwd.join(".codex"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: cwd.join(".git"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
],
}))
@@ -778,15 +778,15 @@ fn windows_elevated_supports_split_write_read_carveouts() {
protected_metadata_targets: vec![
WindowsProtectedMetadataTarget {
path: expected_root.join(".agents"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: expected_root.join(".codex"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: expected_root.join(".git"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
],
}))
@@ -840,11 +840,11 @@ fn windows_metadata_plan_marks_existing_metadata_for_deny() {
protected_metadata_targets: vec![
WindowsProtectedMetadataTarget {
path: cwd.join(".agents"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: cwd.join(".codex"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: cwd.join(".git"),
@@ -856,7 +856,7 @@ fn windows_metadata_plan_marks_existing_metadata_for_deny() {
}
#[test]
fn windows_metadata_plan_does_not_materialize_nested_missing_git() {
fn windows_metadata_plan_uses_sentinel_for_nested_missing_git() {
let temp_dir = tempfile::TempDir::new().expect("tempdir");
let repo = dunce::canonicalize(temp_dir.path())
.expect("canonical temp dir")
@@ -904,15 +904,15 @@ fn windows_metadata_plan_does_not_materialize_nested_missing_git() {
protected_metadata_targets: vec![
WindowsProtectedMetadataTarget {
path: cwd.join(".agents"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: cwd.join(".codex"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: cwd.join(".git"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
],
}))
@@ -973,15 +973,15 @@ fn windows_shell_runtime_path_resolves_metadata_overrides() {
vec![
WindowsProtectedMetadataTarget {
path: cwd.join(".agents"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: cwd.join(".codex"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
WindowsProtectedMetadataTarget {
path: cwd.join(".git"),
mode: WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: WindowsProtectedMetadataMode::MissingDenySentinel,
},
]
);
@@ -190,8 +190,8 @@ fn protected_metadata_targets_for_windows_session(
WindowsProtectedMetadataMode::ExistingDeny => {
codex_windows_sandbox::ProtectedMetadataMode::ExistingDeny
}
WindowsProtectedMetadataMode::MissingCreationMonitor => {
codex_windows_sandbox::ProtectedMetadataMode::MissingCreationMonitor
WindowsProtectedMetadataMode::MissingDenySentinel => {
codex_windows_sandbox::ProtectedMetadataMode::MissingDenySentinel
}
};
codex_windows_sandbox::ProtectedMetadataTarget {
@@ -183,15 +183,15 @@ fn open_session_prepares_windows_metadata_overrides_for_unified_exec() {
vec![
crate::exec::WindowsProtectedMetadataTarget {
path: cwd.join(".agents"),
mode: crate::exec::WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: crate::exec::WindowsProtectedMetadataMode::MissingDenySentinel,
},
crate::exec::WindowsProtectedMetadataTarget {
path: cwd.join(".codex"),
mode: crate::exec::WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: crate::exec::WindowsProtectedMetadataMode::MissingDenySentinel,
},
crate::exec::WindowsProtectedMetadataTarget {
path: cwd.join(".git"),
mode: crate::exec::WindowsProtectedMetadataMode::MissingCreationMonitor,
mode: crate::exec::WindowsProtectedMetadataMode::MissingDenySentinel,
},
]
);