Skip to content

Commit 74d8917

Browse files
committed
feat(compute)!: bind admitted policy to launch generations
A launch retry or gateway recovery must use the policy admitted for that generation, even if policy changes later. This captures and retains that policy when the generation is claimed. Ordinary sandboxes can take a new static policy after stopping when the driver supports the contract; frozen sandboxes keep their original accepted snapshot. Apply a pending filesystem revision when a management caller resubmits it after stop, including the deduplicated revision. Signed-off-by: Shiju <shiju@nvidia.com>
1 parent b0e4430 commit 74d8917

24 files changed

Lines changed: 1739 additions & 797 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.boxed(".openshell.v1.SandboxStatus.launch_policy");
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/extension_protocol.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub const COMPUTE_SUSPEND_RESUME: &str = "openshell.compute.suspend-resume";
2828
/// Optional stopped-state workload configuration updates retaining the resource and storage.
2929
pub const COMPUTE_UPDATE_SANDBOX_CONFIGURATION: &str =
3030
"openshell.compute.update-sandbox-configuration";
31+
/// Immutable policy input bound to each compute launch generation.
32+
pub const COMPUTE_LAUNCH_POLICY: &str = "openshell.compute.launch-policy";
3133

3234
const MAX_IMPLEMENTATION_NAME_BYTES: usize = 128;
3335
const MAX_IMPLEMENTATION_VERSION_BYTES: usize = 128;
@@ -133,6 +135,7 @@ pub fn gateway_metadata(family: ExtensionFamily) -> PeerMetadata {
133135
supported_capabilities.push(COMPUTE_LAUNCH_AUTHENTICATION.to_string());
134136
supported_capabilities.push(COMPUTE_ISOLATION_BACKEND.to_string());
135137
supported_capabilities.push(COMPUTE_UPDATE_SANDBOX_CONFIGURATION.to_string());
138+
supported_capabilities.push(COMPUTE_LAUNCH_POLICY.to_string());
136139
}
137140
PeerMetadata {
138141
protocol_version: Some(ProtocolVersion {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Compute launch input identity. Policy safety remains the admission owner's duty.
5+
6+
use crate::policy_identity::deterministic_policy_hash;
7+
use crate::proto::SandboxLaunchPolicy;
8+
use prost::Message;
9+
10+
/// Check the complete bounded input before a driver changes retained resources.
11+
/// This does not authorize a policy or replace backend-specific admission.
12+
pub fn validate_launch_policy(
13+
input: &SandboxLaunchPolicy,
14+
generation: &str,
15+
) -> Result<(), &'static str> {
16+
if crate::sandbox_generation::SandboxGenerationId::parse(generation).is_err()
17+
|| input.generation_id != generation
18+
|| input.generation_id.is_empty()
19+
{
20+
return Err("launch policy generation does not match the compute launch");
21+
}
22+
let policy = input
23+
.policy
24+
.as_ref()
25+
.ok_or("launch policy document is missing")?;
26+
if policy.encoded_len() > 262_144 {
27+
return Err("launch policy exceeds the policy size limit");
28+
}
29+
if deterministic_policy_hash(policy) != input.policy_hash {
30+
return Err("launch policy hash does not match its document");
31+
}
32+
Ok(())
33+
}
34+
35+
#[cfg(test)]
36+
mod tests {
37+
use super::*;
38+
39+
#[test]
40+
fn launch_input_requires_matching_generation_document_hash_and_size() {
41+
let generation = uuid::Uuid::new_v4().to_string();
42+
let policy = crate::proto::SandboxPolicy::default();
43+
let valid = SandboxLaunchPolicy {
44+
generation_id: generation.clone(),
45+
policy_hash: deterministic_policy_hash(&policy),
46+
policy: Some(policy),
47+
};
48+
assert!(validate_launch_policy(&valid, &generation).is_ok());
49+
for mutation in 0..5 {
50+
let mut input = valid.clone();
51+
match mutation {
52+
0 => input.generation_id = uuid::Uuid::new_v4().to_string(),
53+
1 => input.policy = None,
54+
2 => input.policy_hash = "wrong".into(),
55+
3 => {
56+
let policy = input.policy.as_mut().unwrap();
57+
policy.filesystem = Some(crate::proto::FilesystemPolicy {
58+
read_write: vec!["/".repeat(262_145)],
59+
..Default::default()
60+
});
61+
input.policy_hash = deterministic_policy_hash(policy);
62+
}
63+
_ => input.generation_id.clear(),
64+
}
65+
assert!(
66+
validate_launch_policy(&input, &generation).is_err(),
67+
"mutation {mutation}"
68+
);
69+
}
70+
let mut invalid = valid;
71+
invalid.generation_id = "invalid/generation".into();
72+
assert!(validate_launch_policy(&invalid, "invalid/generation").is_err());
73+
}
74+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub mod host_pattern;
3737
pub mod image;
3838
pub mod isolation_registration;
3939
pub mod jwt;
40+
pub mod launch_policy;
4041
pub mod local_api_socket;
4142
pub mod mcp;
4243
pub mod metadata;

‎crates/openshell-sdk/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,11 @@ These helpers use the raw client's authentication slot. They do not perform OIDC
231231
- Async-only. Tonic is async-native; callers needing a blocking call can wrap
232232
with their own runtime.
233233
- The curated surface will grow as more RPCs graduate from `raw`.
234+
235+
## Next minor API migration
236+
237+
This source-breaking API change targets the next minor release and must not be backported into the `0.1.x` patch series.
238+
239+
Raw `SandboxStatus` adds optional `launch_policy`, exposing the retained generation, policy document and digest under existing policy-read authorization. Provider credential values and environment data are not included. Complete generated Rust status literals must add `launch_policy: None` or use `..Default::default()`.
240+
241+
Legacy wire payloads retain their field identities and decode the new field as absent. Upgrade gateway writers together because older writers can drop retained launch state. A negotiated launch without retained input fails closed. Stop and explicitly start the sandbox to claim a new generation; retries and recovery do not replace an already claimed generation's input. Frozen sandboxes keep their original accepted policy.

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Compile-time source-compatibility fixture for the v0.1.5 public status shape.
4+
//! Exhaustive raw status fixture for the documented next-minor API transition.
5+
//!
6+
//! This intentionally advances the v0.1.5 source baseline. Legacy wire payloads
7+
//! still decode; complete raw Rust literals need the new optional field.
8+
//! See the SDK README migration notice. Do not backport into a 0.1.x patch train.
59
610
use openshell_sdk::raw::proto::SandboxStatus;
711

812
#[test]
9-
fn baseline_exhaustive_sandbox_status_literal_still_compiles() {
10-
// Intentionally no `..Default::default()`: adding even an optional public
11-
// field breaks existing downstream Rust exhaustive struct literals.
13+
fn next_minor_exhaustive_sandbox_status_literal_compiles() {
14+
// Intentionally no `..Default::default()`: future shape changes must be
15+
// reviewed against this declared minor baseline, never silently accepted.
1216
let status = SandboxStatus {
1317
agent_pod: String::new(),
1418
agent_fd: String::new(),
@@ -26,6 +30,7 @@ fn baseline_exhaustive_sandbox_status_literal_still_compiles() {
2630
next_restart_time: None,
2731
main_process_started_time: None,
2832
last_token_grant_failure: None,
33+
launch_policy: None,
2934
};
3035
assert_eq!(status, SandboxStatus::default());
3136
}

0 commit comments

Comments
 (0)