Skip to content

feat(vm): configure the sandbox workspace root - #5797

Open
shiju-nv wants to merge 3 commits into
mainfrom
feat/5282-vm-workspace-root/shiju-nv
Open

shiju-nv wants to merge 3 commits into
mainfrom
feat/5282-vm-workspace-root/shiju-nv

Conversation

@shiju-nv

@shiju-nv shiju-nv commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Make the MicroVM workspace configurable so images built around paths such as /home/agent can run without changing the VM driver. Keep /sandbox as the default, and support either an operator-managed directory or the image's OCI WORKDIR.

Related Issue

Closes #5282

Changes

  • Add workspace_mode (managed or image) and workspace_root to VM gateway configuration, with matching VM driver flags.
  • Prepare custom managed directories for the sandbox user, preserving ownership of existing contents and updating the sandbox account's home. Require custom image workspaces to exist without symlink components and be writable by the resolved sandbox user.
  • Persist the selected workspace and retain the prepared workload image across restarts. Existing VMs without workspace metadata keep /sandbox.
  • Share reserved-path validation between the gateway and driver, and validate bind mounts against the selected workspace.
  • Add coverage for workspace selection, persistence, reserved paths, mount conflicts, and image workdir resolution from the pinned registry image. Update the VM README and gateway/runtime documentation.

Release Notes

Configure [openshell.drivers.vm] with workspace_mode = "managed" and workspace_root = "/home/agent" to choose a workspace, or use workspace_mode = "image" to follow the image's OCI WORKDIR. Missing, empty, /, and /sandbox workdirs, including rootfs tar archives without OCI metadata, fall back to managed /sandbox. The selected workspace is fixed when the sandbox is created.

Testing

  • Checks appropriate to the affected code and behavior pass
  • Unit tests added/updated (if applicable)
  • E2E tests added/updated (if applicable)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

@github-actions github-actions Bot added the state:accepted A maintainer decided OpenShell should pursue this issue label Nov 20, 2026
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Compatibility review (advisory)

New or updated breaking changes; see the full report for all findings.

1. rust-sdk — No explicit risk acceptance found

raw::proto::ProviderCredentialRefreshStrategy gains GithubAppInstallation, extending an existing exhaustive Rust enum.

  • Impact: SDK consumers matching all previous variants without a wildcard fail to compile, while ordinary RPC client calls remain unaffected.
  • Action: Preserve the baseline generated enum for v0.1.10, or defer its extension to a minor release with notice and wildcard-match migration guidance.
  • PR: feat(vm): configure the sandbox workspace root #5797

2. cli — No explicit risk acceptance found

openshell-gateway mutation audit status_detail changes from rejected:<code> or error:<code> to optionally include a third :<reason> component.

  • Impact: Existing JSONL and stderr audit consumers using the documented two-component format can reject records or stop matching failure alerts.
  • Action: Keep the existing two-component status_detail format for v0.1.10 and expose the reason separately, or defer the format change to a minor release with parser migration guidance.
  • PR: feat(vm): configure the sandbox workspace root #5797
Review details
  • Execution: complete
  • Candidate: PR #5797 (3bc117380b03200c8ec5105cd0c9686a02ce18c5)
  • Baseline: 498a0bb3eb92ae1a60ec459e12ce4657b8ee6af2 (498a0bb3eb92ae1a60ec459e12ce4657b8ee6af2)
  • Reviewed: rust-sdk, python-sdk, api-behavior, cli, configuration, policy, helm, state

Advisory review; publication gates are unchanged.

Branch check run

@shiju-nv shiju-nv added area:drivers Compute and secret drivers, host OS/architecture support, backend isolation, and lifecycle. topic:operability Installing/configuring deployments, upgrades, backup/restore, diagnostics, and maintenance. labels Nov 23, 2026

@elezar elezar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The design looks sound: per-sandbox persistence, init reading driver-owned overlay metadata, and the digest-bound registry WORKDIR.

One non-blocking suggestion: this changes guest init (passwd home rewrite, prepare_guest_directory, the image-mode skip), and the init test runs the helper with /sandbox hard-coded. A VM e2e with a custom managed workspace would be a good follow-up if you'd rather not add it here.

Details in the inline comments.

}

/// Resolve a VM workspace that guest init will assign to the sandbox user.
pub fn resolve_vm_managed_workspace_root(root: &str) -> Result<String, String> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The hard-coded /etc, /usr, /home, /var list is a general system-path denylist. container_paths.rs says CONTROL_ROOTS is deliberately not one (see #2578). Can you explain why VM managed mode needs this when Docker and Podman don't, or move it next to CONTROL_ROOTS with a comment?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I added the rationale next to the VM managed validator.

Guest init changes the selected directory's owner and permissions and sets it as the sandbox account's home. The VM-specific restrictions protect system directories from those changes while still allowing workspaces below /home and /var.

}

/// Resolve a VM workload's image-declared working directory.
pub fn resolve_vm_image_workspace_root(working_dir: &str) -> Result<String, String> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: in image mode an image with WORKDIR=/etc or /usr/lib is accepted, while managed mode rejects those paths. This matches Docker and Podman, so I'm fine with it. Is that intended, and should the docs say image mode trusts the image's choice?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, image mode intentionally follows the image's OCI WORKDIR subject to validation.

/etc is rejected in both modes because it contains reserved OpenShell paths. /usr/lib can qualify in image mode if it exists without symlink components and is writable by the sandbox user.

I clarified in the runtime docs that guest init skips managed workspace setup for a custom image path and chooses the account’s /etc/passwd home independently.

clap::ValueEnum,
)]
#[serde(rename_all = "snake_case")]
pub enum VmWorkspaceMode {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

VmWorkspaceMode is defined in both the driver and the gateway (crates/openshell-gateway/src/vm.rs), and the gateway only forwards --workspace-mode image and a non-default --workspace-root. That works today but will break silently if a mode is added. Could the gateway reuse the driver's enum, or always pass both flags?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved VmWorkspaceMode into openshell-core so the gateway and VM CLI share the same type. The gateway now uses an exhaustive match, so a new mode requires an explicit forwarding decision at compile time. Default managed /sandbox still uses the driver’s defaults.

// Old local cache entries were exported by tag. Keep those entries
// separate from exports bound to the inspected image and its config.
let cache_identity = prepared_image_cache_identity(
&format!("local-image-id:{image_identity}"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The cache key changes to local-image-id:..., so every locally built image is re-exported once after upgrade and the old tag-keyed entries are never cleaned up. Worth a release note, or a cleanup of the old entries.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I documented the one-time rebuild in the VM driver README. The old cache key already used the inspected image ID, but the export resolved the tag again. The new namespace separates disks exported by immutable ID from older disks. Those older disks remain on disk and may still back existing sandboxes.

drop(cache_guard);
self.publish_prepared_cache_hit(sandbox_id, image_ref, "registry", &cache_identity);
let working_dir = if inspect_workdir {
pull_registry_image_workdir(client, &reference, auth, image_ref).await?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: in image mode a cache hit now pulls the manifest and config blob again, so an unreachable registry fails creation even when the disk is cached. Could the WorkingDir be stored next to the cached disk so a hit needs no registry round trip? If the re-fetch is intentional, a comment saying why would help.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Image mode now stores the digest-verified WorkingDir alongside the prepared disk. Older entries backfill from the pinned image on first use, including images with no WORKDIR. Warm hits skip the extra pinned manifest and config fetches while preserving registry authentication and mutable-tag resolution. The updated registry test passed for both backfill cases and verifies that warm hits skip those extra requests.

@github-actions

Copy link
Copy Markdown

Compatibility review (advisory)

New or updated breaking changes; see the full report for all findings.

1. rust-sdk — No explicit risk acceptance found

raw::proto::SandboxPolicy gains three fields and raw::proto::GetSandboxConfigRequest gains supported_capabilities, invalidating previously complete Rust struct literals.

  • Impact: SDK callers constructing these messages without ..Default::default() fail to compile even when they do not use Cedar policies.
  • Action: Preserve the baseline raw Rust message shapes for v0.1.10, or defer their extension to a minor release with notice and ..Default::default() migration guidance.
  • PR: feat(vm): configure the sandbox workspace root #5797

2. configuration — No explicit risk acceptance found

Default supervisor and sandbox runtime images move from ghcr.io/nvidia/openshell/&lt;component&gt; to quay.io/ai-openshell/&lt;component&gt; without an opt-in.

  • Impact: Existing Docker and Podman installations using default image settings and GHCR-only registry allowlists or mirrors fail to pull images when provisioning sandboxes after upgrade.
  • Action: Retain GHCR-compatible defaults and publication for v0.1.10 or defer Quay-only defaults to a minor release; the existing migration guide provides notice but does not exempt this patch-train break.
  • PR: feat(vm): configure the sandbox workspace root #5797
Review details
  • Execution: complete
  • Candidate: PR #5797 (d177b2cd663dd4b809a342212b9aadfd70675bab)
  • Baseline: 498a0bb3eb92ae1a60ec459e12ce4657b8ee6af2 (498a0bb3eb92ae1a60ec459e12ce4657b8ee6af2)
  • Reviewed: rust-sdk, python-sdk, api-behavior, cli, configuration, policy, helm, state

Advisory review; publication gates are unchanged.

Branch check run

@shiju-nv

Copy link
Copy Markdown
Collaborator Author

Thanks, I extended vm_gateway_start to exercise a custom managed workspace. It checks the workload's working directory and the sandbox account’s home, writes a file using a relative path, and verifies that the file survives a gateway restart.

Signed-off-by: Shiju <shiju@nvidia.com>
Signed-off-by: Shiju <shiju@nvidia.com>
Share the workspace mode and reserved root across their callers. Reuse verified image working directories on prepared registry cache hits, document the local cache upgrade, and exercise a custom managed workspace across gateway restart.

Signed-off-by: Shiju <shiju@nvidia.com>
@shiju-nv
shiju-nv force-pushed the feat/5282-vm-workspace-root/shiju-nv branch from 323cd9a to fdab97e Compare November 26, 2026 11:05
@shiju-nv
shiju-nv requested a review from elezar November 26, 2026 11:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:drivers Compute and secret drivers, host OS/architecture support, backend isolation, and lifecycle. state:accepted A maintainer decided OpenShell should pursue this issue topic:operability Installing/configuring deployments, upgrades, backup/restore, diagnostics, and maintenance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the MicroVM sandbox workspace root configurable (currently hard-coded to /sandbox)

2 participants