Skip to content

Commit 1358794

Browse files
committed
feat(compute): add provider workload identity contract
Add the contract that the gateway and a compute driver share to give each dedicated supervisor a SPIFFE identity for provider grants. - A capability, openshell.compute.provider-workload-identity, for a driver that gives each dedicated supervisor a Workload API socket and marks it with its launch SPIFFE ID. - The launch bundle can carry the stable sandbox SPIFFE ID and the launch SPIFFE ID. The launch ID is the stable ID followed by /launch/<runtime generation>, so it changes when the gateway issues a new generation. - validate_provider_launch_identity lets a driver check that both IDs belong to the sandbox and generation it is starting. - ConfigureRequest gains a flag that tells a managed driver the mode is selected. - Label and probe constants shared by the supervisor and the drivers. Nothing uses the contract yet. Existing call sites only initialize the new fields. Signed-off-by: Shiju <shiju@nvidia.com>
1 parent 659b45f commit 1358794

17 files changed

Lines changed: 248 additions & 16 deletions

File tree

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

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,61 @@ use std::path::{Path, PathBuf};
88

99
use crate::proto::compute::v1::DriverSandbox;
1010

11+
/// Check that a launch bundle's provider identities belong to this sandbox launch.
12+
///
13+
/// The stable ID must end in this gateway and sandbox. The launch ID must be
14+
/// that stable ID followed by `/launch/<generation>`, so it changes exactly
15+
/// when the gateway issues a new runtime generation. A driver calls this
16+
/// before it marks a supervisor with the launch ID.
17+
#[cfg(feature = "jwt")]
18+
#[allow(clippy::result_large_err)]
19+
pub fn validate_provider_launch_identity(
20+
sandbox_id: &str,
21+
generation_id: &str,
22+
authentication: &crate::jwt::SandboxLaunchAuthentication,
23+
) -> Result<(), tonic::Status> {
24+
let invalid =
25+
|| tonic::Status::invalid_argument("provider identity does not match the sandbox launch");
26+
let supervisor = &authentication.supervisor;
27+
if supervisor.runtime_generation.as_str() != generation_id {
28+
return Err(invalid());
29+
}
30+
let sandbox_path = format!(
31+
"/gateway/{}/sandbox/{sandbox_id}",
32+
authentication.gateway_id
33+
);
34+
let prefix = supervisor
35+
.provider_spiffe_id
36+
.as_deref()
37+
.and_then(|id| id.strip_suffix(&sandbox_path))
38+
.ok_or_else(invalid)?;
39+
let prefix = openshell_spiffe::SandboxSpiffeIdPrefix::parse(prefix).map_err(|_| invalid())?;
40+
let expected = prefix
41+
.supervisor_launch_spiffe_id(&authentication.gateway_id, sandbox_id, generation_id)
42+
.map_err(|_| invalid())?;
43+
if supervisor.provider_launch_spiffe_id.as_deref() != Some(expected.as_str()) {
44+
return Err(invalid());
45+
}
46+
Ok(())
47+
}
48+
49+
/// Gateway alias available inside a sandbox VM.
50+
pub const VM_HOST_GATEWAY_ALIAS: &str = "host.openshell.internal";
51+
52+
/// Gateway hostnames that VM host supervisors rewrite to numeric loopback.
53+
pub const VM_HOST_LOOPBACK_ALIASES: &[&str] = &[
54+
VM_HOST_GATEWAY_ALIAS,
55+
"host.containers.internal",
56+
"host.docker.internal",
57+
];
58+
59+
/// Supervisor command that reports whether it can see a Workload API socket.
60+
pub const PROVIDER_WORKLOAD_IDENTITY_PROBE: &str = "provider-workload-identity-probe";
61+
62+
/// Exit statuses for the provider probe with a socket path argument.
63+
pub const PROVIDER_WORKLOAD_SOCKET_PROBE_PRESENT: i32 = 70;
64+
pub const PROVIDER_WORKLOAD_SOCKET_PROBE_UNAVAILABLE: i32 = 71;
65+
1166
// ---------------------------------------------------------------------------
1267
// Sandbox container/pod label keys (openshell.ai/ namespace)
1368
// ---------------------------------------------------------------------------
@@ -34,6 +89,9 @@ pub const LABEL_SANDBOX_WORKSPACE: &str = "openshell.ai/sandbox-workspace";
3489
/// Label carrying the gateway identity on managed namespaces.
3590
pub const LABEL_GATEWAY_ID: &str = "openshell.ai/gateway-id";
3691

92+
/// SPIFFE ID registered for one driver-owned supervisor launch.
93+
pub const LABEL_PROVIDER_LAUNCH_SPIFFE_ID: &str = "openshell.ai/provider-launch-spiffe-id";
94+
3795
/// Label selector that matches all OpenShell-managed resources which carry a
3896
/// sandbox ID label. Used by list and watch operations to exclude foreign
3997
/// resources from the same namespace.
@@ -743,6 +801,24 @@ pub fn validate_provider_spiffe_unix_socket(path: &Path) -> Result<(), String> {
743801
Ok(())
744802
}
745803

804+
/// Check that an absolute path resolves to a Unix socket in the current filesystem.
805+
pub fn provider_spiffe_socket_visible(path: &Path) -> bool {
806+
#[cfg(unix)]
807+
{
808+
use std::os::unix::fs::FileTypeExt as _;
809+
810+
path.is_absolute()
811+
&& path
812+
.metadata()
813+
.is_ok_and(|meta| meta.file_type().is_socket())
814+
}
815+
#[cfg(not(unix))]
816+
{
817+
let _ = path;
818+
false
819+
}
820+
}
821+
746822
/// Return the guest/container path for a projected provider SPIFFE socket.
747823
pub fn projected_provider_spiffe_socket_path(path: &Path) -> Result<String, String> {
748824
validate_provider_spiffe_unix_socket(path)?;
@@ -1550,4 +1626,93 @@ mod tests {
15501626
})
15511627
.expect("an intercepting proxy's CA is meaningful without an https:// proxy URL");
15521628
}
1629+
1630+
#[cfg(feature = "jwt")]
1631+
#[test]
1632+
fn provider_launch_identity_binds_generation_sandbox_and_launch() {
1633+
use crate::jwt::{
1634+
CredentialEpoch, SandboxLaunchAuthentication, SecretJwt, SessionRotation,
1635+
SupervisorAuthBundle,
1636+
};
1637+
use crate::sandbox_generation::SandboxGenerationId;
1638+
use crate::sandbox_session::SandboxSessionId;
1639+
1640+
let sandbox = "spiffe://example.test/gateway/gateway/sandbox/sandbox-a";
1641+
let authentication = SandboxLaunchAuthentication {
1642+
supervisor: SupervisorAuthBundle {
1643+
session_id: SandboxSessionId::new(),
1644+
runtime_generation: SandboxGenerationId::parse("generation").unwrap(),
1645+
session_rotation: SessionRotation::new(1).unwrap(),
1646+
auth_epoch: CredentialEpoch::new(1).unwrap(),
1647+
gateway_token: SecretJwt::parse("gateway-token").unwrap(),
1648+
gateway_expires_at: 0,
1649+
sandbox_token: SecretJwt::parse("sandbox-token").unwrap(),
1650+
sandbox_expires_at: 0,
1651+
provider_spiffe_id: Some(sandbox.to_string()),
1652+
provider_launch_spiffe_id: Some(format!("{sandbox}/launch/generation")),
1653+
ssh_host_private_key: None,
1654+
traces_otlp_headers: None,
1655+
ocsf_otlp_headers: None,
1656+
agent_otlp_headers: None,
1657+
otlp_tls: Vec::new(),
1658+
traces_otlp_tls: None,
1659+
ocsf_otlp_tls: None,
1660+
agent_otlp_tls: None,
1661+
},
1662+
gateway_id: "gateway".to_string(),
1663+
verification_keys: Vec::new(),
1664+
};
1665+
validate_provider_launch_identity("sandbox-a", "generation", &authentication).unwrap();
1666+
1667+
let with_launch = |launch: Option<String>| {
1668+
let mut changed = authentication.clone();
1669+
changed.supervisor.provider_launch_spiffe_id = launch;
1670+
changed
1671+
};
1672+
for (case, sandbox_id, generation_id, bundle) in [
1673+
(
1674+
"another generation",
1675+
"sandbox-a",
1676+
"other-generation",
1677+
authentication.clone(),
1678+
),
1679+
(
1680+
"another sandbox",
1681+
"sandbox-b",
1682+
"generation",
1683+
authentication.clone(),
1684+
),
1685+
(
1686+
"no launch identity",
1687+
"sandbox-a",
1688+
"generation",
1689+
with_launch(None),
1690+
),
1691+
(
1692+
"a launch identity of another sandbox",
1693+
"sandbox-a",
1694+
"generation",
1695+
with_launch(Some(
1696+
"spiffe://example.test/gateway/gateway/sandbox/sandbox-b/launch/generation"
1697+
.to_string(),
1698+
)),
1699+
),
1700+
(
1701+
"a launch identity for another generation",
1702+
"sandbox-a",
1703+
"generation",
1704+
with_launch(Some(format!("{sandbox}/launch/earlier-generation"))),
1705+
),
1706+
(
1707+
"a launch identity with extra segments",
1708+
"sandbox-a",
1709+
"generation",
1710+
with_launch(Some(format!("{sandbox}/launch/generation/extra"))),
1711+
),
1712+
] {
1713+
let error =
1714+
validate_provider_launch_identity(sandbox_id, generation_id, &bundle).unwrap_err();
1715+
assert_eq!(error.code(), tonic::Code::InvalidArgument, "{case}");
1716+
}
1717+
}
15531718
}

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ pub const COMPUTE_SUSPEND_RESUME: &str = "openshell.compute.suspend-resume";
4747
pub const COMPUTE_UPDATE_SANDBOX_CONFIGURATION: &str =
4848
"openshell.compute.update-sandbox-configuration";
4949

50+
/// Driver gives each dedicated supervisor a Workload API socket and marks it
51+
/// with the launch SPIFFE ID from its launch bundle. A start whose bundle
52+
/// names a different launch replaces the supervisor.
53+
pub const COMPUTE_PROVIDER_WORKLOAD_IDENTITY: &str = "openshell.compute.provider-workload-identity";
54+
5055
/// Capability for supervisor middleware that implements HTTP hooks.
5156
///
5257
/// A service selects HTTP hooks for all of its HTTP bindings by
@@ -160,6 +165,7 @@ pub fn gateway_metadata(family: ExtensionFamily) -> PeerMetadata {
160165
supported_capabilities.push(COMPUTE_LAUNCH_AUTHENTICATION.to_string());
161166
supported_capabilities.push(COMPUTE_ISOLATION_BACKEND.to_string());
162167
supported_capabilities.push(COMPUTE_UPDATE_SANDBOX_CONFIGURATION.to_string());
168+
supported_capabilities.push(COMPUTE_PROVIDER_WORKLOAD_IDENTITY.to_string());
163169
}
164170
ExtensionFamily::SupervisorMiddleware => {
165171
supported_capabilities.push(SUPERVISOR_MIDDLEWARE_HTTP_HOOKS.to_string());
@@ -458,20 +464,15 @@ mod tests {
458464
use super::*;
459465

460466
#[test]
461-
fn compute_gateway_advertises_both_optional_extensions() {
467+
fn compute_gateway_advertises_optional_extensions() {
462468
let gateway = gateway_metadata(ExtensionFamily::Compute);
463-
assert!(
464-
gateway
465-
.supported_capabilities
466-
.iter()
467-
.any(|c| c == COMPUTE_ISOLATION_BACKEND)
468-
);
469-
assert!(
470-
gateway
471-
.supported_capabilities
472-
.iter()
473-
.any(|c| c == COMPUTE_UPDATE_SANDBOX_CONFIGURATION)
474-
);
469+
for capability in [
470+
COMPUTE_ISOLATION_BACKEND,
471+
COMPUTE_UPDATE_SANDBOX_CONFIGURATION,
472+
COMPUTE_PROVIDER_WORKLOAD_IDENTITY,
473+
] {
474+
assert!(has_capability(&gateway.supported_capabilities, capability));
475+
}
475476
}
476477

477478
fn compatible() -> (PeerMetadata, PeerMetadata) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,12 @@ mod session {
499499
pub gateway_expires_at: i64,
500500
pub sandbox_token: SecretJwt,
501501
pub sandbox_expires_at: i64,
502+
/// Exact provider identity selected by the gateway for this supervisor.
503+
#[serde(default, skip_serializing_if = "Option::is_none")]
504+
pub provider_spiffe_id: Option<String>,
505+
/// SPIFFE ID the issuer assigns to this supervisor launch.
506+
#[serde(default, skip_serializing_if = "Option::is_none")]
507+
pub provider_launch_spiffe_id: Option<String>,
502508
/// Never delivered to the workload. Missing only in older bundles.
503509
#[serde(default, skip_serializing_if = "Option::is_none")]
504510
pub ssh_host_private_key: Option<SecretSshHostKey>,
@@ -1787,6 +1793,8 @@ mod tests {
17871793
gateway_expires_at: pair.gateway.expires_at,
17881794
sandbox_token: pair.sandbox.token,
17891795
sandbox_expires_at: pair.sandbox.expires_at,
1796+
provider_spiffe_id: None,
1797+
provider_launch_spiffe_id: None,
17901798
ssh_host_private_key: None,
17911799
traces_otlp_headers: None,
17921800
ocsf_otlp_headers: None,
@@ -1935,6 +1943,8 @@ mod tests {
19351943
gateway_expires_at: pair.gateway.expires_at,
19361944
sandbox_token: pair.sandbox.token,
19371945
sandbox_expires_at: pair.sandbox.expires_at,
1946+
provider_spiffe_id: None,
1947+
provider_launch_spiffe_id: None,
19381948
ssh_host_private_key: None,
19391949
traces_otlp_headers: headers("traces"),
19401950
ocsf_otlp_headers: headers("ocsf"),
@@ -1974,6 +1984,8 @@ mod tests {
19741984
gateway_expires_at: pair.gateway.expires_at,
19751985
sandbox_token: pair.sandbox.token,
19761986
sandbox_expires_at: pair.sandbox.expires_at,
1987+
provider_spiffe_id: None,
1988+
provider_launch_spiffe_id: None,
19771989
ssh_host_private_key: Some(SecretSshHostKey::new(
19781990
"private-ssh-host-key".to_string(),
19791991
)),

‎crates/openshell-driver-docker/src/tests.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub fn test_launch_authentication() -> Vec<u8> {
6363
gateway_expires_at: i64::MAX,
6464
sandbox_token: SecretJwt::parse("sandbox.token.value").unwrap(),
6565
sandbox_expires_at: i64::MAX,
66+
provider_spiffe_id: None,
67+
provider_launch_spiffe_id: None,
6668
ssh_host_private_key: None,
6769
traces_otlp_headers: None,
6870
ocsf_otlp_headers: None,

‎crates/openshell-driver-podman/src/driver.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,8 @@ mod tests {
27042704
gateway_expires_at: i64::MAX,
27052705
sandbox_token: SecretJwt::parse("sandbox.token.value").unwrap(),
27062706
sandbox_expires_at: i64::MAX,
2707+
provider_spiffe_id: None,
2708+
provider_launch_spiffe_id: None,
27072709
ssh_host_private_key: None,
27082710
traces_otlp_headers: None,
27092711
ocsf_otlp_headers: None,

‎crates/openshell-driver-podman/src/isolation.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ mod tests {
470470
gateway_expires_at: i64::MAX,
471471
sandbox_token: SecretJwt::parse("sandbox.token.value").unwrap(),
472472
sandbox_expires_at: i64::MAX,
473+
provider_spiffe_id: None,
474+
provider_launch_spiffe_id: None,
473475
ssh_host_private_key: None,
474476
traces_otlp_headers: None,
475477
ocsf_otlp_headers: None,

‎crates/openshell-driver-vm/src/driver.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11265,6 +11265,8 @@ mod tests {
1126511265
gateway_expires_at: 1,
1126611266
sandbox_token: SecretJwt::parse(format!("sandbox-{label}")).expect("sandbox token"),
1126711267
sandbox_expires_at: 1,
11268+
provider_spiffe_id: None,
11269+
provider_launch_spiffe_id: None,
1126811270
ssh_host_private_key: None,
1126911271
traces_otlp_headers: None,
1127011272
ocsf_otlp_headers: None,

‎crates/openshell-gateway/src/launcher.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ impl<'a> ConfigureInputs<'a> {
872872
.admission
873873
.and_then(|policy| serde_json::to_string(policy).ok())
874874
.unwrap_or_default(),
875+
verified_provider_workload_identity: None,
875876
}
876877
}
877878
}

‎crates/openshell-server/src/auth/sandbox_jwt.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ impl SandboxSessionJwtAuthority {
264264
gateway_expires_at: pair.gateway.expires_at,
265265
sandbox_token: pair.sandbox.token,
266266
sandbox_expires_at: pair.sandbox.expires_at,
267+
provider_spiffe_id: None,
268+
provider_launch_spiffe_id: None,
267269
ssh_host_private_key: None,
268270
traces_otlp_headers: None,
269271
ocsf_otlp_headers: None,
@@ -616,6 +618,9 @@ mod tests {
616618
let first = authority
617619
.mint_persisted_launch("sandbox-a", &identity)
618620
.unwrap();
621+
// The session authority leaves the provider identities unset.
622+
assert!(first.supervisor.provider_spiffe_id.is_none());
623+
assert!(first.supervisor.provider_launch_spiffe_id.is_none());
619624
let mut annotations = std::collections::HashMap::new();
620625
identity.write(&mut annotations);
621626
let mut reloaded =

‎crates/openshell-server/src/persistence/mutation_lock_pg_tests.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ async fn postgres_concurrent_sandbox_creates_with_ssh_identity_do_not_exhaust_lo
8989
gateway_expires_at: 0,
9090
sandbox_token: SecretJwt::parse("sandbox-token").unwrap(),
9191
sandbox_expires_at: 0,
92+
provider_spiffe_id: None,
93+
provider_launch_spiffe_id: None,
9294
ssh_host_private_key: None,
9395
traces_otlp_headers: None,
9496
ocsf_otlp_headers: None,
@@ -211,6 +213,8 @@ fn ssh_launch_authentication() -> openshell_core::jwt::SandboxLaunchAuthenticati
211213
gateway_expires_at: 0,
212214
sandbox_token: SecretJwt::parse("sandbox-token").unwrap(),
213215
sandbox_expires_at: 0,
216+
provider_spiffe_id: None,
217+
provider_launch_spiffe_id: None,
214218
ssh_host_private_key: None,
215219
traces_otlp_headers: None,
216220
ocsf_otlp_headers: None,

0 commit comments

Comments
 (0)