@@ -318,6 +318,10 @@ struct RunArgs {
318318 ) ]
319319 server_sans : Vec < String > ,
320320
321+ /// Authenticate sandbox application requests using configured gateway auth.
322+ #[ arg( long, env = "OPENSHELL_SERVICE_AUTH_ENABLED" , default_value_t = false , action = ArgAction :: Set ) ]
323+ service_auth_enabled : bool ,
324+
321325 /// Hostname format for exposed sandbox services: `readable` (default)
322326 /// keeps `<workspace>--<sandbox>[--<service>]` hostnames; `hashed` mints
323327 /// opaque one-label hostnames discriminated by the gateway installation
@@ -646,6 +650,7 @@ fn prepare_server_config_with_drivers(
646650 )
647651 . with_server_sans ( args. server_sans . clone ( ) )
648652 . with_service_hostname_format ( args. service_hostname_format . unwrap_or_default ( ) )
653+ . with_service_auth ( args. service_auth_enabled )
649654 . with_loopback_service_http ( args. enable_loopback_service_http )
650655 . with_websocket_tunnel ( args. enable_websocket_tunnel ) ;
651656 config
@@ -1593,6 +1598,11 @@ fn merge_file_into_args(args: &mut RunArgs, file: &GatewayFileSection, matches:
15931598 {
15941599 args. service_hostname_format = Some ( * format) ;
15951600 }
1601+ if let Some ( enabled) = file. service_auth_enabled
1602+ && arg_defaulted ( matches, "service_auth_enabled" )
1603+ {
1604+ args. service_auth_enabled = enabled;
1605+ }
15961606 if let Some ( enabled) = file. enable_loopback_service_http
15971607 && arg_defaulted ( matches, "enable_loopback_service_http" )
15981608 {
@@ -4171,6 +4181,40 @@ enabled = false
41714181 } ) ;
41724182 }
41734183
4184+ #[ test]
4185+ fn service_auth_is_opt_in_with_explicit_cli_environment_and_file_precedence ( ) {
4186+ Environment :: new ( )
4187+ . remove ( "OPENSHELL_SERVICE_AUTH_ENABLED" )
4188+ . run ( || {
4189+ let file = toml:: from_str :: < ConfigFile > (
4190+ "[openshell.gateway]\n service_auth_enabled = true\n " ,
4191+ )
4192+ . unwrap ( ) ;
4193+ let ( mut args, matches) = parse_with_args ( & [ "openshell-gateway" ] ) ;
4194+ assert ! ( !args. service_auth_enabled) ;
4195+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4196+ assert ! ( args. service_auth_enabled) ;
4197+ let ( mut args, matches) =
4198+ parse_with_args ( & [ "openshell-gateway" , "--service-auth-enabled" , "false" ] ) ;
4199+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4200+ assert ! ( !args. service_auth_enabled) ;
4201+ } ) ;
4202+ Environment :: new ( )
4203+ . set ( "OPENSHELL_SERVICE_AUTH_ENABLED" , "false" )
4204+ . run ( || {
4205+ let file = toml:: from_str :: < ConfigFile > (
4206+ "[openshell.gateway]\n service_auth_enabled = true\n " ,
4207+ )
4208+ . unwrap ( ) ;
4209+ let ( mut args, matches) = parse_with_args ( & [ "openshell-gateway" ] ) ;
4210+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4211+ assert ! ( !args. service_auth_enabled) ;
4212+ let ( args, _) =
4213+ parse_with_args ( & [ "openshell-gateway" , "--service-auth-enabled" , "true" ] ) ;
4214+ assert ! ( args. service_auth_enabled) ;
4215+ } ) ;
4216+ }
4217+
41744218 #[ test]
41754219 fn operator_auth_is_opt_in_and_file_flag_precedence_is_explicit ( ) {
41764220 Environment :: new ( )
0 commit comments