Skip to content

Commit dd1e11f

Browse files
committed
feat(supervisor): present workload assertions for provider grants
Let a dedicated supervisor prove its sandbox and launch identity when it asks the gateway for a provider access token. - GetSandboxProviderAccessToken accepts two optional JWT-SVIDs. Shared supervisors keep omitting them. - When the launch bundle carries provider SPIFFE IDs, the supervisor fetches one JWT-SVID for the stable sandbox ID and the provider audience, and one for the launch ID and the launch audience. It sends both over TLS or numeric loopback only. - The supervisor reuses a pair for up to five seconds, stops one second before either expires, and never reuses assertions that carry a JWT ID. - The provider audience rule moves to openshell-core so the supervisor and the gateway derive it the same way. A whitespace-only configured audience now derives the issuer on the direct path too. - A probe subcommand takes a Workload API socket path and reports whether the supervisor can see it, so drivers can qualify a supervisor before launch. Bundles without provider SPIFFE IDs keep the existing direct exchange. Signed-off-by: Shiju <shiju@nvidia.com>
1 parent dec8cec commit dd1e11f

16 files changed

Lines changed: 616 additions & 144 deletions

File tree

‎crates/openshell-core/build.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5252
let mut proto_config = tonic_prost_build::Config::new();
5353
// Keep optional grant evidence off sandbox lifecycle futures' stacks.
5454
proto_config.boxed(".openshell.v1.SandboxStatus.last_token_grant_failure");
55+
proto_config.skip_debug([".openshell.v1.GetSandboxProviderAccessTokenRequest"]);
5556
let proto_include = if use_vendored_protoc {
5657
proto_config.protoc_executable(protoc_bin_vendored::protoc_bin_path()?);
5758
Some(protoc_bin_vendored::include_path()?)

‎crates/openshell-core/src/grpc_client.rs‎

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
18891933
fn 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\t443\t/\towner\tprovider:token", None),
1997-
client.get_access_token("api.test\t443\t/\towner\tprovider:token", None),
2040+
client.get_access_token("api.test\t443\t/\towner\tprovider:token", None, None),
2041+
client.get_access_token("api.test\t443\t/\towner\tprovider: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\t443\t/\towner\tprovider: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 {

‎crates/openshell-core/src/oauth.rs‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,42 @@ pub fn effective_token_type(token_type: &str) -> &str {
267267
}
268268
}
269269

270+
/// The supervisor requests this JWT-SVID audience and the gateway verifies the
271+
/// same value, so both sides must derive it here.
272+
pub fn effective_jwt_svid_audience(token_endpoint: &str, jwt_svid_audience: &str) -> String {
273+
if jwt_svid_audience.trim().is_empty() {
274+
derive_issuer_from_token_endpoint(token_endpoint)
275+
} else {
276+
jwt_svid_audience.to_string()
277+
}
278+
}
279+
280+
/// Derive the issuer/realm URL from a token endpoint URL.
281+
///
282+
/// For Keycloak token endpoints like:
283+
/// `https://auth.example.com/realms/openshell/protocol/openid-connect/token`
284+
/// Returns:
285+
/// `https://auth.example.com/realms/openshell`
286+
///
287+
/// This is used as the JWT-SVID audience claim when authenticating to the
288+
/// authorization server via JWT client assertion (RFC 7523).
289+
fn derive_issuer_from_token_endpoint(token_endpoint: &str) -> String {
290+
// For Keycloak, strip everything after /realms/{realm-name}
291+
if let Some(realms_idx) = token_endpoint.find("/realms/") {
292+
// Find the next path segment after the realm name
293+
let after_realms = &token_endpoint[realms_idx + "/realms/".len()..];
294+
if let Some(slash_idx) = after_realms.find('/') {
295+
// Return everything up to (but not including) the next slash
296+
let realm_end = realms_idx + "/realms/".len() + slash_idx;
297+
return token_endpoint[..realm_end].to_string();
298+
}
299+
}
300+
301+
// Fallback: if we can't parse it, use the full token endpoint
302+
// This works for some OAuth2 servers that accept the token endpoint as aud
303+
token_endpoint.to_string()
304+
}
305+
270306
/// Cache lifetime for a granted access token.
271307
///
272308
/// A configured override is used exactly, including zero to disable caching.
@@ -987,6 +1023,65 @@ mod tests {
9871023
assert_eq!(request.request_id, None);
9881024
}
9891025

1026+
#[test]
1027+
fn jwt_svid_audience_is_the_configured_value_or_the_derived_issuer() {
1028+
const OPENSHELL_REALM: &str =
1029+
"https://auth.example.com/realms/openshell/protocol/openid-connect/token";
1030+
const SHORT_REALM: &str = "https://kc.example/realms/a/protocol/openid-connect/token";
1031+
1032+
for (case, token_endpoint, issuer) in [
1033+
(
1034+
"keycloak realm",
1035+
OPENSHELL_REALM,
1036+
"https://auth.example.com/realms/openshell",
1037+
),
1038+
(
1039+
"another keycloak realm",
1040+
"https://auth.example.com/realms/production/protocol/openid-connect/token",
1041+
"https://auth.example.com/realms/production",
1042+
),
1043+
// Fallback: returns the full token endpoint
1044+
(
1045+
"non-keycloak fallback",
1046+
"https://oauth.example.com/token",
1047+
"https://oauth.example.com/token",
1048+
),
1049+
] {
1050+
assert_eq!(
1051+
derive_issuer_from_token_endpoint(token_endpoint),
1052+
issuer,
1053+
"{case}"
1054+
);
1055+
}
1056+
1057+
for (case, token_endpoint, configured, audience) in [
1058+
(
1059+
"explicit override",
1060+
OPENSHELL_REALM,
1061+
"spiffe://custom-audience",
1062+
"spiffe://custom-audience",
1063+
),
1064+
(
1065+
"empty value",
1066+
SHORT_REALM,
1067+
"",
1068+
"https://kc.example/realms/a",
1069+
),
1070+
(
1071+
"blank value",
1072+
SHORT_REALM,
1073+
" ",
1074+
"https://kc.example/realms/a",
1075+
),
1076+
] {
1077+
assert_eq!(
1078+
effective_jwt_svid_audience(token_endpoint, configured),
1079+
audience,
1080+
"{case}"
1081+
);
1082+
}
1083+
}
1084+
9901085
#[test]
9911086
fn token_endpoint_url_allows_https_loopback_and_in_cluster_http() {
9921087
for endpoint in [

‎crates/openshell-core/src/proto/mod.rs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ pub use openshell::*;
9494
pub use sandbox::v1::*;
9595
pub use test::ObjectForTest;
9696

97+
impl std::fmt::Debug for GetSandboxProviderAccessTokenRequest {
98+
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99+
formatter
100+
.debug_struct("GetSandboxProviderAccessTokenRequest")
101+
.field("credential_key", &self.credential_key)
102+
.field("jwt_svid", &self.jwt_svid.as_ref().map(|_| "[REDACTED]"))
103+
.field(
104+
"launch_jwt_svid",
105+
&self.launch_jwt_svid.as_ref().map(|_| "[REDACTED]"),
106+
)
107+
.finish()
108+
}
109+
}
110+
97111
impl SandboxPolicy {
98112
/// Returns whether the explicitly present Cedar message selects the Cedar engine.
99113
#[must_use]
@@ -134,6 +148,20 @@ mod tests {
134148

135149
use super::SandboxPolicy;
136150

151+
#[test]
152+
fn provider_access_token_request_debug_redacts_the_assertion() {
153+
let request = super::GetSandboxProviderAccessTokenRequest {
154+
credential_key: "configured-key".into(),
155+
jwt_svid: Some("oauth-assertion-canary".into()),
156+
launch_jwt_svid: Some("launch-assertion-canary".into()),
157+
};
158+
let output = format!("{request:?}");
159+
assert!(output.contains("configured-key"));
160+
assert!(output.contains("[REDACTED]"));
161+
assert!(!output.contains("oauth-assertion-canary"));
162+
assert!(!output.contains("launch-assertion-canary"));
163+
}
164+
137165
#[test]
138166
fn empty_cedar_message_preserves_format_and_policy_identity() {
139167
let yaml = SandboxPolicy::default();

‎crates/openshell-core/src/sandbox_generation.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ impl SandboxGenerationId {
5555
&self.0
5656
}
5757

58+
/// Audience requested for the JWT-SVID that accompanies the OAuth assertion.
59+
#[must_use]
60+
pub fn provider_spiffe_audience(&self) -> String {
61+
format!("urn:openshell:provider-grants:launch:{self}")
62+
}
63+
5864
#[must_use]
5965
pub fn into_string(self) -> String {
6066
self.0

‎crates/openshell-gateway-interceptors/src/proto_json.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,14 @@ mod tests {
411411
"openshell.v1.GetSandboxProviderEnvironmentResponse",
412412
"environment",
413413
),
414+
(
415+
"openshell.v1.GetSandboxProviderAccessTokenRequest",
416+
"jwt_svid",
417+
),
418+
(
419+
"openshell.v1.GetSandboxProviderAccessTokenRequest",
420+
"launch_jwt_svid",
421+
),
414422
] {
415423
let message = codec.message_descriptor(message_name).unwrap();
416424
let field = message.get_field_by_name(field_name).unwrap();

‎crates/openshell-server/src/grpc/provider.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6568,6 +6568,8 @@ pub(super) mod tests {
65686568
let mut request = Request::new(
65696569
openshell_core::proto::GetSandboxProviderAccessTokenRequest {
65706570
credential_key: SECRET.to_string(),
6571+
jwt_svid: None,
6572+
launch_jwt_svid: None,
65716573
},
65726574
);
65736575
request

‎crates/openshell-server/src/grpc/provider/access_token.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ mod tests {
688688
] {
689689
let mut request = Request::new(GetSandboxProviderAccessTokenRequest {
690690
credential_key: "untrusted".into(),
691+
jwt_svid: None,
692+
launch_jwt_svid: None,
691693
});
692694
request.extensions_mut().insert(principal);
693695
let error = handle(&state, request).await.unwrap_err();

‎crates/openshell-server/src/storage_proto.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ mod tests {
251251
// and the public/durable overlap remain unchanged.
252252
// The service backend HTTP version is part of both schemas. Legacy
253253
// endpoint records omit it and continue to use HTTP/1.1.
254+
// Provider access token requests accept two optional supervisor SVIDs.
255+
// The fields are public-only and older requests still omit them.
254256
const PUBLIC_RPC_SCHEMA_SHA256: &str =
255-
"edfc80ad192e77e1a9d1e1d6e3342280e4438f8bf7cb49969f580060df9a056a";
257+
"7e0830b5850c3fde8deb4ae9b1ff05c83a52bf9b8615e5a0c5020ee86e3727fb";
256258
// The storage.v2 refresh root adds retired handles and the first mint's
257259
// provider revision. All fields from the prior root retain their wire tags.
258260
const DURABLE_SCHEMA_SHA256: &str =

0 commit comments

Comments
 (0)