@@ -312,6 +312,10 @@ struct RunArgs {
312312 ) ]
313313 server_sans : Vec < String > ,
314314
315+ /// Authenticate sandbox application requests using configured gateway auth.
316+ #[ arg( long, env = "OPENSHELL_SERVICE_AUTH_ENABLED" , default_value_t = false , action = ArgAction :: Set ) ]
317+ service_auth_enabled : bool ,
318+
315319 /// Hostname format for exposed sandbox services: `readable` (default)
316320 /// keeps `<workspace>--<sandbox>[--<service>]` hostnames; `hashed` mints
317321 /// opaque one-label hostnames discriminated by the gateway installation
@@ -628,6 +632,7 @@ fn prepare_server_config_with_drivers(
628632 )
629633 . with_server_sans ( args. server_sans . clone ( ) )
630634 . with_service_hostname_format ( args. service_hostname_format . unwrap_or_default ( ) )
635+ . with_service_auth ( args. service_auth_enabled )
631636 . with_loopback_service_http ( args. enable_loopback_service_http )
632637 . with_websocket_tunnel ( args. enable_websocket_tunnel ) ;
633638 config
@@ -1508,6 +1513,11 @@ fn merge_file_into_args(args: &mut RunArgs, file: &GatewayFileSection, matches:
15081513 {
15091514 args. service_hostname_format = Some ( * format) ;
15101515 }
1516+ if let Some ( enabled) = file. service_auth_enabled
1517+ && arg_defaulted ( matches, "service_auth_enabled" )
1518+ {
1519+ args. service_auth_enabled = enabled;
1520+ }
15111521 if let Some ( enabled) = file. enable_loopback_service_http
15121522 && arg_defaulted ( matches, "enable_loopback_service_http" )
15131523 {
@@ -4059,6 +4069,40 @@ enabled = false
40594069 } ) ;
40604070 }
40614071
4072+ #[ test]
4073+ fn service_auth_is_opt_in_with_explicit_cli_environment_and_file_precedence ( ) {
4074+ Environment :: new ( )
4075+ . remove ( "OPENSHELL_SERVICE_AUTH_ENABLED" )
4076+ . run ( || {
4077+ let file = toml:: from_str :: < ConfigFile > (
4078+ "[openshell.gateway]\n service_auth_enabled = true\n " ,
4079+ )
4080+ . unwrap ( ) ;
4081+ let ( mut args, matches) = parse_with_args ( & [ "openshell-gateway" ] ) ;
4082+ assert ! ( !args. service_auth_enabled) ;
4083+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4084+ assert ! ( args. service_auth_enabled) ;
4085+ let ( mut args, matches) =
4086+ parse_with_args ( & [ "openshell-gateway" , "--service-auth-enabled" , "false" ] ) ;
4087+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4088+ assert ! ( !args. service_auth_enabled) ;
4089+ } ) ;
4090+ Environment :: new ( )
4091+ . set ( "OPENSHELL_SERVICE_AUTH_ENABLED" , "false" )
4092+ . run ( || {
4093+ let file = toml:: from_str :: < ConfigFile > (
4094+ "[openshell.gateway]\n service_auth_enabled = true\n " ,
4095+ )
4096+ . unwrap ( ) ;
4097+ let ( mut args, matches) = parse_with_args ( & [ "openshell-gateway" ] ) ;
4098+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4099+ assert ! ( !args. service_auth_enabled) ;
4100+ let ( args, _) =
4101+ parse_with_args ( & [ "openshell-gateway" , "--service-auth-enabled" , "true" ] ) ;
4102+ assert ! ( args. service_auth_enabled) ;
4103+ } ) ;
4104+ }
4105+
40624106 #[ test]
40634107 fn operator_auth_is_opt_in_and_file_flag_precedence_is_explicit ( ) {
40644108 Environment :: new ( )
0 commit comments