@@ -354,6 +354,7 @@ pub struct EgressAuthorization {
354354}
355355
356356/// Input for a network access policy evaluation.
357+ #[ derive( Clone , Debug ) ]
357358pub struct NetworkInput {
358359 pub host : String ,
359360 pub port : u16 ,
@@ -367,12 +368,20 @@ pub struct NetworkInput {
367368 pub cmdline_paths : Vec < PathBuf > ,
368369}
369370
371+ /// Backend-owned validation of an established connection across policy publications.
372+ /// Implementations must reject any intervening narrowing, including quarantines.
373+ pub trait ConnectionRevalidator : std:: fmt:: Debug + Send + Sync {
374+ fn follow ( & self , pin : & AtomicU64 , live : & AtomicU64 ) -> bool ;
375+ fn pinned_policy_hash ( & self , generation : u64 ) -> Option < String > ;
376+ }
377+
370378/// Generation guard captured when an HTTP tunnel or request path starts.
371379#[ derive( Clone , Debug ) ]
372380pub struct PolicyGenerationGuard {
373- captured_generation : u64 ,
381+ captured_generation : Arc < AtomicU64 > ,
374382 current_generation : Arc < AtomicU64 > ,
375383 generation_rx : watch:: Receiver < u64 > ,
384+ revalidator : Option < Arc < dyn ConnectionRevalidator > > ,
376385}
377386
378387/// Builds a [`PolicyGenerationGuard`] for any state holding a plain
@@ -398,23 +407,40 @@ pub fn generation_guard_for(
398407 ) ) ;
399408 }
400409 Ok ( PolicyGenerationGuard {
401- captured_generation : current_generation_value,
410+ captured_generation : Arc :: new ( AtomicU64 :: new ( current_generation_value) ) ,
402411 current_generation : Arc :: clone ( current_generation) ,
403412 generation_rx : generation_tx. subscribe ( ) ,
413+ revalidator : None ,
404414 } )
405415}
406416
407417impl PolicyGenerationGuard {
418+ /// Attach a backend-owned connection contract. Ordinary guards remain strict.
419+ #[ must_use]
420+ pub fn with_revalidator ( mut self , revalidator : Option < Arc < dyn ConnectionRevalidator > > ) -> Self {
421+ self . revalidator = revalidator;
422+ self
423+ }
424+
425+ pub fn pinned_policy_hash ( & self ) -> Option < String > {
426+ self . revalidator
427+ . as_ref ( ) ?
428+ . pinned_policy_hash ( self . captured_generation ( ) )
429+ }
430+
408431 pub fn captured_generation ( & self ) -> u64 {
409- self . captured_generation
432+ self . captured_generation . load ( Ordering :: Acquire )
410433 }
411434
412435 pub fn current_generation ( & self ) -> u64 {
413436 self . current_generation . load ( Ordering :: Acquire )
414437 }
415438
416439 pub fn is_stale ( & self ) -> bool {
417- self . current_generation ( ) != self . captured_generation
440+ self . revalidator . as_ref ( ) . map_or_else (
441+ || self . current_generation ( ) != self . captured_generation ( ) ,
442+ |revalidator| !revalidator. follow ( & self . captured_generation , & self . current_generation ) ,
443+ )
418444 }
419445
420446 pub fn ensure_current ( & self ) -> Result < ( ) > {
@@ -428,10 +454,10 @@ impl PolicyGenerationGuard {
428454 Ok ( ( ) )
429455 }
430456
431- /// Wait until the policy generation changes .
457+ /// Wait until the authorizing policy no longer applies .
432458 ///
433- /// Relay boundaries use this to close even an idle or raw stream as soon
434- /// as a new generation (including fail-closed quarantine) is published .
459+ /// Plain guards close on every publication; connection guards may follow
460+ /// unrelated changes, but must close on a quarantine or relevant narrowing .
435461 pub async fn wait_until_stale ( & self ) {
436462 let mut receiver = self . generation_rx . clone ( ) ;
437463 while !self . is_stale ( ) {
0 commit comments