Skip to content

Commit 32ea316

Browse files
committed
fix(network): preserve sandbox context with socket owners
Signed-off-by: Prekshi Vyas <[email protected]>
1 parent 1b35898 commit 32ea316

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ mod tests {
308308
#[test]
309309
fn host_proxy_event_context_uses_configured_sandbox_identity() {
310310
let bind_addr = "127.0.0.1:18080".parse().unwrap();
311-
let config = test_config(bind_addr, PathBuf::from("agent.exe"));
311+
let config = test_config(bind_addr);
312312

313313
let context = host_proxy_event_context(&config).unwrap();
314314

@@ -320,10 +320,7 @@ mod tests {
320320

321321
#[test]
322322
fn host_proxy_event_context_rejects_missing_sandbox_identity() {
323-
let mut config = test_config(
324-
"127.0.0.1:18080".parse().unwrap(),
325-
PathBuf::from("agent.exe"),
326-
);
323+
let mut config = test_config("127.0.0.1:18080".parse().unwrap());
327324
config.sandbox_id = Some(" ".to_string());
328325

329326
let error = host_proxy_event_context(&config).unwrap_err();

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ pub(crate) enum ProxyIdentityMode {
172172
Windows {
173173
identity_cache: Arc<BinaryIdentityCache>,
174174
required_proxy_authorization: Option<Arc<str>>,
175+
/// Per-sandbox context for host-side proxies. The process-wide OCSF
176+
/// context cannot identify one sandbox when a gateway hosts many.
177+
event_context: Option<Arc<EventContext>>,
175178
},
176179
/// Static fallback for platforms without socket-owner resolution and for
177180
/// tests that need to inject a deterministic identity.
@@ -203,6 +206,7 @@ impl ProxyIdentityMode {
203206
Self::Windows {
204207
identity_cache: Arc::new(BinaryIdentityCache::new()),
205208
required_proxy_authorization,
209+
event_context: None,
206210
}
207211
}
208212

@@ -229,8 +233,10 @@ impl ProxyIdentityMode {
229233
#[cfg(target_os = "windows")]
230234
pub(super) fn with_event_context(mut self, context: EventContext) -> Self {
231235
match &mut self {
232-
#[cfg(target_os = "linux")]
233-
Self::Procfs { .. } => {}
236+
Self::Windows { event_context, .. } => {
237+
*event_context = Some(Arc::new(context));
238+
}
239+
#[cfg(test)]
234240
Self::Static { event_context, .. } => {
235241
*event_context = Some(Arc::new(context));
236242
}
@@ -240,7 +246,12 @@ impl ProxyIdentityMode {
240246

241247
fn event_context(&self) -> &EventContext {
242248
match self {
243-
#[cfg(any(not(target_os = "linux"), test))]
249+
#[cfg(target_os = "windows")]
250+
Self::Windows {
251+
event_context: Some(context),
252+
..
253+
} => context,
254+
#[cfg(any(not(any(target_os = "linux", target_os = "windows")), test))]
244255
Self::Static {
245256
event_context: Some(context),
246257
..
@@ -7417,6 +7428,16 @@ network_policies:
74177428
validate_required_fields(&sandbox_b, &schema);
74187429
}
74197430

7431+
#[cfg(target_os = "windows")]
7432+
#[test]
7433+
fn windows_socket_owner_identity_keeps_per_proxy_sandbox_attribution() {
7434+
let identity = ProxyIdentityMode::windows_with_client_auth(None)
7435+
.with_event_context(proxy_event_context("sandbox-a-id", "sandbox-a"));
7436+
7437+
assert_eq!(identity.event_context().sandbox_id, "sandbox-a-id");
7438+
assert_eq!(identity.event_context().sandbox_name, "sandbox-a");
7439+
}
7440+
74207441
#[test]
74217442
fn forward_l7_parse_rejection_ocsf_includes_denial_context() {
74227443
let event = build_forward_l7_parse_rejection_ocsf_event(

0 commit comments

Comments
 (0)