@@ -1747,6 +1747,13 @@ pub async fn exchange_provider_subject_token(
17471747 ) )
17481748}
17491749
1750+ /// A dedicated supervisor's JWT-SVIDs for the provider and launch audiences.
1751+ #[ derive( Clone ) ]
1752+ pub struct ProviderWorkloadAssertions {
1753+ pub jwt_svid : String ,
1754+ pub launch_jwt_svid : String ,
1755+ }
1756+
17501757/// Final provider access tokens for one sandbox instance over one reused
17511758/// gateway channel.
17521759///
@@ -1782,19 +1789,37 @@ impl SandboxProviderTokenClient {
17821789 }
17831790 }
17841791
1785- /// Obtain only the final access token; the gateway selects and verifies
1786- /// the sandbox identity and resolves all grant parameters from its
1787- /// configuration.
1792+ /// Validate the gateway before fetching a local workload assertion.
1793+ /// A plaintext endpoint must identify loopback without DNS.
1794+ ///
1795+ /// # Errors
1796+ /// Returns a configuration failure for an invalid gateway URL or a
1797+ /// remote plaintext endpoint.
1798+ pub fn require_attested_transport ( & self ) -> std:: result:: Result < ( ) , TokenGrantFailure > {
1799+ let ( endpoint, _) = self . gateway . as_ref ( ) . map_err ( |failure| * failure) ?;
1800+ validate_attested_token_grant_transport ( endpoint)
1801+ }
1802+
1803+ /// Obtain the final access token. The gateway verifies the sandbox
1804+ /// identity and resolves grant parameters from its configuration.
1805+ /// A dedicated supervisor can supply its attested JWT-SVIDs.
17881806 ///
17891807 /// One deadline bounds connection readiness and the call. Network failures
17901808 /// do not serialize channel initialization for concurrent requests.
17911809 #[ tracing:: instrument( name = "supervisor.gateway.get_provider_access_token" , skip_all) ]
17921810 pub async fn get_access_token (
17931811 & self ,
17941812 credential_key : & str ,
1813+ assertions : Option < ProviderWorkloadAssertions > ,
17951814 request_id : Option < & str > ,
17961815 ) -> std:: result:: Result < ProviderSubjectTokenExchangeResult , TokenGrantFailure > {
17971816 let ( endpoint, gateway) = self . gateway . as_ref ( ) . map_err ( |failure| * failure) ?;
1817+ let ( jwt_svid, launch_jwt_svid) = if let Some ( assertions) = assertions {
1818+ self . require_attested_transport ( ) ?;
1819+ ( Some ( assertions. jwt_svid ) , Some ( assertions. launch_jwt_svid ) )
1820+ } else {
1821+ ( None , None )
1822+ } ;
17981823 // Like connect(), refuse locally revoked sandbox instance credentials
17991824 // before the call; the response boundary rejects them again.
18001825 let unavailable = || gateway_grant_failure ( TokenGrantFailureKind :: Unavailable ) ;
@@ -1805,6 +1830,8 @@ impl SandboxProviderTokenClient {
18051830 . ok_or_else ( || gateway_grant_failure ( TokenGrantFailureKind :: Configuration ) ) ?;
18061831 let mut request = tonic:: Request :: new ( crate :: proto:: GetSandboxProviderAccessTokenRequest {
18071832 credential_key : key,
1833+ jwt_svid,
1834+ launch_jwt_svid,
18081835 } ) ;
18091836 if let Some ( value) = request_id. and_then ( |value| value. parse ( ) . ok ( ) ) {
18101837 request. metadata_mut ( ) . insert ( "x-request-id" , value) ;
@@ -1886,6 +1913,23 @@ pub fn token_grant_gateway_endpoint(
18861913 Ok ( endpoint)
18871914}
18881915
1916+ /// Check the transport of an authority parsed by [`token_grant_gateway_endpoint`].
1917+ /// Plain HTTP is permitted only on a numeric loopback address.
1918+ pub fn validate_attested_token_grant_transport (
1919+ endpoint : & url:: Url ,
1920+ ) -> std:: result:: Result < ( ) , TokenGrantFailure > {
1921+ let direct_loopback = match endpoint. host ( ) {
1922+ Some ( url:: Host :: Ipv4 ( address) ) => address. is_loopback ( ) ,
1923+ Some ( url:: Host :: Ipv6 ( address) ) => address. is_loopback ( ) ,
1924+ _ => false ,
1925+ } ;
1926+ if endpoint. scheme ( ) == "https" || ( endpoint. scheme ( ) == "http" && direct_loopback) {
1927+ Ok ( ( ) )
1928+ } else {
1929+ Err ( gateway_grant_failure ( TokenGrantFailureKind :: Configuration ) )
1930+ }
1931+ }
1932+
18891933fn provider_subject_token_exchange_result (
18901934 inner : crate :: proto:: ExchangeProviderSubjectTokenResponse ,
18911935) -> std:: result:: Result < ProviderSubjectTokenExchangeResult , TokenGrantFailure > {
@@ -1993,8 +2037,8 @@ mod token_grant_exchange_tests {
19932037 ) ;
19942038 let started = tokio:: time:: Instant :: now ( ) ;
19952039 let results: [ _ ; 2 ] = tokio:: join!(
1996- client. get_access_token( "api.test\t 443\t /\t owner\t provider:token" , None ) ,
1997- client. get_access_token( "api.test\t 443\t /\t owner\t provider:token" , None ) ,
2040+ client. get_access_token( "api.test\t 443\t /\t owner\t provider:token" , None , None ) ,
2041+ client. get_access_token( "api.test\t 443\t /\t owner\t provider:token" , None , None ) ,
19982042 )
19992043 . into ( ) ;
20002044 for result in results {
@@ -2016,10 +2060,51 @@ mod token_grant_exchange_tests {
20162060 TokenSource :: Env ,
20172061 ) ,
20182062 ) ) ;
2019- let failure = invalid. get_access_token ( "key" , None ) . await . err ( ) . unwrap ( ) ;
2063+ let failure = invalid
2064+ . get_access_token ( "key" , None , None )
2065+ . await
2066+ . err ( )
2067+ . unwrap ( ) ;
20202068 assert_eq ! ( failure. kind( ) , TokenGrantFailureKind :: Configuration ) ;
20212069 }
20222070
2071+ #[ tokio:: test]
2072+ async fn access_token_client_keeps_assertions_off_nonlocal_plaintext ( ) {
2073+ let client = |url| {
2074+ SandboxProviderTokenClient :: new ( GatewayEndpoint :: new (
2075+ url,
2076+ GatewayCredentials :: new (
2077+ AsciiMetadataValue :: from_static ( "Bearer test" ) ,
2078+ TokenSource :: Env ,
2079+ ) ,
2080+ ) )
2081+ } ;
2082+ for url in [ "http://192.0.2.2:8080" , "http://localhost:8080" ] {
2083+ let client = client ( url) ;
2084+ let failure = client
2085+ . get_access_token (
2086+ "api.test\t 443\t /\t owner\t provider:token" ,
2087+ Some ( ProviderWorkloadAssertions {
2088+ jwt_svid : "oauth-assertion-canary" . into ( ) ,
2089+ launch_jwt_svid : "launch-assertion-canary" . into ( ) ,
2090+ } ) ,
2091+ None ,
2092+ )
2093+ . await
2094+ . err ( )
2095+ . expect ( "nonlocal plaintext must reject a workload assertion" ) ;
2096+ assert_eq ! ( failure. kind( ) , TokenGrantFailureKind :: Configuration ) ;
2097+ assert ! ( client. client. get( ) . is_none( ) ) ;
2098+ }
2099+ for url in [
2100+ "https://gateway.test:8080" ,
2101+ "http://127.0.0.1:8080" ,
2102+ "http://[::1]:8080" ,
2103+ ] {
2104+ assert ! ( client( url) . require_attested_transport( ) . is_ok( ) ) ;
2105+ }
2106+ }
2107+
20232108 #[ test]
20242109 fn gateway_response_keeps_expiration_and_rejects_invalid_duration ( ) {
20252110 let response = |seconds, nanos| crate :: proto:: ExchangeProviderSubjectTokenResponse {
0 commit comments