Skip to content

Commit 4c1b16a

Browse files
authored
feat(server): add operator-only provider credential retrieval (#4357)
* feat(server): add operator-only provider credential retrieval Authenticate operators exclusively through verified direct gateway mTLS. Export selected runtime credentials with freshness validation and all-or-nothing delivery. Coordinate refresh across callers and replicas, preserve rotated grants across RPC cancellation, and fence credential delivery against reconfiguration. Add generated bindings, security and regression tests, and operator documentation. Signed-off-by: Seth Jennings <sjenning@redhat.com> * feat(sdk): add curated operator credential retrieval Expose provider credential clients in Python and TypeScript with explicit workspace and key selection, freshness options, optional expiration, and preserved gateway errors. Reuse existing mTLS transports without introducing retries or secret caching. Add generated-wire and error-mapping tests, SDK package validation, and operator usage documentation. Signed-off-by: Seth Jennings <sjenning@redhat.com> * fix(server): honor recovery state for queued automatic refreshes Signed-off-by: Seth Jennings <sjenning@redhat.com> --------- Signed-off-by: Seth Jennings <sjenning@redhat.com>
1 parent 5ab677e commit 4c1b16a

56 files changed

Lines changed: 4724 additions & 1091 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/openshell-cli/tests/ensure_providers_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ impl OpenShell for TestOpenShell {
339339
}))
340340
}
341341

342+
async fn get_provider_credentials(
343+
&self,
344+
_request: tonic::Request<openshell_core::proto::GetProviderCredentialsRequest>,
345+
) -> Result<Response<openshell_core::proto::GetProviderCredentialsResponse>, Status> {
346+
Err(Status::unimplemented("not used by this mock"))
347+
}
348+
342349
async fn get_provider(
343350
&self,
344351
request: tonic::Request<GetProviderRequest>,

‎crates/openshell-cli/tests/mtls_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ impl OpenShell for TestOpenShell {
295295
))
296296
}
297297

298+
async fn get_provider_credentials(
299+
&self,
300+
_request: tonic::Request<openshell_core::proto::GetProviderCredentialsRequest>,
301+
) -> Result<Response<openshell_core::proto::GetProviderCredentialsResponse>, Status> {
302+
Err(Status::unimplemented("not used by this mock"))
303+
}
304+
298305
async fn get_provider(
299306
&self,
300307
_request: tonic::Request<GetProviderRequest>,

‎crates/openshell-cli/tests/provider_commands_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,13 @@ impl OpenShell for TestOpenShell {
751751
}))
752752
}
753753

754+
async fn get_provider_credentials(
755+
&self,
756+
_request: tonic::Request<openshell_core::proto::GetProviderCredentialsRequest>,
757+
) -> Result<Response<openshell_core::proto::GetProviderCredentialsResponse>, Status> {
758+
Err(Status::unimplemented("not used by this mock"))
759+
}
760+
754761
async fn get_provider(
755762
&self,
756763
request: tonic::Request<GetProviderRequest>,

‎crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ impl OpenShell for TestOpenShell {
547547
Ok(Response::new(ProviderResponse::default()))
548548
}
549549

550+
async fn get_provider_credentials(
551+
&self,
552+
_request: tonic::Request<openshell_core::proto::GetProviderCredentialsRequest>,
553+
) -> Result<Response<openshell_core::proto::GetProviderCredentialsResponse>, Status> {
554+
Err(Status::unimplemented("not used by this mock"))
555+
}
556+
550557
async fn get_provider(
551558
&self,
552559
_request: tonic::Request<GetProviderRequest>,

‎crates/openshell-cli/tests/sandbox_exec_streaming_integration.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ mock_gateway! {
243243
delete_service(proto::DeleteServiceRequest) -> proto::DeleteServiceResponse;
244244
revoke_ssh_session(proto::RevokeSshSessionRequest) -> proto::RevokeSshSessionResponse;
245245
create_provider(proto::CreateProviderRequest) -> proto::ProviderResponse;
246+
get_provider_credentials(proto::GetProviderCredentialsRequest) -> proto::GetProviderCredentialsResponse;
246247
get_provider(proto::GetProviderRequest) -> proto::ProviderResponse;
247248
list_providers(proto::ListProvidersRequest) -> proto::ListProvidersResponse;
248249
list_provider_profiles(proto::ListProviderProfilesRequest) -> proto::ListProviderProfilesResponse;

‎crates/openshell-cli/tests/sandbox_name_fallback_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ impl OpenShell for TestOpenShell {
357357
Ok(Response::new(ProviderResponse::default()))
358358
}
359359

360+
async fn get_provider_credentials(
361+
&self,
362+
_request: tonic::Request<openshell_core::proto::GetProviderCredentialsRequest>,
363+
) -> Result<Response<openshell_core::proto::GetProviderCredentialsResponse>, Status> {
364+
Err(Status::unimplemented("not used by this mock"))
365+
}
366+
360367
async fn get_provider(
361368
&self,
362369
_request: tonic::Request<GetProviderRequest>,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ pub struct OidcConfig {
410410
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
411411
#[serde(deny_unknown_fields)]
412412
pub struct MtlsAuthConfig {
413+
/// Enable gateway-wide operators authenticated by verified certificates with OU=operator.
414+
/// Independent of ordinary mTLS user authentication; defaults off.
415+
#[serde(default)]
416+
pub operator_enabled: bool,
413417
/// When true, the gateway maps a verified TLS client certificate into a
414418
/// user principal. Sandbox and supervisor clients use bearer identity, so
415419
/// this setting is independent of the selected compute driver.

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,28 @@ mod tests {
336336
assert_eq!(decoded, request);
337337
}
338338

339+
#[test]
340+
fn operator_credential_response_omits_values_inside_maps() {
341+
let codec = ProtoJsonCodec::openshell().unwrap();
342+
let response = openshell_core::proto::GetProviderCredentialsResponse {
343+
credentials: HashMap::from([(
344+
"ACCESS_TOKEN".to_string(),
345+
openshell_core::proto::ProviderCredentialValue {
346+
value: "must-not-observe".to_string(),
347+
expiration_time: None,
348+
},
349+
)]),
350+
};
351+
let view = codec
352+
.decode_bytes_to_interceptor_json(
353+
"openshell.v1.GetProviderCredentialsResponse",
354+
&response.encode_to_vec(),
355+
)
356+
.unwrap();
357+
assert!(view["credentials"]["ACCESS_TOKEN"].get("value").is_none());
358+
assert!(!view.to_string().contains("must-not-observe"));
359+
}
360+
339361
#[test]
340362
fn interceptor_view_omits_nested_secrets_but_keeps_non_secret_fields() {
341363
let codec = ProtoJsonCodec::openshell().unwrap();

‎crates/openshell-sdk/tests/client_mock.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,13 @@ impl OpenShell for TestOpenShell {
685685
Ok(Response::new(proto::ProviderResponse::default()))
686686
}
687687

688+
async fn get_provider_credentials(
689+
&self,
690+
_request: tonic::Request<proto::GetProviderCredentialsRequest>,
691+
) -> Result<Response<proto::GetProviderCredentialsResponse>, Status> {
692+
Err(Status::unimplemented("not used by this mock"))
693+
}
694+
688695
async fn get_provider(
689696
&self,
690697
_: tonic::Request<proto::GetProviderRequest>,

‎crates/openshell-server/README.md‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!--
2+
SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
SPDX-License-Identifier: Apache-2.0
4+
-->
5+
6+
# OpenShell gateway server
7+
8+
The server owns control-plane RPCs, authentication, provider credential delivery,
9+
and sandbox lifecycle orchestration. The `openshell-gateway` crate composes the
10+
server with selected compute drivers.
11+
12+
## Operator credential export
13+
14+
`GetProviderCredentials` exports selected profile-declared runtime environment
15+
keys from one provider in an explicitly named workspace. It requires the distinct
16+
`Principal::Operator`, established only from a verified TLS leaf certificate with
17+
`OU=operator` when `mtls_auth.operator_enabled` is enabled. The TLS listener supplies
18+
its certificate fingerprint separately from user identity; the ordinary
19+
identity-only serving path cannot establish an operator.
20+
21+
Operators explicitly inherit user/platform-admin permissions, but not sandbox or
22+
peer identities. Descriptor authorization and a handler guard both protect the
23+
export RPC. Operator mutation admission uses a separate caller namespace from
24+
ordinary mTLS users with the same certificate subject. Credential responses never
25+
enter durable mutation replay or generic interceptor routing.
26+
27+
The export resolver validates the entire selection before minting, resolves only
28+
selected credential handles, and fences provider revisions, refresh epochs, and
29+
profile declarations before delivery. Driver expiration and provider expiration
30+
combine using the earlier timestamp. OAuth minting inputs, broker-only keys, and
31+
supervisor-bound dynamic grants are not exportable. A failed response can still
32+
have committed refresh effects. Missing refresh-owned stored outputs trigger
33+
refresh-on-read; missing static outputs and other credential-backend errors fail
34+
closed without falling back to inline values.
35+
36+
## Refresh coordination
37+
38+
Explicit rotation, background refresh, and operator refresh-on-read share the
39+
same refresh coordination:
40+
41+
- A process-local weak keyed mutex coalesces waiters without retaining deleted
42+
providers indefinitely.
43+
- A bounded admission queue and executor pool limit detached refresh work.
44+
- PostgreSQL deployments also take a dedicated per-provider/per-credential
45+
advisory lock; SQLite uses the local mutex. Worker secret cleanup takes the
46+
same locks and reloads state before changing its resource version.
47+
- A durable `refresh_in_progress` marker precedes upstream minting. A
48+
`refresh_committing` marker protects the interval between grant persistence
49+
and provider-handle persistence. Only a completed provider commit publishes
50+
`refreshed` state, with a unique completed-mint identity in metadata
51+
annotations. Waiters coalesce against that identity, not bookkeeping changes
52+
to the resource version.
53+
- Automatic callers recheck live recovery and retry deadlines under both locks.
54+
A failed mint blocks queued automatic exchanges without disabling scheduled
55+
worker retries or a separately requested manual rotation.
56+
- Detached refresh tasks complete despite request cancellation, preserving
57+
replacement refresh tokens returned by the issuer.
58+
- Existing generation/CAS fencing remains active for deletion and
59+
reconfiguration. An ambiguous rotating-token exchange is parked for recovery
60+
rather than automatically consuming the grant again.
61+
62+
A crash or lost database-lock session can leave a parked marker. Reconfigure or
63+
reauthorize the refresh grant after investigating its issuer state. Changing a
64+
marker directly is not a supported recovery workflow.
65+
66+
## Focused verification
67+
68+
```shell
69+
cargo test -p openshell-server --features test-support,prebuilt-z3
70+
cargo clippy -p openshell-server --all-targets --features test-support,prebuilt-z3 -- -D warnings
71+
```
72+
73+
The ignored `refresh_locks_coordinate_independent_replica_sessions` test requires
74+
`OPENSHELL_REFRESH_TEST_DATABASE_URL` pointing to a disposable PostgreSQL database.
75+
It exercises independent sessions without the local mutex. Do not point this
76+
fixture at an existing deployment database.

0 commit comments

Comments
 (0)