@@ -689,30 +689,44 @@ fn sanitize_reason_for_audit(raw: &str) -> String {
689689}
690690
691691/// One-line audit description of a chunk's target: binary, host, port, and
692- /// L7 method/path if present . Used by both the propose and approve/reject
693- /// audit events so the trace can be grepped by endpoint without parsing
694- /// JSON.
692+ /// L7 method/path allows for every endpoint . Used by both the propose and
693+ /// approve/reject audit events so the trace can be grepped by endpoint
694+ /// without parsing JSON.
695695fn summarize_chunk_for_audit ( chunk : & PolicyChunk ) -> String {
696696 let Some ( rule) = chunk. proposed_rule . as_ref ( ) else {
697697 return format ! ( "rule_name:{}" , chunk. rule_name) ;
698698 } ;
699- let endpoint = rule. endpoints . first ( ) . map_or_else (
700- || "unknown" . to_string ( ) ,
701- |ep| format ! ( "{}:{}" , ep. host, ep. port) ,
702- ) ;
703- let l7 = rule
704- . endpoints
705- . first ( )
706- . and_then ( |ep| ep. rules . first ( ) )
707- . and_then ( |r| r. allow . as_ref ( ) )
708- . map ( |a| format ! ( " {} {}" , a. method, a. path) )
709- . unwrap_or_default ( ) ;
699+ let endpoints = if rule. endpoints . is_empty ( ) {
700+ "unknown" . to_string ( )
701+ } else {
702+ rule. endpoints
703+ . iter ( )
704+ . map ( summarize_endpoint_for_audit)
705+ . collect :: < Vec < _ > > ( )
706+ . join ( ", " )
707+ } ;
710708 let binary = if chunk. binary . is_empty ( ) {
711709 String :: new ( )
712710 } else {
713711 format ! ( " by {}" , chunk. binary)
714712 } ;
715- format ! ( "on {endpoint}{l7}{binary}" )
713+ format ! ( "on {endpoints}{binary}" )
714+ }
715+
716+ fn summarize_endpoint_for_audit ( endpoint : & NetworkEndpoint ) -> String {
717+ let allows = endpoint
718+ . rules
719+ . iter ( )
720+ . filter_map ( |r| r. allow . as_ref ( ) )
721+ . map ( |a| format ! ( "{} {}" , a. method, a. path) )
722+ . collect :: < Vec < _ > > ( )
723+ . join ( ", " ) ;
724+ let target = format ! ( "{}:{}" , endpoint. host, endpoint. port) ;
725+ if allows. is_empty ( ) {
726+ target
727+ } else {
728+ format ! ( "{target} [{allows}]" )
729+ }
716730}
717731
718732/// `GET /v1/proposals/{chunk_id}` — immediate state. One gateway call, no loop.
@@ -2053,6 +2067,42 @@ mod tests {
20532067 assert ! ( summary. contains( "/usr/bin/curl" ) ) ;
20542068 }
20552069
2070+ #[ test]
2071+ fn summarize_chunk_for_audit_lists_every_endpoint_and_allow ( ) {
2072+ let allow = |method : & str , path : & str | L7Rule {
2073+ allow : Some ( L7Allow {
2074+ method : method. to_string ( ) ,
2075+ path : path. to_string ( ) ,
2076+ ..Default :: default ( )
2077+ } ) ,
2078+ } ;
2079+ let chunk = PolicyChunk {
2080+ binary : "/usr/bin/perl" . to_string ( ) ,
2081+ proposed_rule : Some ( NetworkPolicyRule {
2082+ name : "two" . to_string ( ) ,
2083+ endpoints : vec ! [
2084+ NetworkEndpoint {
2085+ host: "ports.ubuntu.com" . to_string( ) ,
2086+ port: 80 ,
2087+ rules: vec![ allow( "GET" , "/ubuntu-ports/**" ) , allow( "HEAD" , "/x" ) ] ,
2088+ ..Default :: default ( )
2089+ } ,
2090+ NetworkEndpoint {
2091+ host: "169.254.169.254" . to_string( ) ,
2092+ port: 80 ,
2093+ ..Default :: default ( )
2094+ } ,
2095+ ] ,
2096+ ..Default :: default ( )
2097+ } ) ,
2098+ ..Default :: default ( )
2099+ } ;
2100+ assert_eq ! (
2101+ summarize_chunk_for_audit( & chunk) ,
2102+ "on ports.ubuntu.com:80 [GET /ubuntu-ports/**, HEAD /x], 169.254.169.254:80 by /usr/bin/perl"
2103+ ) ;
2104+ }
2105+
20562106 // Helpers — synthetic proposed rule + policy with that rule already
20572107 // merged. Both reused across reload-readiness tests.
20582108 fn proposed_curl_rule_for_github ( ) -> NetworkPolicyRule {
0 commit comments