Skip to content

Commit 9a5f3e9

Browse files
committed
feat(isolation): bind launches to sandbox sessions
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 575810b commit 9a5f3e9

9 files changed

Lines changed: 271 additions & 22 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/openshell-core/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ serde = { workspace = true }
2626
serde_json = { workspace = true }
2727
tracing = { workspace = true }
2828
url = { workspace = true }
29+
uuid = { workspace = true }
2930
ipnet = "2"
3031
rustls = { workspace = true }
3132
rustls-pemfile = { workspace = true }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub mod proto;
4444
pub mod proto_struct;
4545
pub mod provider_credentials;
4646
pub mod sandbox_env;
47+
pub mod sandbox_session;
4748
pub mod secrets;
4849
pub mod settings;
4950
pub mod shell;
@@ -63,6 +64,7 @@ pub use error::{ComputeDriverError, Error, Result};
6364
pub use metadata::{
6465
GetResourceVersion, ObjectId, ObjectLabels, ObjectName, ObjectWorkspace, SetResourceVersion,
6566
};
67+
pub use sandbox_session::{SandboxSessionId, SandboxSessionIdError};
6668

6769
/// Build version string derived from git metadata.
6870
///
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Strong identity for one sandbox runtime launch.
5+
6+
use std::{fmt, str::FromStr};
7+
8+
use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
9+
use thiserror::Error;
10+
use uuid::Uuid;
11+
12+
/// Identifies one create or start-from-stopped sandbox launch.
13+
///
14+
/// Retries of the same durable launch reuse this value. A later launch gets a
15+
/// new value even when the compute platform reuses the same sandbox resource.
16+
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
17+
pub struct SandboxSessionId(Uuid);
18+
19+
impl SandboxSessionId {
20+
/// Generate a fresh launch identity.
21+
#[must_use]
22+
pub fn new() -> Self {
23+
Self(Uuid::new_v4())
24+
}
25+
26+
/// Return the underlying UUID.
27+
#[must_use]
28+
pub const fn as_uuid(&self) -> &Uuid {
29+
&self.0
30+
}
31+
}
32+
33+
impl Default for SandboxSessionId {
34+
fn default() -> Self {
35+
Self::new()
36+
}
37+
}
38+
39+
impl fmt::Display for SandboxSessionId {
40+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
41+
self.0.hyphenated().fmt(formatter)
42+
}
43+
}
44+
45+
impl fmt::Debug for SandboxSessionId {
46+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
47+
formatter
48+
.debug_tuple("SandboxSessionId")
49+
.field(&self.to_string())
50+
.finish()
51+
}
52+
}
53+
54+
impl FromStr for SandboxSessionId {
55+
type Err = SandboxSessionIdError;
56+
57+
fn from_str(value: &str) -> Result<Self, Self::Err> {
58+
let parsed = Uuid::parse_str(value).map_err(|_| SandboxSessionIdError)?;
59+
if parsed.is_nil() || parsed.hyphenated().to_string() != value {
60+
return Err(SandboxSessionIdError);
61+
}
62+
Ok(Self(parsed))
63+
}
64+
}
65+
66+
impl Serialize for SandboxSessionId {
67+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
68+
where
69+
S: Serializer,
70+
{
71+
serializer.collect_str(self)
72+
}
73+
}
74+
75+
impl<'de> Deserialize<'de> for SandboxSessionId {
76+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
77+
where
78+
D: Deserializer<'de>,
79+
{
80+
let value = String::deserialize(deserializer)?;
81+
value.parse().map_err(|_| {
82+
de::Error::invalid_value(
83+
de::Unexpected::Str(&value),
84+
&"a non-nil canonical lowercase UUID",
85+
)
86+
})
87+
}
88+
}
89+
90+
/// A sandbox session ID was not a non-nil canonical lowercase UUID.
91+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
92+
#[error("sandbox session ID must be a non-nil canonical lowercase UUID")]
93+
pub struct SandboxSessionIdError;
94+
95+
#[cfg(test)]
96+
mod tests {
97+
use crate::sandbox_session::SandboxSessionId;
98+
99+
#[test]
100+
fn round_trips_canonical_id() {
101+
let session = SandboxSessionId::new();
102+
let encoded = serde_json::to_string(&session).expect("serialize session ID");
103+
let decoded: SandboxSessionId =
104+
serde_json::from_str(&encoded).expect("deserialize session ID");
105+
assert_eq!(decoded, session);
106+
}
107+
108+
#[test]
109+
fn rejects_nil_and_noncanonical_ids() {
110+
for invalid in [
111+
"00000000-0000-0000-0000-000000000000",
112+
"550E8400-E29B-41D4-A716-446655440000",
113+
"550e8400e29b41d4a716446655440000",
114+
"not-a-uuid",
115+
] {
116+
assert!(invalid.parse::<SandboxSessionId>().is_err(), "{invalid}");
117+
}
118+
}
119+
}

‎crates/openshell-isolation-interface/src/contract.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use async_trait::async_trait;
4141
use tokio::io::{AsyncRead, AsyncWrite};
4242
use tokio::sync::oneshot;
4343

44+
pub use openshell_core::SandboxSessionId;
4445
pub use openshell_core::policy::SandboxPolicy;
4546

4647
// ============================================================================
@@ -243,6 +244,11 @@ impl ResolvedWorkloadIdentity {
243244
pub struct SandboxContext {
244245
/// Which sandbox this is.
245246
pub sandbox_id: String,
247+
/// Which create or start-from-stopped launch this attachment belongs to.
248+
///
249+
/// Retries of one durable launch reuse this identity. A later launch gets
250+
/// a new identity even when the compute platform reuses its outer resource.
251+
pub session_id: SandboxSessionId,
246252
/// The admitted launch-time policy.
247253
pub policy: SandboxPolicy,
248254
/// The admitted agent workload.
@@ -334,8 +340,10 @@ pub trait IsolationBackend: Send + Sync {
334340
/// Validate the opaque payload, establish any boundary-local resources,
335341
/// and atomically bind them to the trusted sandbox context: returns `Bound`
336342
/// or fails closed. Never binds a resource already bound to an active
337-
/// boundary. Durable resource lifecycle remains owned by the compute driver
338-
/// or external orchestrator that supplied the descriptor.
343+
/// boundary. The authenticated runtime session must match
344+
/// `sandbox.session_id`; a session from an earlier launch is rejected.
345+
/// Durable resource lifecycle remains owned by the compute driver or
346+
/// external orchestrator that supplied the descriptor.
339347
async fn attach(
340348
&self,
341349
descriptor: VerifiedTopologyDescriptor,
@@ -440,6 +448,9 @@ pub struct SandboxConfirmEvidence {
440448
pub authenticated_supervisor: bool,
441449
pub session_epoch: String,
442450
pub direct_egress_blocked: bool,
451+
/// The driver-owned containment primitive terminates the workload when its
452+
/// Sandbox Runtime exits.
453+
pub runtime_exit_terminates_workload: bool,
443454
pub resource_claims: BTreeMap<String, String>,
444455
}
445456

@@ -469,6 +480,7 @@ impl SandboxConfirmEvidence {
469480
&& self.tcp_deny_round_trip
470481
&& self.authenticated_supervisor
471482
&& self.direct_egress_blocked
483+
&& self.runtime_exit_terminates_workload
472484
&& !self.generation.is_empty()
473485
&& !self.session_epoch.is_empty();
474486
if complete {

‎crates/openshell-isolation-interface/tests/backend_conformance.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ fn descriptor(backend_name: &str) -> TopologyDescriptor {
328328
fn sandbox_ctx() -> SandboxContext {
329329
SandboxContext {
330330
sandbox_id: "sb-1".to_string(),
331+
session_id: "550e8400-e29b-41d4-a716-446655440000"
332+
.parse()
333+
.expect("valid session ID"),
331334
policy: SandboxPolicy {
332335
version: 1,
333336
filesystem: openshell_core::policy::FilesystemPolicy::default(),
@@ -394,6 +397,7 @@ fn confirmation_evidence() -> SandboxConfirmEvidence {
394397
authenticated_supervisor: true,
395398
session_epoch: "epoch-1".to_string(),
396399
direct_egress_blocked: true,
400+
runtime_exit_terminates_workload: true,
397401
resource_claims: BTreeMap::new(),
398402
}
399403
}
@@ -805,6 +809,10 @@ fn confirmation_evidence_rejects_identity_or_posture_drift() {
805809
drifted.capabilities.effective = 1;
806810
assert!(drifted.validate(&expected).is_err());
807811

812+
let mut unmanaged = confirmation_evidence();
813+
unmanaged.runtime_exit_terminates_workload = false;
814+
assert!(unmanaged.validate(&expected).is_err());
815+
808816
let different = ResolvedWorkloadIdentity::new(
809817
1002,
810818
1000,

‎examples/governance-interceptor/Cargo.lock‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)