Skip to content

Commit 955284b

Browse files
committed
feat(policy): admit backend filesystem prerequisites
Compose trusted backend prerequisites before admission and preserve one policy/provider identity across delivered configuration and endpoint status. Closes #5108 Signed-off-by: Shiju <[email protected]>
1 parent c92c2c7 commit 955284b

18 files changed

Lines changed: 665 additions & 131 deletions

File tree

‎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+
/// Driver declares the proxy prerequisites admitted before runtime signing.
32+
pub const COMPUTE_PROXY_FILESYSTEM_BASELINE: &str = "openshell.compute.proxy-filesystem-baseline";
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_PROXY_FILESYSTEM_BASELINE.to_string());
136139
}
137140
PeerMetadata {
138141
protocol_version: Some(ProtocolVersion {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Trusted backend prerequisites composed before effective policy admission.
5+
6+
use std::collections::BTreeSet;
7+
8+
use crate::proto::SandboxPolicy;
9+
use crate::proto::compute::v1::ProxyFilesystemBaseline;
10+
11+
/// Proxy runtime paths selected by trusted backend composition.
12+
/// An explicit empty baseline suppresses legacy defaults.
13+
#[derive(Debug, Clone, Default, PartialEq, Eq)]
14+
pub struct FilesystemBaseline {
15+
pub read_only: Vec<String>,
16+
pub read_write: Vec<String>,
17+
}
18+
19+
impl From<ProxyFilesystemBaseline> for FilesystemBaseline {
20+
fn from(value: ProxyFilesystemBaseline) -> Self {
21+
Self {
22+
read_only: value.read_only,
23+
read_write: value.read_write,
24+
}
25+
}
26+
}
27+
28+
impl From<FilesystemBaseline> for ProxyFilesystemBaseline {
29+
fn from(value: FilesystemBaseline) -> Self {
30+
Self {
31+
read_only: value.read_only,
32+
read_write: value.read_write,
33+
}
34+
}
35+
}
36+
37+
impl FilesystemBaseline {
38+
/// Validate bounded, canonical POSIX path syntax without inspecting the
39+
/// gateway host filesystem, which need not be the workload's platform.
40+
pub fn validate(&self) -> Result<(), &'static str> {
41+
if self.read_only.len() + self.read_write.len() > 64 {
42+
return Err("proxy filesystem baseline has too many paths");
43+
}
44+
let mut seen = BTreeSet::new();
45+
for path in self.read_only.iter().chain(&self.read_write) {
46+
if path.len() > 4096
47+
|| !path.starts_with('/')
48+
|| path.chars().any(char::is_control)
49+
|| (path != "/"
50+
&& path[1..]
51+
.split('/')
52+
.any(|part| matches!(part, "" | "." | "..")))
53+
|| !seen.insert(path)
54+
{
55+
return Err(
56+
"proxy filesystem baseline requires unique canonical POSIX absolute paths",
57+
);
58+
}
59+
}
60+
Ok(())
61+
}
62+
63+
/// Add prerequisites to a proxy-mode policy without replacing explicit
64+
/// grants. An explicit read-only path stays read-only. `path_exists` is
65+
/// used only by legacy image-local Linux defaults; advertised prerequisites
66+
/// are unconditional and callers pass a predicate that always returns true.
67+
/// Validate the descriptor at the trusted admission boundary before use.
68+
pub fn enrich(&self, policy: &mut SandboxPolicy, path_exists: impl Fn(&str) -> bool) -> bool {
69+
if policy.network_policies.is_empty()
70+
|| (self.read_only.is_empty() && self.read_write.is_empty())
71+
{
72+
return false;
73+
}
74+
let filesystem = policy
75+
.filesystem
76+
.get_or_insert_with(|| crate::proto::FilesystemPolicy {
77+
include_workdir: true,
78+
..Default::default()
79+
});
80+
let mut modified = false;
81+
for path in &self.read_only {
82+
if !filesystem.read_only.contains(path)
83+
&& !filesystem.read_write.contains(path)
84+
&& path_exists(path)
85+
{
86+
filesystem.read_only.push(path.clone());
87+
modified = true;
88+
}
89+
}
90+
for path in &self.read_write {
91+
if !filesystem.read_only.contains(path)
92+
&& !filesystem.read_write.contains(path)
93+
&& path_exists(path)
94+
{
95+
filesystem.read_write.push(path.clone());
96+
modified = true;
97+
}
98+
}
99+
modified
100+
}
101+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub mod error;
2828
pub mod extension_protocol;
2929
#[cfg(unix)]
3030
pub mod external_driver_socket;
31+
pub mod filesystem_baseline;
3132
pub mod forward;
3233
pub mod google_cloud;
3334
pub mod gpu;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,7 @@ impl DockerComputeDriver {
11071107
}),
11081108
rootfs_tar_staging_dir: String::new(),
11091109
rootfs_tar_max_bytes: 0,
1110+
proxy_filesystem_baseline: None,
11101111
extension: Some(openshell_core::extension_protocol::extension_metadata(
11111112
openshell_core::extension_protocol::ExtensionFamily::Compute,
11121113
"openshell/docker",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ impl KubernetesComputeDriver {
13401340
}),
13411341
rootfs_tar_staging_dir: String::new(),
13421342
rootfs_tar_max_bytes: 0,
1343+
proxy_filesystem_baseline: None,
13431344
extension: Some(openshell_core::extension_protocol::extension_metadata(
13441345
openshell_core::extension_protocol::ExtensionFamily::Compute,
13451346
"openshell/kubernetes",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ impl MxcComputeBackend {
476476
resource_capabilities: None,
477477
rootfs_tar_staging_dir: String::new(),
478478
rootfs_tar_max_bytes: 0,
479+
proxy_filesystem_baseline: None,
479480
extension: Some(openshell_core::extension_protocol::extension_metadata(
480481
openshell_core::extension_protocol::ExtensionFamily::Compute,
481482
"openshell/mxc",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ impl PodmanComputeDriver {
766766
}),
767767
rootfs_tar_staging_dir: String::new(),
768768
rootfs_tar_max_bytes: 0,
769+
proxy_filesystem_baseline: None,
769770
extension: Some(openshell_core::extension_protocol::extension_metadata(
770771
openshell_core::extension_protocol::ExtensionFamily::Compute,
771772
"openshell/podman",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,7 @@ impl VmDriver {
16021602
.to_string_lossy()
16031603
.into_owned(),
16041604
rootfs_tar_max_bytes: self.config.rootfs_tar_max_bytes(),
1605+
proxy_filesystem_baseline: None,
16051606
extension: Some(extension),
16061607
}
16071608
}

‎crates/openshell-server/src/compute/mod.rs‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use hyper_util::rt::TokioIo;
3131
use openshell_core::extension_protocol::{
3232
ExtensionFamily, NegotiatedExtension, gateway_metadata, negotiate,
3333
};
34+
use openshell_core::filesystem_baseline::FilesystemBaseline;
3435
#[cfg(test)]
3536
use openshell_core::proto::ServiceAuthorizationMode;
3637
use openshell_core::proto::compute::v1::{
@@ -513,6 +514,8 @@ pub struct ComputeDriverInfoSnapshot {
513514
pub driver_reports_runtime_readiness: bool,
514515
/// Static portable resource request forms from the startup capability snapshot.
515516
pub resource_capabilities: Option<DriverResourceCapabilities>,
517+
/// Trusted workload proxy prerequisites, present only after negotiation.
518+
pub proxy_filesystem_baseline: Option<FilesystemBaseline>,
516519
/// Directory where rootfs tar files must be staged.
517520
pub rootfs_tar_staging_dir: String,
518521
/// Maximum rootfs tar file size in bytes.
@@ -1001,6 +1004,32 @@ impl ComputeRuntime {
10011004
capabilities.extension.clone(),
10021005
)
10031006
.map_err(|error| ComputeError::Message(error.to_string()))?;
1007+
let declares_baseline =
1008+
negotiated_extension
1009+
.supported_capabilities
1010+
.iter()
1011+
.any(|capability| {
1012+
capability
1013+
== openshell_core::extension_protocol::COMPUTE_PROXY_FILESYSTEM_BASELINE
1014+
});
1015+
let proxy_filesystem_baseline = match (
1016+
declares_baseline,
1017+
capabilities.proxy_filesystem_baseline.clone(),
1018+
) {
1019+
(false, None) => None,
1020+
(true, Some(descriptor)) => {
1021+
let baseline = FilesystemBaseline::from(descriptor);
1022+
baseline
1023+
.validate()
1024+
.map_err(|error| ComputeError::Message(error.to_string()))?;
1025+
Some(baseline)
1026+
}
1027+
_ => {
1028+
return Err(ComputeError::Message(
1029+
"compute proxy filesystem baseline capability and descriptor must agree".into(),
1030+
));
1031+
}
1032+
};
10041033
info!(
10051034
configured_driver = %driver_name,
10061035
advertised_driver = %capabilities.driver_name,
@@ -1015,6 +1044,7 @@ impl ComputeRuntime {
10151044
supports_sandbox_authentication: capabilities.supports_sandbox_authentication,
10161045
driver_reports_runtime_readiness: capabilities.driver_reports_runtime_readiness,
10171046
resource_capabilities: capabilities.resource_capabilities,
1047+
proxy_filesystem_baseline,
10181048
rootfs_tar_staging_dir: capabilities.rootfs_tar_staging_dir,
10191049
rootfs_tar_max_bytes: capabilities.rootfs_tar_max_bytes,
10201050
};
@@ -1301,6 +1331,10 @@ impl ComputeRuntime {
13011331
std::slice::from_ref(&self.driver_info)
13021332
}
13031333

1334+
pub(crate) fn proxy_filesystem_baseline(&self) -> Option<&FilesystemBaseline> {
1335+
self.driver_info.proxy_filesystem_baseline.as_ref()
1336+
}
1337+
13041338
#[must_use]
13051339
pub(crate) fn rootfs_tar_staging(&self) -> &rootfs_tar::RootfsTarStagingRegistry {
13061340
&self.rootfs_tar_staging
@@ -8406,6 +8440,7 @@ impl ComputeDriver for NoopTestDriver {
84068440
resource_capabilities: None,
84078441
rootfs_tar_staging_dir: String::new(),
84088442
rootfs_tar_max_bytes: 0,
8443+
proxy_filesystem_baseline: None,
84098444
extension: Some(openshell_core::extension_protocol::extension_metadata(
84108445
ExtensionFamily::Compute,
84118446
"openshell/noop-test-driver",
@@ -8601,6 +8636,7 @@ pub fn new_test_runtime_with_driver(
86018636
resource_capabilities: None,
86028637
rootfs_tar_staging_dir: String::new(),
86038638
rootfs_tar_max_bytes: 0,
8639+
proxy_filesystem_baseline: None,
86048640
},
86058641
telemetry_compute_driver: TelemetryComputeDriver::custom(),
86068642
driver_process: None,
@@ -9038,6 +9074,7 @@ mod tests {
90389074
resource_capabilities: None,
90399075
rootfs_tar_staging_dir: String::new(),
90409076
rootfs_tar_max_bytes: 0,
9077+
proxy_filesystem_baseline: None,
90419078
extension: (!self.omit_protocol_metadata).then(|| {
90429079
let mut metadata = openshell_core::extension_protocol::extension_metadata(
90439080
ExtensionFamily::Compute,
@@ -9504,6 +9541,7 @@ mod tests {
95049541
resource_capabilities: None,
95059542
rootfs_tar_staging_dir: String::new(),
95069543
rootfs_tar_max_bytes: 0,
9544+
proxy_filesystem_baseline: None,
95079545
extension: Some(openshell_core::extension_protocol::extension_metadata(
95089546
ExtensionFamily::Compute,
95099547
"openshell/controlled-test-driver",
@@ -9804,6 +9842,7 @@ mod tests {
98049842
resource_capabilities: None,
98059843
rootfs_tar_staging_dir: String::new(),
98069844
rootfs_tar_max_bytes: 0,
9845+
proxy_filesystem_baseline: None,
98079846
},
98089847
telemetry_compute_driver: TelemetryComputeDriver::custom(),
98099848
driver_process: None,
@@ -18624,6 +18663,83 @@ endpoint = { kind = "unix", socket_path = "/run/agent-substrate/isolation.sock"
1862418663
assert!(runtime.image_update_driver.is_none());
1862518664
}
1862618665

18666+
#[tokio::test]
18667+
async fn proxy_filesystem_baseline_handshake_requires_a_valid_matching_descriptor() {
18668+
use crate::test_support::FakeComputeDriver;
18669+
use openshell_core::extension_protocol::COMPUTE_PROXY_FILESYSTEM_BASELINE;
18670+
use openshell_core::proto::compute::v1::ProxyFilesystemBaseline;
18671+
18672+
let valid = ProxyFilesystemBaseline {
18673+
read_only: vec!["/System".into()],
18674+
read_write: vec!["/dev".into()],
18675+
};
18676+
for (declared, descriptor, accepted) in [
18677+
(false, None, true),
18678+
(true, Some(ProxyFilesystemBaseline::default()), true),
18679+
(true, Some(valid.clone()), true),
18680+
(true, None, false),
18681+
(false, Some(valid), false),
18682+
(
18683+
true,
18684+
Some(ProxyFilesystemBaseline {
18685+
read_only: vec!["/a/../b".into()],
18686+
..Default::default()
18687+
}),
18688+
false,
18689+
),
18690+
(
18691+
true,
18692+
Some(ProxyFilesystemBaseline {
18693+
read_only: vec!["/same".into()],
18694+
read_write: vec!["/same".into()],
18695+
}),
18696+
false,
18697+
),
18698+
(
18699+
true,
18700+
Some(ProxyFilesystemBaseline {
18701+
read_only: vec!["/a".into(); 65],
18702+
..Default::default()
18703+
}),
18704+
false,
18705+
),
18706+
] {
18707+
let expected = descriptor.clone().map(FilesystemBaseline::from);
18708+
let driver = Arc::new(FakeComputeDriver::new().with_capabilities(
18709+
GetCapabilitiesResponse {
18710+
proxy_filesystem_baseline: descriptor,
18711+
extension: Some(openshell_core::extension_protocol::extension_metadata(
18712+
ExtensionFamily::Compute,
18713+
"openshell/test",
18714+
"test",
18715+
if declared {
18716+
vec![COMPUTE_PROXY_FILESYSTEM_BASELINE.to_string()]
18717+
} else {
18718+
vec![]
18719+
},
18720+
)),
18721+
..Default::default()
18722+
},
18723+
));
18724+
let store = Arc::new(Store::connect("sqlite::memory:").await.unwrap());
18725+
let result = ComputeRuntime::from_driver(
18726+
"test".into(),
18727+
driver,
18728+
None,
18729+
store,
18730+
SandboxIndex::new(),
18731+
SandboxWatchBus::new(),
18732+
TracingLogBus::new(),
18733+
Arc::new(SupervisorSessionRegistry::new()),
18734+
)
18735+
.await;
18736+
assert_eq!(result.is_ok(), accepted);
18737+
if let Ok(runtime) = result {
18738+
assert_eq!(runtime.proxy_filesystem_baseline(), expected.as_ref());
18739+
}
18740+
}
18741+
}
18742+
1862718743
#[tokio::test]
1862818744
async fn negotiated_launch_requirement_rejects_create_before_driver_or_store() {
1862918745
let driver = Arc::new(TestDriver {

0 commit comments

Comments
 (0)