@@ -702,6 +702,11 @@ pub async fn sandbox_create(
702702 ) ) ,
703703 await_main_process_attachment,
704704 workload_template : template. unwrap_or_default ( ) . to_string ( ) ,
705+ forward_ports : forward
706+ . as_ref ( )
707+ . map ( |spec| u32:: from ( spec. port ) )
708+ . into_iter ( )
709+ . collect ( ) ,
705710 service_exposures : expose
706711 . map ( |target_port| SandboxServiceExposure {
707712 service : String :: new ( ) ,
@@ -1688,6 +1693,33 @@ where
16881693 println ! ( " {} {}" , "Id:" . dimmed( ) , id) ;
16891694 println ! ( " {} {}" , "Name:" . dimmed( ) , name) ;
16901695 println ! ( " {} {}" , "Phase:" . dimmed( ) , phase_name( sandbox. phase( ) ) ) ;
1696+ if let Some ( ingress) = sandbox
1697+ . status
1698+ . as_ref ( )
1699+ . and_then ( |status| status. ingress_admission . as_ref ( ) )
1700+ {
1701+ let ports = if ingress. all_ports {
1702+ "all" . to_string ( )
1703+ } else {
1704+ ingress
1705+ . ports
1706+ . iter ( )
1707+ . map ( u32:: to_string)
1708+ . collect :: < Vec < _ > > ( )
1709+ . join ( ", " )
1710+ } ;
1711+ println ! (
1712+ " {} {}; ports: {ports}" ,
1713+ "Ingress:" . dimmed( ) ,
1714+ ingress_scope_name( ingress. scope)
1715+ ) ;
1716+ } else {
1717+ println ! (
1718+ " {} legacy driver (admission unavailable)" ,
1719+ "Ingress:" . dimmed( )
1720+ ) ;
1721+ }
1722+
16911723 if let Some ( status) = sandbox. status . as_ref ( ) {
16921724 for condition in & status. conditions {
16931725 if matches ! (
@@ -2169,8 +2201,12 @@ pub async fn service_forward_tcp(
21692201 let ( bind_addr, bind_port) = parse_tcp_forward_spec ( local, target_port) ?;
21702202 let mut client = grpc_client ( server, tls) . await ?;
21712203
2172- let mut replica = fetch_ready_sandbox_for_forward ( & mut client, name, workspace) . await ?;
2204+ let ( mut replica, scope) =
2205+ fetch_ready_sandbox_for_forward ( & mut client, name, workspace, target_port) . await ?;
21732206
2207+ if scope == openshell_core:: proto:: IngressScope :: SharedHostLoopback {
2208+ eprintln ! ( "Target is an admitted shared-host loopback service." ) ;
2209+ }
21742210 let listener = tokio:: net:: TcpListener :: bind ( ( bind_addr. as_str ( ) , bind_port) )
21752211 . await
21762212 . into_diagnostic ( )
@@ -2203,7 +2239,7 @@ pub async fn service_forward_tcp(
22032239 }
22042240
22052241 _ = health_check. tick( ) => {
2206- replica = fetch_ready_sandbox_for_forward( & mut client, name, workspace) . await ?;
2242+ replica = fetch_ready_sandbox_for_forward( & mut client, name, workspace, target_port ) . await ?. 0 ;
22072243 }
22082244
22092245 accepted = listener. accept( ) => {
@@ -2274,7 +2310,11 @@ async fn fetch_ready_sandbox_for_forward(
22742310 client : & mut crate :: tls:: GrpcClient ,
22752311 name : & str ,
22762312 workspace : & str ,
2277- ) -> Result < Option < AsciiMetadataValue > > {
2313+ target_port : u16 ,
2314+ ) -> Result < (
2315+ Option < AsciiMetadataValue > ,
2316+ openshell_core:: proto:: IngressScope ,
2317+ ) > {
22782318 let response = match client
22792319 . get_sandbox ( with_owner_hint ( GetSandboxRequest {
22802320 name : name. to_string ( ) ,
@@ -2307,7 +2347,17 @@ async fn fetch_ready_sandbox_for_forward(
23072347 ) ) ;
23082348 }
23092349
2310- Ok ( replica)
2350+ let scope = openshell_core:: ingress:: admit_port (
2351+ sandbox
2352+ . status
2353+ . as_ref ( )
2354+ . and_then ( |status| status. ingress_admission . as_ref ( ) ) ,
2355+ u32:: from ( target_port) ,
2356+ false ,
2357+ )
2358+ . map_err ( |error| miette:: miette!( "{error}" ) ) ?;
2359+
2360+ Ok ( ( replica, scope) )
23112361}
23122362
23132363#[ derive( Debug ) ]
@@ -3012,6 +3062,16 @@ fn configuration_failure_message(sandbox: &Sandbox) -> Option<&str> {
30123062 . filter ( |message| !message. is_empty ( ) )
30133063}
30143064
3065+ fn ingress_scope_name ( scope : i32 ) -> & ' static str {
3066+ use openshell_core:: proto:: IngressScope ;
3067+ match IngressScope :: try_from ( scope) {
3068+ Ok ( IngressScope :: IsolatedLoopback ) => "isolated_loopback" ,
3069+ Ok ( IngressScope :: SharedHostLoopback ) => "shared_host_loopback" ,
3070+ Ok ( IngressScope :: Unsupported ) => "unsupported" ,
3071+ Ok ( IngressScope :: Unspecified ) | Err ( _) => "unknown" ,
3072+ }
3073+ }
3074+
30153075fn sandbox_to_json ( sandbox : & Sandbox ) -> serde_json:: Value {
30163076 use openshell_core:: proto:: ConfigurationAdmissionState ;
30173077
@@ -3123,6 +3183,11 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
31233183 "conditions" : conditions,
31243184 "endpoint_statuses" : endpoint_statuses,
31253185 "last_token_grant_failure" : last_token_grant_failure,
3186+ "ingress_admission" : sandbox. status. as_ref( ) . and_then( |status| status. ingress_admission. as_ref( ) ) . map( |ingress| serde_json:: json!( {
3187+ "scope" : ingress_scope_name( ingress. scope) ,
3188+ "all_ports" : ingress. all_ports,
3189+ "ports" : ingress. ports,
3190+ } ) ) ,
31263191 "configuration_admission" : admission,
31273192 "provisioning" : provisioning,
31283193 "created_from_workload_template" : created_from_workload_template,
@@ -8829,6 +8894,37 @@ mod tests {
88298894 . error
88308895 . clear ( ) ;
88318896 assert_eq ! ( super :: configuration_failure_message( & sandbox) , None ) ;
8897+ assert ! ( super :: sandbox_to_json( & sandbox) [ "ingress_admission" ] . is_null( ) ) ;
8898+ for ( scope, expected) in [
8899+ (
8900+ openshell_core:: proto:: IngressScope :: IsolatedLoopback as i32 ,
8901+ "isolated_loopback" ,
8902+ ) ,
8903+ (
8904+ openshell_core:: proto:: IngressScope :: SharedHostLoopback as i32 ,
8905+ "shared_host_loopback" ,
8906+ ) ,
8907+ (
8908+ openshell_core:: proto:: IngressScope :: Unsupported as i32 ,
8909+ "unsupported" ,
8910+ ) ,
8911+ ( 0 , "unknown" ) ,
8912+ ( 99 , "unknown" ) ,
8913+ ] {
8914+ sandbox. status . as_mut ( ) . unwrap ( ) . ingress_admission =
8915+ Some ( openshell_core:: proto:: SandboxIngressAdmission {
8916+ scope,
8917+ ports : vec ! [ 8080 ] ,
8918+ all_ports : false ,
8919+ } ) ;
8920+ let output = super :: sandbox_to_json ( & sandbox) ;
8921+ assert_eq ! ( output[ "ingress_admission" ] [ "scope" ] , expected) ;
8922+ assert_eq ! (
8923+ output[ "ingress_admission" ] [ "ports" ] ,
8924+ serde_json:: json!( [ 8080 ] )
8925+ ) ;
8926+ assert_eq ! ( output[ "ingress_admission" ] [ "all_ports" ] , false ) ;
8927+ }
88328928 }
88338929
88348930 #[ test]
0 commit comments