Skip to content

Commit 577be9d

Browse files
committed
feat(docker): supply CDI context for GPU sandboxes
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent bfa8b55 commit 577be9d

8 files changed

Lines changed: 457 additions & 108 deletions

File tree

‎architecture/compute-runtimes.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ Resource requirements enter the driver layer through `SandboxSpec.resource_requi
242242
can request a specific number of GPUs or the driver-specific default behaviour.
243243
For all in-tree drivers, this is equivalent to selecting a single GPU.
244244

245+
For Docker GPU sandboxes, the driver treats CDI specs as runtime metadata for
246+
both outer injection and inner sandbox policy. It selects opaque CDI device IDs,
247+
passes them to Docker, mounts daemon-reported CDI spec directories into
248+
supervisor-only paths, and uploads a versioned CDI context before starting the
249+
container. The supervisor resolves that context inside the sandbox and derives
250+
Landlock paths and supplemental groups from CDI `containerEdits`. Host-side CDI
251+
spec paths are diagnostic only and are never treated as sandbox policy paths.
252+
Kubernetes must not infer CDI device IDs from the `nvidia.com/gpu` resource
253+
request; it needs a node-local selected-device handoff before using the same
254+
supervisor resolver.
255+
245256
VM runtime state paths are derived only from driver-validated sandbox IDs
246257
matching `[A-Za-z0-9._-]{1,128}`. The gateway-owned VM driver socket uses a
247258
private `run/` directory plus Unix peer UID/PID checks. Standalone

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ use serde::{Deserialize, Serialize};
99

1010
pub const CDI_CONTEXT_VERSION: u32 = 1;
1111

12+
/// File name used for the serialized CDI context.
13+
pub const CDI_CONTEXT_FILE_NAME: &str = "cdi-context.json";
14+
1215
/// Absolute supervisor path for the CDI context file mounted by a compute driver.
1316
pub const CDI_CONTEXT_PATH: &str = "/run/openshell/supervisor/cdi-context.json";
1417

1518
/// Base supervisor path under which compute drivers mount CDI specification directories.
1619
pub const CDI_SPEC_DIR_BASE: &str = "/run/openshell/supervisor/cdi-specs";
1720

21+
/// Return the supervisor path used for a CDI specification directory.
22+
#[must_use]
23+
pub fn cdi_spec_mount_path(index: usize) -> String {
24+
format!("{CDI_SPEC_DIR_BASE}/{index}")
25+
}
26+
1827
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1928
pub struct CdiContext {
2029
pub version: u32,

‎crates/openshell-driver-docker/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ miette = { workspace = true }
3838
toml = { workspace = true }
3939
tower-http = { workspace = true }
4040
http = { workspace = true }
41+
tar = "0.4"
4142

4243
[dev-dependencies]
4344
openshell-otel-test-support = { path = "../openshell-otel-test-support" }
4445
opentelemetry = { workspace = true }
4546
opentelemetry_sdk = { workspace = true, features = ["testing"] }
4647
prost-types = { workspace = true }
47-
tar = "0.4"
4848
temp-env = "0.3"
4949
tempfile = "3"
5050
tracing-subscriber = { workspace = true }

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,33 @@ contract:
107107
| `PidsLimit` | Enforces the sandbox PID budget at the Docker cgroup layer. Set `[openshell.drivers.docker].sandbox_pids_limit = 0` to inherit the Docker/runtime default. |
108108
| CDI GPU request | Uses opaque `driver_config.cdi_devices` values when set; otherwise selects the requested count of NVIDIA CDI GPUs in round-robin order when daemon CDI support is detected. Docker daemon `/info` can permit `nvidia.com/gpu=all` as a WSL2 all-only compatibility fallback, where it counts as one selectable device. Exact CDI device lists must not contain duplicates and must match the effective GPU count. |
109109
| `policy-dns-transparent-tcp` capability | Declares that the combined Docker supervisor can own namespace-local DNS/TCP capture and coupled workload restart. The shared supervisor still owns DNS eligibility, mappings, authorization, pinned dialing, relaying, and OCSF decisions. The marker is stripped from the workload environment. |
110+
| CDI context upload | For GPU/CDI sandboxes only, mounts daemon-reported CDI spec directories read-only under `/run/openshell/supervisor/cdi-specs/<n>` and uploads `/run/openshell/supervisor/cdi-context.json` after container create and before start. |
110111

111112
The agent child process does not retain these supervisor privileges.
112113

114+
## CDI GPU Metadata
115+
116+
Docker remains the source of truth for GPU injection. The driver selects opaque
117+
CDI device IDs from `driver_config.cdi_devices` or the daemon's discovered CDI
118+
inventory, then passes the same IDs to Docker with a CDI `DeviceRequest`.
119+
120+
When a GPU/CDI request is present, the driver also mounts the Docker
121+
daemon-reported `Info.CDISpecDirs` into supervisor-only paths and uploads a
122+
small versioned CDI context through Docker's container archive API. The context
123+
uses container-side spec paths for resolution and keeps host-side spec sources
124+
diagnostic-only. If the upload fails, the driver removes the created container
125+
and sandbox token file before reporting the failure.
126+
127+
The sandbox supervisor resolves the selected IDs from those mounted specs
128+
before it launches agent processes. CDI device nodes become read-write
129+
Landlock paths, mount destinations default to read-only paths, and
130+
`additionalGids` become supplemental groups for the entrypoint and SSH child
131+
processes. Writable CDI mount destinations are accepted only for exact
132+
single-file paths already listed in the sandbox policy `read_write` list;
133+
writable CDI directory mounts fail closed. Kubernetes, Podman, WSL2 hardware
134+
validation, and Tegra/Jetson hardware validation are separate follow-up
135+
targets.
136+
113137
## Driver Config Mounts
114138

115139
The gateway forwards the `docker` block from `--driver-config-json` to this

0 commit comments

Comments
 (0)