Skip to content

Commit 2378c84

Browse files
fix(network): restore Windows binary path normalization (#5014)
Keep exact Windows binary path matching by default. Let gateway operators opt in to separator equivalence and directory-verified ASCII case matching while retaining executable integrity pins and consistent connection and HTTP admission. Closes #5013 Signed-off-by: Shailendra Singh <shailendras@nvidia.com>
1 parent 28de567 commit 2378c84

19 files changed

Lines changed: 990 additions & 40 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/openshell-binary-identity/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ repository.workspace = true
1414
openshell-isolation-interface = { path = "../openshell-isolation-interface" }
1515
sha2 = { workspace = true }
1616

17+
[target.'cfg(windows)'.dependencies]
18+
windows = { workspace = true, features = ["Win32_Storage_FileSystem"] }
19+
1720
[lints]
1821
workspace = true

‎crates/openshell-binary-identity/README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ The crate does not intercept connections, authenticate remote observers, or
1818
evaluate policy. The isolation backend remains responsible for binding the
1919
resolved identity to the active boundary and exact accepted connection before
2020
constructing `PendingTcpOpen`.
21+
22+
On Windows, the crate also exposes a safe query for the case-sensitivity of
23+
every parent directory of a trusted runtime executable path. Network policy
24+
matching may fold ASCII case only when all of those directories confirm
25+
case-insensitive lookup. Namespace paths and failed queries retain exact case
26+
matching. The query never receives policy-authored paths, and matching does not
27+
change the original path used for executable hashing.

‎crates/openshell-binary-identity/src/lib.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
//! collects its process ancestry. Backends bind the returned identity to the
1010
//! intercepted connection before constructing a `MediatedConnection`.
1111
12+
#[cfg(target_os = "windows")]
13+
pub mod windows;
14+
15+
/// Whether a Windows path starts with an ordinary absolute drive prefix.
16+
#[must_use]
17+
pub fn is_ordinary_windows_drive_path(path: &[u8]) -> bool {
18+
matches!(path, [drive, b':', b'/' | b'\\', ..] if drive.is_ascii_alphabetic())
19+
}
20+
1221
use openshell_isolation_interface::contract::{BinaryIdentity, ResolveError};
1322
#[cfg(target_os = "linux")]
1423
use openshell_isolation_interface::contract::{ExecutableIdentity, Sha256Digest};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Trusted Windows runtime-path attributes for executable policy matching.
5+
6+
use std::path::Path;
7+
8+
#[allow(unsafe_code)]
9+
fn windows_directory_case_sensitive(path: &Path) -> Option<bool> {
10+
use std::mem::size_of;
11+
use std::os::windows::io::AsRawHandle;
12+
use windows::Win32::Foundation::HANDLE;
13+
use windows::Win32::Storage::FileSystem::{
14+
FILE_CASE_SENSITIVE_INFO, FileCaseSensitiveInfo, GetFileInformationByHandleEx,
15+
};
16+
17+
let handle = open_windows_directory_for_attributes(path)?;
18+
let mut info = FILE_CASE_SENSITIVE_INFO::default();
19+
let info_size = u32::try_from(size_of::<FILE_CASE_SENSITIVE_INFO>()).ok()?;
20+
// SAFETY: `handle` stays alive for the call and `info` is the exact buffer
21+
// type and size required by `FileCaseSensitiveInfo`.
22+
unsafe {
23+
GetFileInformationByHandleEx(
24+
HANDLE(handle.as_raw_handle()),
25+
FileCaseSensitiveInfo,
26+
(&raw mut info).cast(),
27+
info_size,
28+
)
29+
}
30+
.ok()?;
31+
Some(info.Flags & 1 != 0)
32+
}
33+
34+
/// Check every parent of a trusted, ordinary absolute executable path.
35+
///
36+
/// Returns `None` for namespace paths or when any directory cannot be queried.
37+
/// Callers must retain exact case matching unless this returns `Some(true)`.
38+
/// Never call this with policy-authored paths.
39+
#[must_use]
40+
pub fn path_components_case_insensitive(path: &Path) -> Option<bool> {
41+
let text = path.to_string_lossy();
42+
if text.contains(['*', '?']) || !super::is_ordinary_windows_drive_path(text.as_bytes()) {
43+
return None;
44+
}
45+
46+
let parent = path.parent()?;
47+
for directory in parent.ancestors().filter(|p| !p.as_os_str().is_empty()) {
48+
if windows_directory_case_sensitive(directory)? {
49+
return Some(false);
50+
}
51+
}
52+
Some(true)
53+
}
54+
55+
fn open_windows_directory_for_attributes(path: &Path) -> Option<std::fs::File> {
56+
use std::os::windows::fs::OpenOptionsExt;
57+
use windows::Win32::Storage::FileSystem::{
58+
FILE_FLAG_BACKUP_SEMANTICS, FILE_READ_ATTRIBUTES, FILE_SHARE_DELETE, FILE_SHARE_READ,
59+
FILE_SHARE_WRITE,
60+
};
61+
62+
std::fs::OpenOptions::new()
63+
.access_mode(FILE_READ_ATTRIBUTES.0)
64+
.share_mode(FILE_SHARE_READ.0 | FILE_SHARE_WRITE.0 | FILE_SHARE_DELETE.0)
65+
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS.0)
66+
.open(path)
67+
.ok()
68+
}

‎crates/openshell-driver-mxc/examples/run-mxc-e2e.ps1‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
# service-forwarding - named HTTP service routing and endpoint deletion.
3939
# host-service - workload reaches an HTTP service on host 127.0.0.1.
4040
# https-ca - opt-in outbound HTTPS using the injected proxy CA.
41+
# socket-owner-normalized - opt in to equivalent Windows policy paths.
42+
# socket-owner-normalized-default - equivalent spelling is denied by default.
4143

4244
[CmdletBinding()]
4345
param(
@@ -79,7 +81,7 @@ if (-not $BinaryDir) {
7981
}
8082
$savedEnv = @{}
8183
$processEnvironment = [Environment]::GetEnvironmentVariables("Process")
82-
foreach ($name in @("OPENSHELL_MXC_MOCK_WXC", "OPENSHELL_WXC_EXEC_PATH", "OPENSHELL_COMPUTE_DRIVER", "OPENSHELL_MXC_SHARE_DIR")) {
84+
foreach ($name in @("OPENSHELL_MXC_MOCK_WXC", "OPENSHELL_WXC_EXEC_PATH", "OPENSHELL_COMPUTE_DRIVER", "OPENSHELL_MXC_SHARE_DIR", "OPENSHELL_WINDOWS_BINARY_PATH_NORMALIZATION")) {
8385
$exists = $processEnvironment.Contains($name)
8486
$savedEnv[$name] = [pscustomobject]@{
8587
Exists = $exists
@@ -806,14 +808,14 @@ try {
806808
Description = 'curl trusts the injected CA and observes the OpenShell HTTPS proxy certificate'
807809
}
808810
}
809-
if ($Scenario -in @('socket-owner-allow', 'socket-owner-deny')) {
811+
if ($Scenario -in @('socket-owner-allow', 'socket-owner-normalized', 'socket-owner-normalized-default', 'socket-owner-deny')) {
810812
$allScenarios += @{
811813
Name = $Scenario; PolicyFile = Join-Path $policyDir 'https-ca.yaml'
812814
SandboxId = 'own'; Backends = 'process_container'; Kind = 'socket-owner'
813815
PosTarget = Join-Path $DemoDir 'example.html'
814816
ControlTarget = Join-Path $DemoDir 'owner-launched.txt'
815817
ErrorTarget = Join-Path $DemoDir 'curl-stderr.txt'
816-
ExpectAllowed = ($Scenario -eq 'socket-owner-allow')
818+
ExpectAllowed = ($Scenario -in @('socket-owner-allow', 'socket-owner-normalized'))
817819
Description = 'network policy follows child curl rather than parent cmd'
818820
}
819821
}
@@ -890,10 +892,18 @@ try {
890892
}
891893
$policyText = $policyText.Replace('__HOST_SERVICE_PORT__', "$hostPort")
892894
}
893-
# Preserve the exact Windows executable path used in the launch;
894-
# network binary identities are compared as strings, not FS paths.
895-
$policyText = $policyText.Replace('__CURL_EXE__', $curlExe.Replace("'", "''"))
896-
if ($sc.Kind -eq 'socket-owner' -and -not $sc.ExpectAllowed) {
895+
# The normalization regression changes only the policy spelling;
896+
# the launched executable and its hash retain their original path.
897+
$policyCurlExe = $curlExe
898+
Remove-Item Env:OPENSHELL_WINDOWS_BINARY_PATH_NORMALIZATION -ErrorAction SilentlyContinue
899+
if ($sc.Name -eq 'socket-owner-normalized') {
900+
$env:OPENSHELL_WINDOWS_BINARY_PATH_NORMALIZATION = '1'
901+
}
902+
if ($sc.Name -in @('socket-owner-normalized', 'socket-owner-normalized-default')) {
903+
$policyCurlExe = $curlExe.Replace('\', '/').ToUpperInvariant()
904+
}
905+
$policyText = $policyText.Replace('__CURL_EXE__', $policyCurlExe.Replace("'", "''"))
906+
if ($sc.Name -eq 'socket-owner-deny') {
897907
$policyText = $policyText.Replace($curlExe, $cmdExe)
898908
}
899909
Set-Content -Path $policyUsed -Value $policyText -Encoding UTF8

‎crates/openshell-driver-mxc/tests/wxc_exec_real.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,12 @@ fn pc_proxy_scopes_network_policy_to_socket_owner() {
331331
let wxc = wxc_path().expect("real MXC socket-owner qualification requires wxc-exec");
332332
probe_processcontainer(&wxc).expect("native ProcessContainer must be live");
333333
probe_processcontainer_host_loopback(&wxc).expect("native governed loopback must be available");
334-
for scenario in ["socket-owner-allow", "socket-owner-deny"] {
334+
for scenario in [
335+
"socket-owner-allow",
336+
"socket-owner-normalized",
337+
"socket-owner-normalized-default",
338+
"socket-owner-deny",
339+
] {
335340
let directory = tempfile::tempdir().unwrap();
336341
let repo = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..");
337342
let target = if cfg!(target_arch = "aarch64") {

‎crates/openshell-supervisor-network/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
This crate forbids unsafe code, including its local tests. Typed socket APIs
44
provide original-destination lookup for transparent proxying.
55

6+
Windows binary policy preserves existing matching by default. If the supervisor
7+
opts in to normalization, ordinary drive paths support separator equivalence.
8+
ASCII case folding requires trusted directory evidence from
9+
`openshell-binary-identity`. The L4 decision carries that evidence into its
10+
generation-pinned L7 evaluator. The integrity cache reserves a single pin across
11+
potential case aliases in this mode, including when directory evidence is
12+
unavailable. Hashing still opens the original path.
13+
14+
The Windows glob matcher already accepts either separator in wildcard rules.
15+
Shared normalization also covers exact rules, and trusted case evidence applies
16+
to both forms. MXC filesystem-grant normalization and socket-owner attribution
17+
remain separate from these network-policy comparisons.
18+
619
Socket attribution tests pass a duplicate connected socket as a spawned child's
720
stdin. Re-executing the test binary checks multiple holders with the same binary
821
identity; executing a different binary checks ambiguous shared-socket identity.

‎crates/openshell-supervisor-network/data/sandbox-policy.rego‎

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,34 +141,69 @@ binary_allowed(_, _) if {
141141
not binary_identity_required
142142
}
143143

144+
# Binary path matching uses exact spelling by default. On Windows, Rust adds an
145+
# ASCII-folded candidate only after querying every parent directory of the
146+
# runtime-observed executable and confirming case-insensitive lookup throughout.
147+
binary_path_matches(binary, candidate) if {
148+
binary.windows_path == candidate.path
149+
}
150+
151+
binary_path_matches(binary, candidate) if {
152+
candidate.ascii_case_folded != ""
153+
binary.ascii_case_folded_path == candidate.ascii_case_folded
154+
}
155+
156+
binary_glob_matches(binary, candidate) if {
157+
glob.match(binary.windows_path, ["/"], candidate.path)
158+
}
159+
160+
binary_glob_matches(binary, candidate) if {
161+
candidate.ascii_case_folded != ""
162+
glob.match(binary.ascii_case_folded_path, ["/"], candidate.ascii_case_folded)
163+
}
164+
144165
# Binary matching: exact path.
145166
# SHA256 integrity is enforced in Rust via trust-on-first-use (TOFU) cache,
146167
# not in Rego. The proxy computes and caches binary hashes at runtime.
147168
binary_allowed(policy, exec) if {
148-
some b
149-
b := policy.binaries[_]
169+
some b in policy.binaries
150170
not contains(b.path, "*")
151171
b.path == exec.path
152172
}
153173

154174
# Binary matching: ancestor exact path (e.g., claude spawns node).
155175
binary_allowed(policy, exec) if {
156-
some b
157-
b := policy.binaries[_]
176+
some b in policy.binaries
158177
not contains(b.path, "*")
159-
ancestor := exec.ancestors[_]
178+
some ancestor in exec.ancestors
160179
b.path == ancestor
161180
}
162181

182+
# An opted-in Windows runtime can supply alternate path spellings. Other
183+
# runtimes and default Windows configurations only use the original path.
184+
binary_allowed(policy, exec) if {
185+
some b in policy.binaries
186+
not contains(b.path, "*")
187+
some candidate in exec.match_paths
188+
binary_path_matches(b, candidate)
189+
}
190+
163191
# Binary matching: glob pattern against exe path or any ancestor.
164192
# NOTE: cmdline_paths are intentionally excluded — argv[0] is trivially
165193
# spoofable via execve and must not be used as a grant-access signal.
166194
binary_allowed(policy, exec) if {
167195
some b in policy.binaries
168196
contains(b.path, "*")
169197
all_paths := array.concat([exec.path], exec.ancestors)
170-
some p in all_paths
171-
glob.match(b.path, ["/"], p)
198+
some path in all_paths
199+
glob.match(b.path, ["/"], path)
200+
}
201+
202+
binary_allowed(policy, exec) if {
203+
some b in policy.binaries
204+
contains(b.path, "*")
205+
some candidate in exec.match_paths
206+
binary_glob_matches(b, candidate)
172207
}
173208

174209
# --- Network action (allow / deny) ---

‎crates/openshell-supervisor-network/src/identity.rs‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,20 @@ impl BinaryIdentityCache {
133133
self.verify_or_cache_with_paths(path, path, procfs::file_sha256)
134134
}
135135

136+
#[cfg(test)]
137+
pub(crate) fn verify_or_cache_supplied_identity(
138+
&self,
139+
identity: &BinaryIdentity,
140+
) -> std::result::Result<(), SuppliedIdentityError> {
141+
self.verify_or_cache_supplied_identity_with_path_normalization(identity, false)
142+
}
143+
136144
/// Atomically verify or pin every authorization-capable executable in a
137145
/// backend-supplied identity chain.
138-
pub(crate) fn verify_or_cache_supplied_identity(
146+
pub(crate) fn verify_or_cache_supplied_identity_with_path_normalization(
139147
&self,
140148
identity: &BinaryIdentity,
149+
normalize_windows_paths: bool,
141150
) -> std::result::Result<(), SuppliedIdentityError> {
142151
let mut supplied = HashMap::new();
143152
for executable in std::iter::once(&identity.executable).chain(&identity.ancestors) {
@@ -153,8 +162,21 @@ impl BinaryIdentityCache {
153162
executable.path.display()
154163
))
155164
})?;
156-
if let Some(existing) = supplied.insert(executable.path.clone(), digest)
157-
&& existing != digest
165+
let path = &executable.path;
166+
// Reserve one pin for all potential case aliases in opt-in mode.
167+
// A failed directory query or changed directory flag must not create
168+
// a fresh pin. Policy admission still requires directory evidence.
169+
let key = if cfg!(windows)
170+
&& normalize_windows_paths
171+
&& openshell_binary_identity::is_ordinary_windows_drive_path(
172+
path.as_os_str().as_encoded_bytes(),
173+
) {
174+
PathBuf::from(path.as_os_str().to_ascii_lowercase())
175+
} else {
176+
path.clone()
177+
};
178+
if let Some(existing) = supplied.insert(key, (digest, path))
179+
&& existing.0 != digest
158180
{
159181
return Err(SuppliedIdentityError::Unavailable(format!(
160182
"Invalid executable identity: conflicting evidence for {}",
@@ -167,8 +189,8 @@ impl BinaryIdentityCache {
167189
SuppliedIdentityError::Unavailable("Binary identity cache lock poisoned".to_string())
168190
})?;
169191

170-
for (path, digest) in &supplied {
171-
if let Some(existing) = hashes.get(path)
192+
for (key, (digest, path)) in &supplied {
193+
if let Some(existing) = hashes.get(key)
172194
&& existing.hash != digest.to_string()
173195
{
174196
return Err(SuppliedIdentityError::Unavailable(format!(
@@ -186,8 +208,8 @@ impl BinaryIdentityCache {
186208
return Err(SuppliedIdentityError::CapacityExhausted);
187209
}
188210

189-
for (path, digest) in supplied {
190-
hashes.entry(path).or_insert_with(|| CachedBinary {
211+
for (key, (digest, _)) in supplied {
212+
hashes.entry(key).or_insert_with(|| CachedBinary {
191213
hash: digest.to_string(),
192214
fingerprint: None,
193215
});

0 commit comments

Comments
 (0)