Skip to content

feat(docker): supply CDI context for GPU sandboxes - #2265

Open
elezar wants to merge 3 commits into
1606-cdi-sandbox-consumer/elezarfrom
feat/1606-derive-cdi-sandbox-requirements/elezar
Open

feat(docker): supply CDI context for GPU sandboxes#2265
elezar wants to merge 3 commits into
1606-cdi-sandbox-consumer/elezarfrom
feat/1606-derive-cdi-sandbox-requirements/elezar

Conversation

@elezar

@elezar elezar commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

Provide the Docker-side CDI producer for GPU sandboxes: discover CDI support, select devices, bind-mount a gateway-owned CDI context and daemon-reported specs read-only, and clear CDI state for non-GPU containers. This is the final PR in the #1606 stack.

Related Issue

Part of #1606. Depends on #2776.

Changes

  • Add Docker CDI runtime discovery, GPU selection, and read-only CDI spec mounts.
  • Create the driver-owned CDI context before container creation and bind-mount it read-only into the supervisor.
  • Clear CDI context for non-GPU containers and clean context and token state after failed provisioning.
  • Document the Docker CDI lifecycle and add Docker-focused coverage.

Testing

  • mise run pre-commit passes.
  • Focused core CDI and Docker driver unit tests pass.
  • E2E tests added/updated (CI GPU E2E remains required).

Checklist

  • Follows Conventional Commits.
  • Commits are signed off (DCO).

@copy-pr-bot

copy-pr-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 61d751d to c8ebad0 Compare July 14, 2026 13:18
@github-actions

Copy link
Copy Markdown

@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch 6 times, most recently from d7f06ff to 5cd240a Compare July 20, 2026 11:18
@elezar
elezar marked this pull request as ready for review July 20, 2026 13:57
@elezar elezar added test:e2e Requires end-to-end coverage test:e2e-gpu Requires GPU end-to-end coverage labels Jul 20, 2026
@github-actions

Copy link
Copy Markdown

Label test:e2e-gpu applied for 5cd240a. Open the existing run and click Re-run all jobs to execute with the label set. The run will execute GPU E2E after building the required supervisor image once. The matching required CI gate status on this PR will flip green automatically once the run finishes.

@github-actions

Copy link
Copy Markdown

Label test:e2e applied for 5cd240a. Open the existing run and click Re-run all jobs to execute with the label set. The run will execute the standard E2E suite after building the required gateway and supervisor images once. The matching required CI gate status on this PR will flip green automatically once the run finishes.

@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 5cd240a to c8b3044 Compare July 21, 2026 12:11
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from c8b3044 to c040b8d Compare July 22, 2026 13:42
Comment thread crates/openshell-driver-docker/src/lib.rs Outdated

@elezar elezar left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gator-agent

PR Review Status

Validation: This PR is project-valid because it implements roadmap issue #1606 for Docker GPU/CDI sandbox policy derivation, includes user-facing documentation, and has the required E2E/GPU E2E labels.
Head SHA: c040b8dd5d7adcb126d1c5199e6203ba5dfdc93b

Thanks @drew, I checked the CDI context trust-boundary concern you raised and confirmed it is still a blocking issue on this head. The independent review also found related supervisor-side hardening gaps and a Docker token cleanup regression.

Review findings:

  • Blocking findings remain on CDI context trust, CDI device-node validation, and failed-provisioning token cleanup.

Docs: Fern docs were updated under docs/; no navigation change appears necessary for these existing pages.
Checks: Required checks are currently green, including DCO, Branch Checks, Helm Lint, Core E2E, and GPU E2E.
E2E: test:e2e and test:e2e-gpu are applied and passing.

Next state: gator:in-review

Comment thread crates/openshell-driver-docker/src/lib.rs Outdated
Comment thread crates/openshell-sandbox/src/lib.rs
Comment thread crates/openshell-core/src/cdi.rs Outdated
Comment thread crates/openshell-driver-docker/src/lib.rs Outdated
@elezar elezar added the gator:in-review Gator is reviewing or awaiting PR review feedback label Jul 22, 2026

@elezar elezar left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gator-agent

PR Review Status

Validation: This PR is project-valid because it implements roadmap issue #1606 for Docker GPU/CDI sandbox policy derivation, includes architecture and Fern documentation updates, and has the required test:e2e and test:e2e-gpu labels.
Head SHA: cf6a99519f85611da0558468ce42f84c6940976d

Thanks @drew, I re-checked the CDI context trust-boundary concern you raised against the latest head. The Docker env cleanup and token cleanup paths are improved, but the independent review found the supervisor still needs a stronger driver-attestation boundary before CDI-derived policy is trusted.

Review findings:

  • Blocking finding remains on CDI context trust/attestation.
  • Warning remains on explicit CDI device ID namespace validation.

Docs: Fern docs were updated under docs/; no navigation change appears necessary for these existing pages.
Checks: Current head has DCO and Helm Lint passing, with Branch Checks, E2E, and GPU E2E still pending/queued.
E2E: test:e2e and test:e2e-gpu are applied; results are still pending for this head.

Next state: gator:in-review

Comment thread crates/openshell-sandbox/src/lib.rs
let cdi_context = self
.config
.gpu
.cdi_context(gpu_devices.as_deref())

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gator-agent

Warning: The selected IDs passed into the CDI context can come from explicit driver_config.cdi_devices, and current validation only checks count/duplicates, not that each ID is in the NVIDIA GPU CDI namespace. Since this PR now derives device, mount, and group policy from those specs, arbitrary CDI vendors can broaden sandbox permissions behind a GPU request. Please require nvidia.com/gpu= for explicit IDs, matching the default inventory filter, and add a negative unit test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree that these should be NVIDIA-SPECIFIC. CDI is vendor agnostic, and we should be able to use the same mechanism to inject CDI devices from other vendors. I agree that we could check for valid CDI device IDs though.

@elezar elezar added gator:blocked Gator is blocked by process or repository gates and removed gator:in-review Gator is reviewing or awaiting PR review feedback labels Jul 29, 2026
@krishicks

Copy link
Copy Markdown
Collaborator

I looked at rebasing this and found two issues:

  1. The PR as it stands doesn't properly compile on macOS because the new container-device-interface crate that's pulled in is Linux-only. I have a commit locally that fixes that so that it can build on macOS
  2. The conflict from rebasing is substantial. I had an agent analyze the conflict without trying to resolve it, output in details below
Details The conflict is understandable: main added OCI image identity and working-directory handling in the same code that PR #2265 changes for CDI. It is not safe to choose either side wholesale. There are four conflicted files, with the conflict originating in feat(gpu): derive sandbox policy from CDI specs and then propagating through the two descendant commits.
  • crates/openshell-driver-docker/src/lib.rs:2275: main added build_environment_for_oci_user(..., oci_user) while CDI added include_cdi_context. The resolution needs both parameters. The test helper should preserve the CDI boolean while supplying an empty OCI user.

  • crates/openshell-driver-docker/src/lib.rs:2631: main requires working_dir: "/" and passes image.user; CDI needs to pass whether GPU selection requested a CDI context. Both behaviors must be retained.

  • crates/openshell-driver-docker/src/tests.rs:1476: mostly mechanical. Keep main’s renamed test and workspace assertion, but use the new GPU-aware runtime_config(false) signature.

  • crates/openshell-supervisor-process/src/process.rs:2077: this is the substantive conflict. Main added distinct supplementary-group handling for OCI-derived identities, while CDI adds additionalGids. The combined result must merge CDI groups into both:

    • OCI image-user supplementary groups.
    • Explicit policy/named-user groups.

The supervisor merge deserves extra care because main now uses supplementary groups during workspace authorization, before privilege dropping. Ideally CDI groups should be incorporated into the common resolved identity so workspace validation and the eventual setgroups() call see the same group set. Simply pasting the old CDI block after main’s new logic could reject a valid workspace or overwrite OCI-derived groups.

Cargo.lock:1166 has four textual regions caused by main’s dependency updates colliding with CDI’s new packages. It should be regenerated from the merged manifests, retaining main’s newer dependency selections rather than selecting either lockfile side manually.

@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from cf6a995 to 6079eb8 Compare August 17, 2026 13:01
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 6079eb8 to acfdb59 Compare August 17, 2026 13:21
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from acfdb59 to 1bb159e Compare August 17, 2026 13:25
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 1bb159e to 8b64a14 Compare August 17, 2026 14:02
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 8b64a14 to 0b9e522 Compare August 17, 2026 14:05
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 0b9e522 to 2a25840 Compare August 18, 2026 09:38
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 2a25840 to 5c2b7e6 Compare August 18, 2026 10:25
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 5c2b7e6 to 2f2af27 Compare August 18, 2026 11:04
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 2f2af27 to 1c13b62 Compare August 18, 2026 11:19
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 1c13b62 to 4958081 Compare August 18, 2026 11:28
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch 2 times, most recently from bb6d5cb to 614c389 Compare August 18, 2026 12:50
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch 2 times, most recently from 1714395 to 9c71c29 Compare August 18, 2026 14:46

@drew drew left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current bind-mount implementation is coherent, but the documented lifecycle still describes the abandoned archive-upload design, and the upload-only tar dependency remains in the production dependency graph.

| `restart_policy = unless-stopped` | Keeps managed sandboxes resumable across daemon or gateway restarts. |
| `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. |
| 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. |
| 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. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Update the documented CDI context lifecycle to match the implementation. The driver now writes a gateway-owned context file and bind-mounts it read-only during container creation; it no longer uploads an archive after create. This row and the prose below still promise a post-create upload and upload-failure cleanup. The same stale contract appears in architecture/compute-runtimes.md and docs/reference/sandbox-compute-drivers.mdx. Please update all three surfaces (and the PR description) to describe the bind-mounted lifecycle and its actual failure behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread crates/openshell-driver-docker/Cargo.toml Outdated
elezar added 3 commits August 19, 2026 09:49
Signed-off-by: Evan Lezar <elezar@nvidia.com>
Signed-off-by: Evan Lezar <elezar@nvidia.com>
Signed-off-by: Evan Lezar <elezar@nvidia.com>
@elezar
elezar force-pushed the feat/1606-derive-cdi-sandbox-requirements/elezar branch from 9c71c29 to 9f1a3ef Compare August 19, 2026 07:50
@elezar
elezar requested a review from drew August 19, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gator:blocked Gator is blocked by process or repository gates test:e2e Requires end-to-end coverage test:e2e-gpu Requires GPU end-to-end coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants