Skip to content

Commit 6d8bed5

Browse files
committed
feat(drivers): deliver the admission policy in Configure
The gateway owns allow_driver_config and resource_admission. It validates them, removes them from the forwarded driver table, and sends the policy in a new Configure field. The launched drivers reject the keys in their tables and apply the policy from Configure. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 5a44137 commit 6d8bed5

17 files changed

Lines changed: 185 additions & 40 deletions

File tree

‎crates/openshell-driver-podman/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,4 @@ The gateway passes the `[openshell.drivers.podman]` table on stdin and gateway m
176176

177177
`serve` resolves the Podman socket from `OPENSHELL_PODMAN_SOCKET`, `socket_path`, or discovery, and pings it before it binds. It exits 69 when Podman is not reachable and 78 when the table is invalid. Until `Configure` succeeds, `ComputeDriver` calls return `UNAVAILABLE` and the driver creates no networks, volumes, or secrets. `preflight` validates the table without contacting Podman.
178178

179-
The gateway port and name, trusted runtime images, and OTLP settings come from `Configure`. Trusted runtime images from the gateway's environment take precedence over the table, as they did when the driver ran in process. The gateway supplies `gateway_port` and the CA, so the table rejects `gateway_port` and `guest_tls_ca`. `grpc_endpoint` remains an optional override, and an `https://` endpoint needs the gateway CA.
179+
The gateway port and name, trusted runtime images, and OTLP settings come from `Configure`. Trusted runtime images from the gateway's environment take precedence over the table, as they did when the driver ran in process. The gateway supplies `gateway_port` and the CA, so the table rejects `gateway_port`, `guest_tls_ca` and the admission keys (`allow_driver_config`, `resource_admission`), which the gateway delivers in `Configure`. `grpc_endpoint` remains an optional override, and an `https://` endpoint needs the gateway CA.

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,12 @@ pub fn settings_from_table(table: &str) -> Result<PodmanComputeConfig, String> {
288288
}
289289

290290
/// Settings the gateway supplies through `Configure` instead of the table.
291-
const GATEWAY_SUPPLIED_KEYS: &[&str] = &["gateway_port", "guest_tls_ca"];
291+
const GATEWAY_SUPPLIED_KEYS: &[&str] = &[
292+
"gateway_port",
293+
"guest_tls_ca",
294+
"allow_driver_config",
295+
"resource_admission",
296+
];
292297

293298
impl PodmanComputeConfig {
294299
/// Validate and normalize startup configuration without connecting to Podman.
@@ -654,7 +659,12 @@ mod table_tests {
654659

655660
#[test]
656661
fn gateway_supplied_keys_are_rejected() {
657-
for key in ["gateway_port = 8080", "guest_tls_ca = \"/ca.pem\""] {
662+
for key in [
663+
"gateway_port = 8080",
664+
"guest_tls_ca = \"/ca.pem\"",
665+
"allow_driver_config = true",
666+
"resource_admission = {}",
667+
] {
658668
let error = settings_from_table(key).unwrap_err();
659669
assert!(error.contains("supplied by the gateway"), "{error}");
660670
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,15 @@ async fn apply_configure(
146146
}
147147
let supervisor_otlp = openshell_driver_sdk::supervisor_otlp(request.telemetry.as_ref())?;
148148
let network_trust = openshell_driver_sdk::load_network_trust(request.network_trust.as_ref())?;
149-
let config = driver_config(
149+
let admission = openshell_driver_sdk::admission_from_json(&request.admission_json)?;
150+
let mut config = driver_config(
150151
settings,
151152
&gateway,
152153
request.image_overrides.as_ref(),
153154
supervisor_otlp,
154155
)?;
156+
config.allow_driver_config = admission.allow_driver_config;
157+
config.resource_admission = admission.resource_admission;
155158
let driver = PodmanComputeDriver::new(config, network_trust)
156159
.await
157160
.map_err(|error| Status::internal(error.to_string()))?;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use openshell_core::resource_admission::DriverAdmissionConfig;
5+
use tonic::Status;
6+
7+
/// The admission policy the gateway sent in `Configure`.
8+
///
9+
/// Empty means the defaults. The gateway validates the policy before it sends
10+
/// it; the driver checks it again so a malformed message cannot weaken
11+
/// admission.
12+
pub fn admission_from_json(json: &str) -> Result<DriverAdmissionConfig, Status> {
13+
if json.trim().is_empty() {
14+
return Ok(DriverAdmissionConfig::default());
15+
}
16+
let policy: DriverAdmissionConfig = serde_json::from_str(json)
17+
.map_err(|error| Status::invalid_argument(format!("invalid admission policy: {error}")))?;
18+
policy.validate().map_err(Status::invalid_argument)?;
19+
Ok(policy)
20+
}
21+
22+
#[cfg(test)]
23+
mod tests {
24+
use super::*;
25+
26+
#[test]
27+
fn empty_means_the_secure_defaults() {
28+
let policy = admission_from_json("").unwrap();
29+
assert!(!policy.allow_driver_config);
30+
}
31+
32+
#[test]
33+
fn a_policy_round_trips() {
34+
let sent = DriverAdmissionConfig {
35+
allow_driver_config: true,
36+
..DriverAdmissionConfig::default()
37+
};
38+
let json = serde_json::to_string(&sent).unwrap();
39+
assert!(admission_from_json(&json).unwrap().allow_driver_config);
40+
}
41+
42+
#[test]
43+
fn malformed_json_is_invalid() {
44+
let status = admission_from_json("{not json").unwrap_err();
45+
assert_eq!(status.code(), tonic::Code::InvalidArgument);
46+
}
47+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! failures with a stable exit code and one JSON line on stdout, and receives
88
//! gateway metadata through [`launch`]'s `Configure` RPC.
99
10+
mod admission;
1011
mod endpoint;
1112
mod gateway;
1213
mod guard;
@@ -15,6 +16,7 @@ mod table;
1516
mod telemetry;
1617
mod trust;
1718

19+
pub use admission::admission_from_json;
1820
pub use endpoint::{endpoint_uses_tls, validate_grpc_endpoint};
1921
pub use gateway::GatewayContext;
2022
#[cfg(unix)]

‎crates/openshell-driver-vm/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,4 @@ openshell-driver-vm serve --bind-socket <path> --expected-peer-pid <pid> --log-l
349349
openshell-driver-vm preflight < table.toml
350350
```
351351
352-
`settings_from_table` in `src/settings.rs` is the only place the table is parsed and validated. `serve` exits 78 on an invalid table. The driver binds its socket and answers `GetLaunchInfo` at once, but `ComputeDriver` calls return `UNAVAILABLE` and no VM state is created until `Configure` succeeds. `preflight` validates the table and exits.
352+
`settings_from_table` in `src/settings.rs` is the only place the table is parsed and validated. `serve` exits 78 on an invalid table. The table rejects `guest_tls_ca`, `gateway_port` and the admission keys, which the gateway supplies in `Configure`. The driver binds its socket and answers `GetLaunchInfo` at once, but `ComputeDriver` calls return `UNAVAILABLE` and no VM state is created until `Configure` succeeds. `preflight` validates the table and exits.

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,28 @@ async fn apply_configure(
162162
tracing::error!(%error, "OTLP exporting could not be started");
163163
}
164164
let supervisor_otlp = openshell_driver_sdk::supervisor_otlp(request.telemetry.as_ref())?;
165+
let admission = openshell_driver_sdk::admission_from_json(&request.admission_json)?;
165166
let config = driver_config(
166167
settings,
167168
&gateway,
168169
request.network_trust.as_ref(),
169170
supervisor_otlp,
171+
admission,
170172
log_level,
171173
gpu,
172174
)?;
173175
VmDriver::new(config).await.map_err(Status::internal)
174176
}
175177

176178
/// The driver configuration for `settings` and the gateway's metadata. An
177-
/// explicit table value wins over the gateway context.
179+
/// explicit `grpc_endpoint` wins over the gateway context. The gateway
180+
/// supplies the admission policy.
178181
fn driver_config(
179182
settings: VmSettings,
180183
gateway: &GatewayContext,
181184
network_trust: Option<&openshell_driver_sdk::launch::NetworkTrust>,
182185
supervisor_otlp: openshell_core::sandbox_env::SupervisorOtlp,
186+
admission: openshell_core::resource_admission::DriverAdmissionConfig,
183187
log_level: &str,
184188
(gpu_enabled, gpu_mem_mib, gpu_vcpus): (bool, u32, u8),
185189
) -> Result<VmDriverConfig, Status> {
@@ -202,8 +206,8 @@ fn driver_config(
202206
));
203207
}
204208
Ok(VmDriverConfig {
205-
allow_driver_config: settings.allow_driver_config,
206-
resource_admission: settings.resource_admission,
209+
allow_driver_config: admission.allow_driver_config,
210+
resource_admission: admission.resource_admission,
207211
grpc_endpoint,
208212
supervisor_otlp,
209213
supervisor_gateway_name: gateway.gateway_name.clone(),
@@ -258,6 +262,7 @@ mod tests {
258262
gateway,
259263
trust,
260264
openshell_core::sandbox_env::SupervisorOtlp::default(),
265+
openshell_core::resource_admission::DriverAdmissionConfig::default(),
261266
"info",
262267
(false, 8192, 4),
263268
)
@@ -296,6 +301,30 @@ mod tests {
296301
assert_eq!(built.supervisor_gateway_name.as_deref(), Some("gw"));
297302
}
298303

304+
#[test]
305+
fn the_admission_policy_comes_from_configure() {
306+
let gateway = GatewayContext {
307+
gateway_port: Some(1),
308+
..Default::default()
309+
};
310+
let policy = openshell_core::resource_admission::DriverAdmissionConfig {
311+
allow_driver_config: true,
312+
..Default::default()
313+
};
314+
let built = driver_config(
315+
settings_from_table("").unwrap(),
316+
&gateway,
317+
None,
318+
openshell_core::sandbox_env::SupervisorOtlp::default(),
319+
policy,
320+
"info",
321+
(false, 8192, 4),
322+
)
323+
.unwrap();
324+
assert!(built.allow_driver_config);
325+
assert!(!config("", &gateway, None).unwrap().allow_driver_config);
326+
}
327+
299328
#[test]
300329
fn an_https_endpoint_needs_the_gateway_ca() {
301330
let gateway = GatewayContext {

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ impl std::error::Error for ConfigError {}
3232
#[serde(default, deny_unknown_fields)]
3333
#[allow(clippy::struct_excessive_bools)]
3434
pub struct VmSettings {
35-
pub allow_driver_config: bool,
36-
pub resource_admission: openshell_core::resource_admission::ResourceAdmissionConfig,
3735
/// Working directory for VM driver sandbox state.
3836
pub state_dir: PathBuf,
3937
/// Default sandbox image the driver should use when a request omits one.
@@ -87,7 +85,6 @@ impl VmSettings {
8785

8886
/// Checks that need neither the gateway context nor the backend.
8987
fn validate(&self) -> Result<(), ConfigError> {
90-
self.resource_admission.validate().map_err(ConfigError)?;
9188
if !self.grpc_endpoint.trim().is_empty() {
9289
openshell_driver_sdk::validate_grpc_endpoint(&self.grpc_endpoint)
9390
.map_err(ConfigError)?;
@@ -157,9 +154,6 @@ impl VmSettings {
157154
impl Default for VmSettings {
158155
fn default() -> Self {
159156
Self {
160-
allow_driver_config: false,
161-
resource_admission:
162-
openshell_core::resource_admission::ResourceAdmissionConfig::default(),
163157
state_dir: Self::default_state_dir(),
164158
default_image: openshell_core::image::default_sandbox_image(),
165159
grpc_endpoint: String::new(),
@@ -203,14 +197,12 @@ mod tests {
203197
assert_eq!(settings.vcpus, 2);
204198
assert_eq!(settings.mem_mib, 2048);
205199
assert!(settings.grpc_endpoint.is_empty());
206-
assert!(!settings.allow_driver_config);
207200
}
208201

209202
#[test]
210203
fn existing_operator_keys_are_accepted() {
211204
let settings = settings_from_table(
212205
r#"
213-
allow_driver_config = true
214206
state_dir = "/var/lib/openshell/vm"
215207
default_image = "example.test/sandbox:1"
216208
bootstrap_image = "example.test/bootstrap:1"
@@ -227,7 +219,6 @@ mod tests {
227219
"#,
228220
)
229221
.unwrap();
230-
assert!(settings.allow_driver_config);
231222
assert_eq!(settings.vcpus, 4);
232223
assert_eq!(settings.sandbox_uid, Some(10001));
233224
assert_eq!(
@@ -244,7 +235,12 @@ mod tests {
244235

245236
#[test]
246237
fn gateway_supplied_values_are_not_driver_keys() {
247-
for key in ["guest_tls_ca = \"/ca.pem\"", "gateway_port = 8080"] {
238+
for key in [
239+
"guest_tls_ca = \"/ca.pem\"",
240+
"gateway_port = 8080",
241+
"allow_driver_config = true",
242+
"resource_admission = {}",
243+
] {
248244
assert!(settings_from_table(key).is_err(), "accepted: {key}");
249245
}
250246
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ pub struct ConfigureInputs<'a> {
595595
pub gateway_name: &'a str,
596596
pub network_trust: Option<&'a openshell_core::NetworkSupervisorTrustBundle>,
597597
pub otlp: Option<&'a openshell_server::config_file::OtlpConfig>,
598+
/// The operator's admission policy, which the gateway owns.
599+
pub admission: Option<&'a openshell_core::resource_admission::DriverAdmissionConfig>,
598600
pub sandbox_runtime_image: Option<String>,
599601
pub supervisor_image: Option<String>,
600602
}
@@ -608,13 +610,15 @@ impl<'a> ConfigureInputs<'a> {
608610
gateway_name: &'a str,
609611
network_trust: Option<&'a openshell_core::NetworkSupervisorTrustBundle>,
610612
otlp: Option<&'a openshell_server::config_file::OtlpConfig>,
613+
admission: Option<&'a openshell_core::resource_admission::DriverAdmissionConfig>,
611614
) -> Self {
612615
Self {
613616
gateway_port,
614617
guest_tls_ca,
615618
gateway_name,
616619
network_trust,
617620
otlp,
621+
admission,
618622
sandbox_runtime_image: std::env::var(openshell_core::config::SANDBOX_RUNTIME_IMAGE_ENV)
619623
.ok(),
620624
supervisor_image: std::env::var(openshell_core::config::SUPERVISOR_IMAGE_ENV).ok(),
@@ -677,9 +681,21 @@ impl<'a> ConfigureInputs<'a> {
677681
supervisor_image: self.supervisor_image.clone(),
678682
}),
679683
telemetry,
684+
admission_json: self
685+
.admission
686+
.and_then(|policy| serde_json::to_string(policy).ok())
687+
.unwrap_or_default(),
680688
}
681689
}
682690
}
683691

692+
/// Remove the admission keys from a driver table. The gateway owns the
693+
/// policy: it reads and validates it, and sends it in `Configure`.
694+
pub fn strip_gateway_owned_keys(table: &mut toml::map::Map<String, toml::Value>) {
695+
for key in ["allow_driver_config", "resource_admission"] {
696+
table.remove(key);
697+
}
698+
}
699+
684700
#[cfg(test)]
685701
mod tests;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,17 @@ fn configure_carries_the_gateway_metadata_the_argv_used_to() {
332332
"sha256:abc",
333333
PathBuf::from("/var/lib/openshell/network/additional-ca.crt"),
334334
);
335+
let admission = openshell_core::resource_admission::DriverAdmissionConfig {
336+
allow_driver_config: true,
337+
..Default::default()
338+
};
335339
let inputs = ConfigureInputs {
336340
gateway_port: 8080,
337341
guest_tls_ca: Some(Path::new("/etc/openshell/ca.pem")),
338342
gateway_name: "gw",
339343
network_trust: Some(&bundle),
340344
otlp: Some(&otlp),
345+
admission: Some(&admission),
341346
sandbox_runtime_image: Some("runtime:1".to_string()),
342347
supervisor_image: None,
343348
};
@@ -365,6 +370,9 @@ fn configure_carries_the_gateway_metadata_the_argv_used_to() {
365370
assert_eq!(traces.protocol, "http/protobuf");
366371
assert_eq!(telemetry.ocsf.unwrap().endpoint, "https://ocsf.test:4317");
367372
assert!(telemetry.agent.is_none());
373+
let sent: openshell_core::resource_admission::DriverAdmissionConfig =
374+
serde_json::from_str(&request.admission_json).unwrap();
375+
assert!(sent.allow_driver_config);
368376
assert_eq!(
369377
telemetry.collector.unwrap().ca_file,
370378
ca.display().to_string()
@@ -379,6 +387,7 @@ fn configure_omits_what_the_gateway_does_not_have() {
379387
gateway_name: "gw",
380388
network_trust: None,
381389
otlp: None,
390+
admission: None,
382391
sandbox_runtime_image: None,
383392
supervisor_image: None,
384393
};
@@ -388,4 +397,5 @@ fn configure_omits_what_the_gateway_does_not_have() {
388397
assert_eq!(request.gateway.unwrap().tls_ca_path, "");
389398
assert!(request.network_trust.is_none());
390399
assert!(request.telemetry.is_none());
400+
assert!(request.admission_json.is_empty());
391401
}

0 commit comments

Comments
 (0)