Skip to content

Commit 3da38d3

Browse files
committed
refactor(supervisor): name shared-host registrations sandbox instances
Merge the sandbox instance naming from the foundation branch and apply it to the shared supervisor layer. Registrations, status reports, removal bounds, the shared host's per-instance files, and the Kubernetes driver's shared placement now describe sandbox instances: one running generation of a stable Sandbox resource. The session-control protocol keeps its wire names: the /v1/sessions paths and the "sessions" list field, the openshell.ai/sandbox-runtime-supervisor-session annotation, the kubernetes.supervisor_session claim key, the --session-control-tls-dir and --session-root flags, TLS identities, and Helm rendering are unchanged. Only Rust names, comments, and diagnostics change. Signed-off-by: Drew Newberry <anewberry@nvidia.com>
2 parents 1391e18 + 408de7d commit 3da38d3

31 files changed

Lines changed: 822 additions & 691 deletions

File tree

‎.agents/skills/helm-dev-environment/SKILL.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ gatewayConfig:
7171
The gateway chart creates a single-replica shared supervisor Deployment,
7272
Service, and NetworkPolicy in the release namespace, regardless of
7373
shared/managed/operator workspace mode, and the certgen hook issues its
74-
session-control Secrets. New sandbox generations run as sessions in that
75-
process. Its process-health `tcpSocket` probes connect to the mTLS
74+
session-control Secrets. New sandbox generations run as sandbox instances in
75+
that process. Its process-health `tcpSocket` probes connect to the mTLS
7676
session-control port (5501); there is no separate health port. The chart starts
7777
`--mode=shared`, sets `--gateway-endpoint` to the gateway gRPC URL, and binds
7878
`--address` to this control/probe listener. Build the

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

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! `OpenShell` server.
66
//!
77
//! Every request carries a sandbox bearer credential in the `Authorization`
8-
//! header. Each supervisor session owns its [`GatewayCredentials`], usually
8+
//! header. Each sandbox instance owns its [`GatewayCredentials`], usually
99
//! built from the trusted launch bundle with
1010
//! [`GatewayCredentials::from_auth_bundle`]. Diagnostic tools can instead
1111
//! resolve a token with [`GatewayCredentials::from_environment`] from one of:
@@ -16,8 +16,8 @@
1616
//! caller exchanges it for a gateway JWT via `IssueSandboxToken`.
1717
//!
1818
//! Callers reach the gateway through a [`GatewayEndpoint`], which pairs the
19-
//! URL with one session's credentials. No credential is installed
20-
//! process-wide, so sessions hosted by one supervisor process cannot use or
19+
//! URL with one sandbox instance's credentials. No credential is installed
20+
//! process-wide, so instances hosted by one supervisor process cannot use or
2121
//! rotate each other's identity.
2222
2323
use std::collections::HashMap;
@@ -65,7 +65,7 @@ pub const MAX_SUPERVISOR_STREAM_MESSAGE_BYTES: usize = 9 * 1024 * 1024;
6565

6666
/// Shared, refreshable Bearer header. All [`AuthInterceptor`] clones read
6767
/// the same slot, so the renewal task can replace the token in place without
68-
/// rebuilding the channel. `None` means the owning session revoked it.
68+
/// rebuilding the channel. `None` means the owning sandbox instance revoked it.
6969
type TokenSlot = Arc<RwLock<Option<AsciiMetadataValue>>>;
7070

7171
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -75,7 +75,7 @@ enum TokenSource {
7575
K8sServiceAccount,
7676
}
7777

78-
/// Gateway credentials owned by one supervisor session.
78+
/// Gateway credentials owned by one sandbox instance.
7979
///
8080
/// Clients built from a [`GatewayEndpoint`] read only these slots, and the
8181
/// renewal task started by the first connection updates only them. Dropping
@@ -200,7 +200,7 @@ impl GatewayCredentials {
200200
}
201201

202202
/// Start the renewal task once for these credentials, on the caller's
203-
/// runtime, so a hosted session's renewal stops with that session.
203+
/// runtime, so a hosted sandbox instance's renewal stops with that instance.
204204
fn start_renewal(&self, channel: &AuthedChannel, plain_channel: &Channel, endpoint: &str) {
205205
let mut renewal = self
206206
.inner
@@ -239,14 +239,16 @@ impl GatewayCredentials {
239239
.bearer
240240
.write()
241241
.unwrap_or_else(std::sync::PoisonError::into_inner);
242-
// A revoked session must not be revived by an in-flight response.
242+
// Revoked instance credentials must not be revived by an in-flight
243+
// response.
243244
if slot.is_some() {
244245
*slot = Some(bearer);
245246
}
246247
}
247248
}
248249

249-
/// The gateway URL a session uses, paired with that session's credentials.
250+
/// The gateway URL a sandbox instance uses, paired with that instance's
251+
/// credentials.
250252
#[derive(Clone)]
251253
pub struct GatewayEndpoint {
252254
url: Arc<str>,
@@ -271,7 +273,7 @@ impl GatewayEndpoint {
271273
&self.credentials
272274
}
273275

274-
/// Reach another gateway address with the same session credentials.
276+
/// Reach another gateway address with the same sandbox instance credentials.
275277
#[must_use]
276278
pub fn with_url(&self, url: impl Into<Arc<str>>) -> Self {
277279
Self::new(url, self.credentials.clone())
@@ -357,7 +359,9 @@ impl tonic::service::Interceptor for AuthInterceptor {
357359
.read()
358360
.unwrap_or_else(std::sync::PoisonError::into_inner)
359361
.clone()
360-
.ok_or_else(|| Status::unauthenticated("gateway session credentials were revoked"))?;
362+
.ok_or_else(|| {
363+
Status::unauthenticated("sandbox instance gateway credentials were revoked")
364+
})?;
361365
req.metadata_mut().insert("authorization", bearer);
362366
#[cfg(feature = "trace-context")]
363367
let req =
@@ -458,11 +462,14 @@ impl Drop for ClientSpanStatus {
458462
}
459463
}
460464

461-
/// Build a Bearer-authenticated channel to the gateway with one session's
462-
/// credentials. The first connection starts that session's renewal task.
465+
/// Build a Bearer-authenticated channel to the gateway with one sandbox
466+
/// instance's credentials. The first connection starts that instance's
467+
/// renewal task.
463468
async fn connect_channel(gateway: &GatewayEndpoint) -> Result<AuthedChannel> {
464469
if gateway.credentials.is_revoked() {
465-
return Err(miette::miette!("gateway session credentials were revoked"));
470+
return Err(miette::miette!(
471+
"sandbox instance gateway credentials were revoked"
472+
));
466473
}
467474
let channel = build_plain_channel(gateway.url()).await?;
468475
let intercepted = InterceptedService::new(
@@ -577,8 +584,9 @@ pub async fn report_provider_readiness(
577584
.into_diagnostic()
578585
}
579586

580-
/// Slots and transport retained by one session's renewal task. It holds no
581-
/// reference to [`GatewayCredentials`], so dropping them still stops it.
587+
/// Slots and transport retained by one sandbox instance's renewal task. It
588+
/// holds no reference to [`GatewayCredentials`], so dropping them still stops
589+
/// it.
582590
struct RenewalTarget {
583591
channel: AuthedChannel,
584592
bearer: TokenSlot,
@@ -590,10 +598,10 @@ struct RenewalTarget {
590598
}
591599

592600
/// Background task that renews the sandbox JWT at ~80% of its remaining
593-
/// lifetime. The new token replaces the value in the session's slot, so all
594-
/// in-flight and future clients of that session pick it up on their next
595-
/// request. The loop never panics: every failure is logged and re-attempted
596-
/// after a bounded backoff.
601+
/// lifetime. The new token replaces the value in the sandbox instance's slot,
602+
/// so all in-flight and future clients of that instance pick it up on their
603+
/// next request. The loop never panics: every failure is logged and
604+
/// re-attempted after a bounded backoff.
597605
async fn refresh_token_loop(target: RenewalTarget) {
598606
let RenewalTarget {
599607
channel,
@@ -832,7 +840,7 @@ fn compute_refresh_delay(slot: &TokenSlot) -> Option<Duration> {
832840
let current = slot
833841
.read()
834842
.unwrap_or_else(std::sync::PoisonError::into_inner);
835-
// A revoked session has nothing to renew.
843+
// Revoked instance credentials have nothing to renew.
836844
current.as_ref()?.to_str().ok().map(str::to_string)
837845
}
838846
.unwrap_or_default();
@@ -1058,7 +1066,7 @@ mod workspace_tests {
10581066
}
10591067
}
10601068

1061-
/// Connect to the `OpenShell` server with one session's credentials.
1069+
/// Connect to the `OpenShell` server with one sandbox instance's credentials.
10621070
async fn connect(gateway: &GatewayEndpoint) -> Result<OpenShellClient<AuthedChannel>> {
10631071
let channel = connect_channel(gateway).await?;
10641072
Ok(OpenShellClient::new(channel))
@@ -1711,7 +1719,8 @@ mod token_grant_exchange_tests {
17111719
#[derive(Clone)]
17121720
pub struct CachedOpenShellClient {
17131721
client: OpenShellClient<AuthedChannel>,
1714-
/// Session credentials rotated alongside extension credentials.
1722+
/// Sandbox instance gateway credentials rotated alongside extension
1723+
/// credentials.
17151724
credentials: GatewayCredentials,
17161725
workspace: Arc<tokio::sync::OnceCell<String>>,
17171726
/// Extension credentials for this supervisor. Cloning the client shares

‎crates/openshell-driver-kubernetes/README.md‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -182,40 +182,41 @@ still enforced by TLS, JWT claims, session generation, and recorded Pod UIDs.
182182
### Shared supervisor topology
183183

184184
With `supervisor_topology = "gateway"`, each new runtime
185-
generation becomes a session on one supervisor process that Helm deploys in the
186-
gateway namespace, instead of a supervisor Pod and boundary Service of its own.
187-
The generation's placement is recorded on the Sandbox resource
188-
(`openshell.ai/sandbox-runtime-supervisor-topology: gateway` and the session
189-
route in `openshell.ai/sandbox-runtime-supervisor-session`) when the generation
190-
starts. Every later lifecycle decision reads the record, so changing the setting
185+
generation becomes a sandbox instance on one supervisor process that Helm
186+
deploys in the gateway namespace, instead of a supervisor Pod and boundary
187+
Service of its own. A sandbox instance is one running generation of a stable
188+
Sandbox resource. The generation's placement is recorded on the Sandbox
189+
resource (`openshell.ai/sandbox-runtime-supervisor-topology: gateway` and the
190+
instance route in `openshell.ai/sandbox-runtime-supervisor-session`, whose key
191+
keeps its established name) when the generation starts. Every later lifecycle decision reads the record, so changing the setting
191192
never reinterprets a running generation, and an unknown or incomplete record
192193
fails closed.
193194

194195
- **Create and start.** The driver creates a per-sandbox egress allowance
195196
`os-shared-control-<id>` from the workload Pod to the Pods the shared
196197
supervisor's Service selects, on the runtime port, binds its UID and
197-
resourceVersion into the boundary evidence, and registers the session over
198-
session control before releasing the workload Pod. Registration does not wait
199-
for the runtime, so create still returns before the gateway persists the
200-
generation. The runtime identity's last component is the session route, which
201-
no Pod UID can equal, so `authenticate_sandbox` cannot vouch for a shared
198+
resourceVersion into the boundary evidence, and registers the sandbox
199+
instance over session control before releasing the workload Pod.
200+
Registration does not wait for the runtime, so create still returns before
201+
the gateway persists the generation. The runtime identity's last component is
202+
the instance route, which no Pod UID can equal, so `authenticate_sandbox` cannot vouch for a shared
202203
generation.
203-
- **Readiness.** A shared generation is available while its session is
204-
registered for the sandbox and accepted by the gateway and its fence and
205-
egress allowance exist. A missing or ended session is unavailable, and
204+
- **Readiness.** A shared generation is available while its sandbox instance
205+
is registered for the sandbox and accepted by the gateway and its fence and
206+
egress allowance exist. A missing or ended instance is unavailable, and
206207
reconciliation suspends the workload; an unreachable supervisor is unknown.
207-
- **Stop and delete.** The driver removes the session before suspending or
208-
deleting the workload. Removal is best effort because ending the workload ends
209-
supervision anyway. Reconciliation removes sessions that no Sandbox's current
210-
generation may run; it lists sessions before Sandboxes, because a generation
211-
records its route before registering it.
212-
- **Isolation.** The admission credential is separate from every session's
208+
- **Stop and delete.** The driver removes the sandbox instance before
209+
suspending or deleting the workload. Removal is best effort because ending the
210+
workload ends supervision anyway. Reconciliation removes instances that no
211+
Sandbox's current generation may run; it lists instances before Sandboxes,
212+
because a generation records its route before registering it.
213+
- **Isolation.** The admission credential is separate from every instance's
213214
credentials. Sandboxes cannot reach session control, and the routing preface
214215
only selects which generation-pinned TLS identity the supervisor demands.
215216

216217
The topology does not support upstream proxies or provider SPIFFE identity, and
217218
the shared supervisor is a single point of failure for the sandboxes it hosts.
218-
Shared sessions export no supervisor OTLP traces or OCSF events; the driver
219+
Shared sandbox instances export no supervisor OTLP traces or OCSF events; the driver
219220
warns at startup when the gateway configures that export.
220221
When the setting is removed, reconciliation suspends shared generations, and a
221222
restart creates the dedicated generation's boundary Service the shared one never

‎crates/openshell-driver-kubernetes/src/config.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,9 @@ impl KubernetesComputeConfig {
525525
self.validate_allowed_pod_labels()
526526
}
527527

528-
/// The shared supervisor serves only sessions it can isolate: it holds no
529-
/// per-sandbox workload identity, upstream proxy credential, or proxy CA.
528+
/// The shared supervisor serves only sandbox instances it can isolate: it
529+
/// holds no per-sandbox workload identity, upstream proxy credential, or
530+
/// proxy CA.
530531
pub fn validate_supervisor_topology(&self) -> Result<(), String> {
531532
match self.supervisor_topology {
532533
None => {

0 commit comments

Comments
 (0)