@@ -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
@@ -1552,6 +1557,11 @@ fn merge_file_into_args(args: &mut RunArgs, file: &GatewayFileSection, matches:
15521557 {
15531558 args. service_hostname_format = Some ( * format) ;
15541559 }
1560+ if let Some ( enabled) = file. service_auth_enabled
1561+ && arg_defaulted ( matches, "service_auth_enabled" )
1562+ {
1563+ args. service_auth_enabled = enabled;
1564+ }
15551565 if let Some ( enabled) = file. enable_loopback_service_http
15561566 && arg_defaulted ( matches, "enable_loopback_service_http" )
15571567 {
@@ -4127,6 +4137,40 @@ enabled = false
41274137 } ) ;
41284138 }
41294139
4140+ #[ test]
4141+ fn service_auth_is_opt_in_with_explicit_cli_environment_and_file_precedence ( ) {
4142+ Environment :: new ( )
4143+ . remove ( "OPENSHELL_SERVICE_AUTH_ENABLED" )
4144+ . run ( || {
4145+ let file = toml:: from_str :: < ConfigFile > (
4146+ "[openshell.gateway]\n service_auth_enabled = true\n " ,
4147+ )
4148+ . unwrap ( ) ;
4149+ let ( mut args, matches) = parse_with_args ( & [ "openshell-gateway" ] ) ;
4150+ assert ! ( !args. service_auth_enabled) ;
4151+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4152+ assert ! ( args. service_auth_enabled) ;
4153+ let ( mut args, matches) =
4154+ parse_with_args ( & [ "openshell-gateway" , "--service-auth-enabled" , "false" ] ) ;
4155+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4156+ assert ! ( !args. service_auth_enabled) ;
4157+ } ) ;
4158+ Environment :: new ( )
4159+ . set ( "OPENSHELL_SERVICE_AUTH_ENABLED" , "false" )
4160+ . run ( || {
4161+ let file = toml:: from_str :: < ConfigFile > (
4162+ "[openshell.gateway]\n service_auth_enabled = true\n " ,
4163+ )
4164+ . unwrap ( ) ;
4165+ let ( mut args, matches) = parse_with_args ( & [ "openshell-gateway" ] ) ;
4166+ merge_file_into_args ( & mut args, & file. openshell . gateway , & matches) ;
4167+ assert ! ( !args. service_auth_enabled) ;
4168+ let ( args, _) =
4169+ parse_with_args ( & [ "openshell-gateway" , "--service-auth-enabled" , "true" ] ) ;
4170+ assert ! ( args. service_auth_enabled) ;
4171+ } ) ;
4172+ }
4173+
41304174 #[ test]
41314175 fn operator_auth_is_opt_in_and_file_flag_precedence_is_explicit ( ) {
41324176 Environment :: new ( )
0 commit comments