|
| 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