@@ -347,45 +347,62 @@ pub struct ServiceRoutingConfig {
347347 /// HTTP for sandbox service hostnames.
348348 pub enable_loopback_service_http : bool ,
349349
350- /// Optional gateway name used to derive opaque hashed service route
351- /// labels.
350+ /// Format used for newly generated service hostnames.
352351 ///
353- /// When `None` (the default), the gateway keeps generating readable
354- /// `<workspace>--<sandbox>[--<service>]` service hostnames. When set,
355- /// newly generated service hostnames use a stable, one-label hash derived
356- /// from this name plus the workspace, sandbox, and service instead.
357- ///
358- /// This value is unrelated to [`Config::name`] and
359- /// [`GatewayJwtConfig::gateway_id`]; it is never derived from them.
360- pub service_routing_gateway_name : Option < String > ,
352+ /// `Readable` (the default) generates
353+ /// `<workspace>--<sandbox>[--<service>]` hostnames. `Hashed` generates a
354+ /// stable, one-label opaque hash derived from the gateway installation
355+ /// name plus the workspace, sandbox, and service — see
356+ /// [`Config::service_routing_discriminator`].
357+ pub service_hostname_format : ServiceHostnameFormat ,
361358}
362359
363- impl ServiceRoutingConfig {
364- /// Validate the service-routing configuration.
365- ///
366- /// Currently validates [`Self::service_routing_gateway_name`]: `None` is
367- /// always valid, while `Some(name)` must be a DNS-1123 label — 1–63 ASCII
368- /// bytes of lowercase `a-z`, `0-9`, or `-`, with no leading or trailing
369- /// `-`. An empty string is rejected; the setting is represented as
370- /// disabled only by `None`.
371- pub fn validate ( & self ) -> crate :: error:: Result < ( ) > {
372- Self :: validate_gateway_name ( self . service_routing_gateway_name . as_deref ( ) )
360+ /// Format of exposed-service hostnames minted by the gateway.
361+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Serialize , Deserialize ) ]
362+ #[ serde( rename_all = "snake_case" ) ]
363+ pub enum ServiceHostnameFormat {
364+ /// Readable `<workspace>--<sandbox>[--<service>]` hostnames.
365+ #[ default]
366+ Readable ,
367+ /// Opaque one-label hashed hostnames, discriminated by the gateway
368+ /// installation name.
369+ Hashed ,
370+ }
371+
372+ impl FromStr for ServiceHostnameFormat {
373+ type Err = String ;
374+
375+ fn from_str ( value : & str ) -> Result < Self , Self :: Err > {
376+ match value {
377+ "readable" => Ok ( Self :: Readable ) ,
378+ "hashed" => Ok ( Self :: Hashed ) ,
379+ _ => Err ( format ! (
380+ "invalid service hostname format '{value}'; expected readable or hashed"
381+ ) ) ,
382+ }
373383 }
384+ }
374385
375- /// Validate an optional service-routing gateway name.
386+ impl ServiceRoutingConfig {
387+ /// Validate the service-routing configuration against the gateway
388+ /// installation name.
376389 ///
377- /// `None` is always valid. `Some(name)` must be a DNS-1123 label — 1–63
378- /// ASCII bytes of lowercase `a-z`, `0-9`, or `-`, with no leading or
379- /// trailing `-`. An empty string is rejected; the setting is represented
380- /// as disabled only by `None`.
381- pub fn validate_gateway_name ( name : Option < & str > ) -> crate :: error:: Result < ( ) > {
382- if let Some ( name) = name
383- && !is_dns_label ( name)
390+ /// When [`ServiceHostnameFormat::Hashed`] is selected, the installation
391+ /// name becomes the hash discriminator and must be a DNS-1123 label —
392+ /// 1–63 ASCII bytes of lowercase `a-z`, `0-9`, or `-`, with no leading or
393+ /// trailing `-`. It must also be unique among all gateways sharing the
394+ /// service base domain; that uniqueness is an operational contract the
395+ /// deploying platform is responsible for, since a single gateway cannot
396+ /// observe its siblings.
397+ pub fn validate ( & self , installation_name : & str ) -> crate :: error:: Result < ( ) > {
398+ if self . service_hostname_format == ServiceHostnameFormat :: Hashed
399+ && !is_dns_label ( installation_name)
384400 {
385401 return Err ( crate :: error:: Error :: Config {
386402 message : format ! (
387- "service_routing_gateway_name must be a DNS label (1-63 lowercase \
388- ASCII alphanumeric or '-' bytes, no leading/trailing '-'): {name:?}"
403+ "hashed service hostnames require the gateway installation name to be \
404+ a DNS label (1-63 lowercase ASCII alphanumeric or '-' bytes, no \
405+ leading/trailing '-'): {installation_name:?}"
389406 ) ,
390407 } ) ;
391408 }
@@ -1170,17 +1187,36 @@ impl Config {
11701187 self
11711188 }
11721189
1173- /// Set the service-routing gateway name used to derive hashed service
1174- /// route labels.
1190+ /// Select the hostname format for exposed sandbox services.
11751191 ///
1176- /// `None` preserves readable service hostnames. `Some(name)` must pass
1177- /// [`ServiceRoutingConfig::validate`].
1192+ /// [`ServiceHostnameFormat::Hashed`] derives its discriminator from the
1193+ /// gateway installation name ([`Config::name`]); see
1194+ /// [`Self::service_routing_discriminator`].
11781195 #[ must_use]
1179- pub fn with_service_routing_gateway_name ( mut self , name : Option < impl Into < String > > ) -> Self {
1180- self . service_routing . service_routing_gateway_name = name . map ( Into :: into ) ;
1196+ pub fn with_service_hostname_format ( mut self , format : ServiceHostnameFormat ) -> Self {
1197+ self . service_routing . service_hostname_format = format ;
11811198 self
11821199 }
11831200
1201+ /// The discriminator hashed into exposed-service hostnames when
1202+ /// [`ServiceHostnameFormat::Hashed`] is selected: the gateway
1203+ /// installation name.
1204+ ///
1205+ /// Returns `None` while readable hostnames are in use, in which case no
1206+ /// hashed service hosts exist. The name is an operator- or
1207+ /// platform-assigned value; it must be unique among all gateways sharing
1208+ /// the service base domain, an operational contract enforced by the
1209+ /// deploying platform rather than the gateway itself. Renaming the
1210+ /// installation changes every minted hostname.
1211+ ///
1212+ /// Unrelated to [`GatewayJwtConfig::gateway_id`], which carries security
1213+ /// and Kubernetes-ownership semantics.
1214+ #[ must_use]
1215+ pub fn service_routing_discriminator ( & self ) -> Option < & str > {
1216+ ( self . service_routing . service_hostname_format == ServiceHostnameFormat :: Hashed )
1217+ . then_some ( self . name . as_str ( ) )
1218+ }
1219+
11841220 /// Enable or disable plaintext HTTP routing for loopback sandbox service
11851221 /// hostnames on TLS-enabled gateway listeners.
11861222 #[ must_use]
@@ -1202,7 +1238,7 @@ impl Default for ServiceRoutingConfig {
12021238 Self {
12031239 base_domains : default_service_routing_domains ( ) ,
12041240 enable_loopback_service_http : default_enable_loopback_service_http ( ) ,
1205- service_routing_gateway_name : None ,
1241+ service_hostname_format : ServiceHostnameFormat :: default ( ) ,
12061242 }
12071243 }
12081244}
@@ -1281,8 +1317,8 @@ mod tests {
12811317 AppArmorProfile , Config , ConfigDeliveryMode , DEFAULT_SERVICE_ROUTING_DOMAIN ,
12821318 GatewayInterceptorBindingPolicy , GatewayInterceptorConfig , GatewayInterceptorFailurePolicy ,
12831319 GatewayJwtConfig , GatewayProviderProfileSourceConfig , ImagePullPolicy ,
1284- PolicyValidationFailureMode , UpstreamProxyConfig , default_sandbox_pids_limit ,
1285- normalize_compute_driver_name,
1320+ PolicyValidationFailureMode , ServiceHostnameFormat , UpstreamProxyConfig ,
1321+ default_sandbox_pids_limit , normalize_compute_driver_name,
12861322 } ;
12871323 use std:: net:: SocketAddr ;
12881324 use std:: time:: Duration ;
@@ -1758,28 +1794,31 @@ mod tests {
17581794 }
17591795
17601796 #[ test]
1761- fn service_routing_gateway_name_defaults_to_none ( ) {
1797+ fn service_hostname_format_defaults_to_readable ( ) {
17621798 let cfg = Config :: new ( None ) ;
1763- assert ! ( cfg. service_routing. service_routing_gateway_name. is_none( ) ) ;
1764- cfg. service_routing . validate ( ) . expect ( "unset is valid" ) ;
1799+ assert_eq ! (
1800+ cfg. service_routing. service_hostname_format,
1801+ ServiceHostnameFormat :: Readable
1802+ ) ;
1803+ assert_eq ! ( cfg. service_routing_discriminator( ) , None ) ;
1804+ cfg. service_routing
1805+ . validate ( "any name" )
1806+ . expect ( "readable is valid" ) ;
17651807 }
17661808
17671809 #[ test]
1768- fn service_routing_gateway_name_accepts_dns_label ( ) {
1769- for name in [ "gateway-west" , "g" , & "g" . repeat ( 63 ) , "gateway-1-west" ] {
1770- let cfg = Config :: new ( None ) . with_service_routing_gateway_name ( Some ( name) ) ;
1771- assert_eq ! (
1772- cfg. service_routing. service_routing_gateway_name. as_deref( ) ,
1773- Some ( name)
1774- ) ;
1775- cfg. service_routing
1776- . validate ( )
1777- . unwrap_or_else ( |e| panic ! ( "{name:?} must be valid: {e}" ) ) ;
1778- }
1810+ fn hashed_format_discriminates_on_the_installation_name ( ) {
1811+ let cfg = Config :: new ( None )
1812+ . with_name ( "gateway-west" )
1813+ . with_service_hostname_format ( ServiceHostnameFormat :: Hashed ) ;
1814+ assert_eq ! ( cfg. service_routing_discriminator( ) , Some ( "gateway-west" ) ) ;
1815+ cfg. service_routing
1816+ . validate ( "gateway-west" )
1817+ . expect ( "DNS-label installation name is valid" ) ;
17791818 }
17801819
17811820 #[ test]
1782- fn service_routing_gateway_name_rejects_empty_uppercase_invalid_hyphen_and_overlong_values ( ) {
1821+ fn hashed_format_requires_a_dns_label_installation_name ( ) {
17831822 for name in [
17841823 "" ,
17851824 "Gateway-West" ,
@@ -1789,25 +1828,30 @@ mod tests {
17891828 "gateway west" ,
17901829 & "g" . repeat ( 64 ) ,
17911830 ] {
1792- let cfg = Config :: new ( None ) . with_service_routing_gateway_name ( Some ( name) ) ;
1831+ let cfg = Config :: new ( None )
1832+ . with_name ( name)
1833+ . with_service_hostname_format ( ServiceHostnameFormat :: Hashed ) ;
17931834 let error = cfg
17941835 . service_routing
1795- . validate ( )
1836+ . validate ( name )
17961837 . expect_err ( & format ! ( "{name:?} must be rejected" ) ) ;
17971838 let message = error. to_string ( ) ;
1798- assert ! ( message. contains( "service_routing_gateway_name" ) , "{name:?}" ) ;
1839+ assert ! (
1840+ message. contains( "hashed service hostnames require" ) ,
1841+ "{name:?}: {message}"
1842+ ) ;
17991843 }
18001844 }
18011845
18021846 #[ test]
1803- fn server_sans_update_preserves_service_routing_gateway_name ( ) {
1847+ fn server_sans_update_preserves_service_hostname_format ( ) {
18041848 let cfg = Config :: new ( None )
1805- . with_service_routing_gateway_name ( Some ( "gateway-west" ) )
1849+ . with_service_hostname_format ( ServiceHostnameFormat :: Hashed )
18061850 . with_server_sans ( [ "*.apps.example.com" ] ) ;
18071851
18081852 assert_eq ! (
1809- cfg. service_routing. service_routing_gateway_name . as_deref ( ) ,
1810- Some ( "gateway-west" )
1853+ cfg. service_routing. service_hostname_format ,
1854+ ServiceHostnameFormat :: Hashed
18111855 ) ;
18121856 assert_eq ! (
18131857 cfg. service_routing. base_domains,
0 commit comments