@@ -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