Skip to content

Commit c4bccda

Browse files
committed
refactor(sandbox): keep runtime transports behind the backend
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent b0041e4 commit c4bccda

4 files changed

Lines changed: 91 additions & 40 deletions

File tree

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,12 @@ pub enum SandboxTransport {
2929
guest_cid: u32,
3030
port: u32,
3131
},
32-
/// The supervisor accepts a connection from its sandbox runtime. TLS and
33-
/// gRPC roles stay unchanged.
34-
RuntimeInitiatedTcp {
35-
authority: String,
36-
listen_address: SocketAddr,
37-
},
38-
RuntimeInitiatedUnix {
39-
socket_path: PathBuf,
40-
},
41-
RuntimeInitiatedVsock {
42-
guest_cid: u32,
43-
port: u32,
44-
},
4532
}
4633

4734
impl SandboxTransport {
4835
pub fn validate(&self) -> Result<(), &'static str> {
4936
let valid = match self {
50-
Self::Unix { socket_path } | Self::RuntimeInitiatedUnix { socket_path } => {
51-
socket_path.is_absolute()
52-
}
37+
Self::Unix { socket_path } => socket_path.is_absolute(),
5338
Self::Tcp {
5439
authority,
5540
addresses,
@@ -60,11 +45,7 @@ impl SandboxTransport {
6045
.iter()
6146
.all(|address| address.port() != 0 && !address.ip().is_unspecified())
6247
}
63-
Self::RuntimeInitiatedTcp {
64-
authority,
65-
listen_address,
66-
} => !authority.is_empty() && listen_address.port() != 0,
67-
Self::Vsock { guest_cid, port } | Self::RuntimeInitiatedVsock { guest_cid, port } => {
48+
Self::Vsock { guest_cid, port } => {
6849
*guest_cid >= 3 && *guest_cid != u32::MAX && *port != 0 && *port != u32::MAX
6950
}
7051
};
@@ -101,14 +82,6 @@ pub fn validate_registrations(registrations: &[BackendRegistration]) -> Result<(
10182
let mut names = BTreeSet::new();
10283
for registration in registrations {
10384
validate_backend_name(&registration.name)?;
104-
if matches!(
105-
registration.endpoint,
106-
SandboxTransport::RuntimeInitiatedTcp { .. }
107-
| SandboxTransport::RuntimeInitiatedUnix { .. }
108-
| SandboxTransport::RuntimeInitiatedVsock { .. }
109-
) {
110-
return Err("runtime-initiated control is not a registered backend endpoint");
111-
}
11285
if !names.insert(&registration.name) {
11386
return Err("duplicate isolation backend registration");
11487
}
@@ -128,11 +101,6 @@ impl TryFrom<&BackendRegistration> for crate::proto::compute::v1::IsolationBacke
128101
validate_backend_name(&registration.name)?;
129102
registration.endpoint.validate()?;
130103
let endpoint = match &registration.endpoint {
131-
SandboxTransport::RuntimeInitiatedTcp { .. }
132-
| SandboxTransport::RuntimeInitiatedUnix { .. }
133-
| SandboxTransport::RuntimeInitiatedVsock { .. } => {
134-
return Err("runtime-initiated control is not a registered backend endpoint");
135-
}
136104
SandboxTransport::Unix { socket_path } => Endpoint::UnixSocketPath(
137105
socket_path
138106
.to_str()

‎crates/openshell-sandbox-backend/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ retain generation, session, resource, identity, and provisioning evidence checks
102102

103103
## Boundary transport establishment
104104

105+
`SandboxTransport` belongs to this backend's runtime descriptor. Core retains
106+
only operator-registered endpoints; `DelegatedLaunch` converts those endpoints
107+
into the backend's transport without changing their serialized representation.
108+
105109
The supervisor chooses one `BoundaryTransport` per runtime descriptor and uses
106110
clones of it for policy discovery and attachment. It dials the descriptor's
107111
endpoint, uses a backend-supplied `BoundaryTransportConnector` for raw stream

‎crates/openshell-sandbox-backend/src/boundary_protocol.rs‎

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,88 @@ impl<'de> Deserialize<'de> for SupervisorInstanceId {
238238
#[error("supervisor instance ID must be a non-nil canonical lowercase UUID")]
239239
pub struct SupervisorInstanceIdError;
240240

241-
pub use openshell_core::isolation_registration::SandboxTransport;
241+
/// Backend-owned transport for a driver-provisioned runtime. The serialized
242+
/// variants preserve existing runtime descriptors independently of operator
243+
/// endpoint registration in core.
244+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
245+
#[serde(tag = "kind", rename_all = "kebab-case", deny_unknown_fields)]
246+
pub enum SandboxTransport {
247+
Unix {
248+
socket_path: PathBuf,
249+
},
250+
Tcp {
251+
/// Logical HTTP authority used for routing.
252+
authority: String,
253+
/// Concrete connection candidates pinned by the operator or driver.
254+
addresses: Vec<std::net::SocketAddr>,
255+
},
256+
Vsock {
257+
guest_cid: u32,
258+
port: u32,
259+
},
260+
/// The supervisor accepts a connection from its sandbox runtime. TLS and
261+
/// gRPC roles stay unchanged.
262+
RuntimeInitiatedTcp {
263+
authority: String,
264+
listen_address: std::net::SocketAddr,
265+
},
266+
RuntimeInitiatedUnix {
267+
socket_path: PathBuf,
268+
},
269+
RuntimeInitiatedVsock {
270+
guest_cid: u32,
271+
port: u32,
272+
},
273+
}
274+
275+
impl SandboxTransport {
276+
pub fn validate(&self) -> Result<(), &'static str> {
277+
let valid = match self {
278+
Self::Unix { socket_path } | Self::RuntimeInitiatedUnix { socket_path } => {
279+
socket_path.is_absolute()
280+
}
281+
Self::Tcp {
282+
authority,
283+
addresses,
284+
} => {
285+
!authority.is_empty()
286+
&& !addresses.is_empty()
287+
&& addresses
288+
.iter()
289+
.all(|address| address.port() != 0 && !address.ip().is_unspecified())
290+
}
291+
Self::RuntimeInitiatedTcp {
292+
authority,
293+
listen_address,
294+
} => !authority.is_empty() && listen_address.port() != 0,
295+
Self::Vsock { guest_cid, port } | Self::RuntimeInitiatedVsock { guest_cid, port } => {
296+
*guest_cid >= 3 && *guest_cid != u32::MAX && *port != 0 && *port != u32::MAX
297+
}
298+
};
299+
if valid {
300+
Ok(())
301+
} else {
302+
Err("invalid boundary control transport endpoint")
303+
}
304+
}
305+
}
306+
307+
impl From<openshell_core::isolation_registration::SandboxTransport> for SandboxTransport {
308+
fn from(endpoint: openshell_core::isolation_registration::SandboxTransport) -> Self {
309+
use openshell_core::isolation_registration::SandboxTransport as RegisteredEndpoint;
310+
match endpoint {
311+
RegisteredEndpoint::Unix { socket_path } => Self::Unix { socket_path },
312+
RegisteredEndpoint::Tcp {
313+
authority,
314+
addresses,
315+
} => Self::Tcp {
316+
authority,
317+
addresses,
318+
},
319+
RegisteredEndpoint::Vsock { guest_cid, port } => Self::Vsock { guest_cid, port },
320+
}
321+
}
322+
}
242323

243324
/// Supervisor-side, generation-pinned TLS server authentication.
244325
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]

‎crates/openshell-sandbox-backend/src/delegated.rs‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use openshell_isolation_interface::contract::{
1212
};
1313
use serde::{Deserialize, Serialize};
1414

15-
use crate::boundary_protocol::{
16-
SandboxRuntimeDescriptor, SandboxTlsClientConfig, SandboxTransport,
17-
};
15+
use crate::boundary_protocol::{SandboxRuntimeDescriptor, SandboxTlsClientConfig};
1816

1917
/// Delivered by the trusted driver separately from its opaque backend payload.
2018
/// Endpoint selection belongs to operator configuration, not launch data.
@@ -37,15 +35,15 @@ impl DelegatedLaunch {
3735
/// Combine driver-owned identity and TLS with the operator-owned endpoint.
3836
pub fn runtime_descriptor(
3937
self,
40-
transport: SandboxTransport,
38+
transport: openshell_core::isolation_registration::SandboxTransport,
4139
) -> Result<SandboxRuntimeDescriptor, BackendError> {
4240
validate_backend_name(&self.backend_name)?;
4341
let descriptor = SandboxRuntimeDescriptor {
4442
boundary_id: self.sandbox_id,
4543
generation: self.generation,
4644
session_id: self.session_id,
4745
workload_identity: self.workload_identity,
48-
transport,
46+
transport: transport.into(),
4947
tls: self.tls,
5048
host_gateway_ip: self.host_gateway_ip,
5149
resource_claims: self.resource_claims,

0 commit comments

Comments
 (0)