Validate network socket policies using the executor OS (#46302)

## Why

A controller and its executor can run different operating systems. Validating socket paths against the controller's OS can reject absolute paths that are valid on the executor, such as Windows paths on a Linux controller.

## What changed

- Thread `NetworkProxyExecutorOs` through network policy validation, proxy construction, and policy updates.
- Require allowed socket paths to be NUL-free and absolute for the executor OS, while preserving deny entries unchanged.
- Accept either Unix or Windows absolute syntax when executor metadata omits the OS, then validate against the executor's own OS at launch.
- Keep native path normalization and socket support checks at execution time.

## Testing

Add coverage for cross-platform absolute path syntax, invalid allow entries, preserved deny entries, and remote policy round trips that retain executor semantics through domain edits and proxy construction.

GitOrigin-RevId: 1ebc09cbce7138f60ec5fd62875591a3df52d067
This commit is contained in:
Sean Huang authored and copyberry committed 2026-09-17 20:59:55 +00:00
1 parent 8f73cdee45
commit ea218f5cd8
23 files changed
+519 -134

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
//! Executor path semantics for policy validation, independent of the controller OS.
//! Socket support and native path normalization remain executor runtime concerns.
/// OS of the executor whose network policy is being validated.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NetworkProxyExecutorOs {
Linux,
Macos,
Windows,
/// Legacy executors may omit their OS. Accept absolute syntax supported by
/// either platform here; the executor validates against its own OS at launch.
Unknown,
}
impl NetworkProxyExecutorOs {
/// Uses executor metadata, never the OS of the process doing the validation.
pub fn from_platform_os(platform_os: Option<&str>) -> Self {
match platform_os {
Some("linux") => Self::Linux,
Some("macos") => Self::Macos,
Some("windows") => Self::Windows,
Some(_) | None => Self::Unknown,
}
}
pub(crate) fn socket_path_is_absolute(self, path: &str) -> bool {
// Core also accepts Unix-style absolute paths on Windows, for portability.
path.starts_with('/')
|| match self {
Self::Linux | Self::Macos => false,
Self::Windows | Self::Unknown => windows_path_is_absolute(path),
}
}
}
// Match std::path's Windows absolute-path syntax without consulting the host.
// Non-drive prefixes have an implicit root, including device and verbatim paths.
fn windows_path_is_absolute(path: &str) -> bool {
let bytes = path.as_bytes();
if matches!(bytes, [drive, b':', b'\\' | b'/', ..] if drive.is_ascii_alphabetic()) {
return true;
}
let [b'\\' | b'/', b'\\' | b'/', rest @ ..] = bytes else {
return false;
};
if path.starts_with(r"\\?\") || matches!(rest, [b'.', b'\\' | b'/', ..]) {
return true;
}
let mut components = rest.split(|byte| matches!(byte, b'\\' | b'/'));
matches!(
(components.next(), components.next()),
(Some(server), Some(share)) if !server.is_empty() && !share.is_empty()
)
}