Skip to content

feat: support privileged (true guest root) workloads in openshell-sandbox for VM sandboxes #5925

In progress

Description

@drew

User Story

I use OpenShell to run development and agent workloads inside VM-backed sandboxes. I need a way to run workloads as real guest root inside the VM (installing packages with apt-get, running bubblewrap, running dockerd with full networking, or debugging with strace/gdb) while preserving supervisor-enforced network policy, filesystem and process rules, kernel instrumentation, credential injection, and lifecycle controls.

Problem Statement

Today openshell-sandbox only supports a single capability-free execution model. The runtime and the workload share one unprivileged identity, no_new_privs is always set, Landlock is applied, and namespace/mount/admin syscalls are blocked. Even inside a VM where the hypervisor already isolates the guest from the host, OpenShell cannot run workloads that require real root privileges.

Conversely, simply dropping all in-guest kernel enforcement in a root VM (relying solely on an external network fence and an in-guest nftables relay) gives up filesystem_policy, process rules, kernel-sourced process/file telemetry, clean vsock / dockerd networking, and shared-supervisor density.

Impact / Why This Matters

Users who need Docker, bubblewrap, root package installs, or root system tooling in a VM sandbox currently have to pre-bake every dependency into images or run outside OpenShell without policy or credential mediation. User-namespace-only workarounds break workloads that need real CAP_NET_ADMIN / CAP_SYS_ADMIN (for example Docker bridge networking, iptables, or strace/gdb), while untrusted-guest designs abandon file/process policy and kernel instrumentation altogether.

Proposed Design

Add an opt-in --privileged mode to openshell-sandbox for VM drivers that control the guest kernel, combining two complementary planes:

  1. In-guest kernel plane: a hardened mainline CONFIG_BPF_LSM=y VM kernel + boot-once BPF LSM enforcing shim isolation, workload filesystem_policy / process rules, and kernel-sourced telemetry, paired with CLONE_NEWNET + seccomp_notify (ADDFD) network mediation.
  2. Outside-the-guest defense-in-depth plane: hypervisor isolation, outer network fencing with drift verification, ephemeral root overlay across boots, host-side bootstrap/device hygiene, and reset-halt lifecycle controls.

In-guest behavior and trust boundary

  • Default unchanged. Capability-free remains the default. Existing capability-free sandboxes and the supervisor/sandbox boundary protocols (SandboxProtocol, IsolationBackend) stay unchanged.
  • True guest root, isolated from the shim. The workload runs as real guest UID 0 inside its own mount namespace (pivot_root into the writable workload rootfs with MS_REC | MS_PRIVATE), child PID namespace, child cgroup namespace, and separate workload network namespace (CLONE_NEWNET, loopback-only). The shim stays in the initial network namespace that owns the control transport (eth0 for TCP or vsock), so the workload cannot see, reconfigure, or sniff the supervisor link while remaining free to manage bridges, veths, and iptables/nftables inside its own network namespace. The workload keeps root capabilities (CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_SYS_CHROOT, CAP_SETUID/CAP_SETGID, CAP_MKNOD, CAP_SYS_PTRACE) and drops kernel-escape capabilities (CAP_SYS_MODULE, CAP_SYS_RAWIO, CAP_SYS_BOOT, CAP_BPF, CAP_PERFMON).
  • Boot-once BPF LSM in guest PID 1 (shim seal + policy + instrumentation). openshell-sandbox boots as guest PID 1 from a minimal read-only runtime root holding only the binary, stages bootstrap/TLS secrets into memory, detaches the config disk, and loads one embedded BPF LSM program before starting any workload process. Only shim tasks are marked in BPF_MAP_TYPE_TASK_STORAGE, and the LSM covers three planes without requiring no_new_privs:
    • Shim seal:
      • lsm/bpf blocks unmarked tasks from calling bpf() (locking down further loads/detaches without signed BPF loaders or custom kernel patches).
      • lsm/ptrace_access_check, lsm/perf_event_alloc, lsm/task_kill, and lsm/task_setrlimit block process tampering against marked shim tasks.
      • lsm/socket_create blocks AF_VSOCK and non-loopback init_net sockets/netlink from unmarked tasks.
      • lsm/file_open, lsm/inode_*, lsm/sb_remount, and lsm/sb_umount protect the runtime /run/openshell superblock (TLS CA and runtime state) and the runtime-owned workload freezer cgroup.
      • lsm/locked_down enforces kernel lockdown.
    • Workload filesystem_policy enforcement:
      • lsm/file_open, lsm/inode_create, lsm/inode_unlink, lsm/inode_rename, lsm/inode_setattr, and lsm/sb_mount enforce read-only, read-write, and denied path rules even against guest UID 0 (CAP_DAC_OVERRIDE).
      • Rules evaluate against kernel inode ancestry / superblocks and gate lsm/sb_mount so root can mount overlays, tmpfs, and container roots (dockerd, bwrap) without bypassing path rules via bind mounts or read-write remounts of protected paths.
      • Because the sealed shim owns the BPF maps, filesystem_policy updates support live reload without restarting the workload.
    • Workload process rules and kernel instrumentation:
      • lsm/bprm_check_security enforces process execution rules against real kernel inodes/paths.
      • lsm/task_alloc / lsm/task_free maintain trusted kernel-side process lineage in BPF_MAP_TYPE_TASK_STORAGE and stream non-spoofable process, file, and denial telemetry to openshell-sandbox over a BPF ringbuf.
      • When filesystem_policy holds system binary directories read-only (enforced against UID 0 by BPF LSM), binary attribution for executables under those paths remains trustworthy; executables in writable paths are treated as advisory.
  • Controlled VM kernel. The VM driver boots a hardened mainline Linux kernel with CONFIG_BPF_LSM=y, CONFIG_BPF_SYSCALL=y, CONFIG_BPF_JIT=y, and CONFIG_DEBUG_INFO_BTF=y, with root-to-kernel escape paths compiled out (CONFIG_MODULES=n, CONFIG_KEXEC=n, CONFIG_KEXEC_FILE=n, CONFIG_HIBERNATION=n, CONFIG_DEVMEM=n, CONFIG_DEVKMEM=n, CONFIG_PROC_KCORE=n, CONFIG_BLK_DEV_WRITE_MOUNTED=n, CONFIG_UPROBES=n).
  • Irreversible network mediation. The workload root process inherits a networking-only seccomp_notify filter (with io_uring blocked so async socket ops cannot bypass mediation) before exec. Linux does not allow even UID 0 to remove a seccomp filter. Because NetworkBroker creates mediated TCP and loopback DNS (127.0.0.53:53) sockets in the shim's init_net and injects them via ADDFD, external connections and DNS work cleanly across the workload's CLONE_NEWNET boundary over both vsock and TCP, with connect-time denies and no collision with dockerd bridges or iptables/nftables.

Outside-the-guest defense in depth (host / cluster plane)

  • Outer network fence with drift verification. Privileged VMs require an outer network fence: zero virtual NICs for vsock VMs (openshell-driver-vm / Firecracker), or a default-deny floor plus per-sandbox NetworkPolicy allowing egress only to the supervisor for TCP VMs (KubeVirt / Kata), with start-time and periodic spec-drift verification.
  • Ephemeral root overlay across boots. The guest base image is mounted read-only with a writable overlay wiped on every stop/start (only the explicit workspace volume persists), preventing mutated guest state from poisoning subsequent boots.
  • Host-side bootstrap and device hygiene. Deliver bootstrap material via host-side one-shot channels (detaching the config volume from the host once Ready where supported, avoiding guest-reversible PCI rescan on cloud-init disks), disable unused virtual devices (e.g., QEMU guest-agent virtio-serial, iTCO watchdog), and pin guest image digests.
  • Reset and duplicate-attach containment. If a guest triggers a reset and a fresh boundary attempts to attach to an already-live generation, the supervisor/driver ends that generation and halts the VM from the host.
  • Supervisor topology and credential handling. BPF LSM sealing enables hosting both capability-free and privileged sandboxes on a shared supervisor, while deployments that want additional blast-radius isolation (such as KubeVirt) can still select a dedicated supervisor per sandbox. Credential injection should happen supervisor-side (L7 proxy); in-guest provider files and env vars are readable to guest root if exposed to the workload and are refused by default unless explicitly opted in.
  • Driver-bound mode selection and supervisor-loss containment. The driver passes --privileged to openshell-sandbox and binds the privileged profile in both BoundaryConfig and SandboxRuntimeDescriptor. openshell-sandbox and the supervisor fail closed on mismatches and validate privileged audit evidence at Confirm. Losing the supervisor freezes the runtime-owned workload cgroup (cgroup.freeze, qualified at startup against a SIGCONT canary), falling back to terminating the workload / halting the VM if freezing is unavailable.

Explicit security caveats

  • VM-only: Requires a driver-controlled Linux kernel with CONFIG_BPF_LSM=y and an outer network fence (vsock with no NIC, or a fenced control NIC restricted to the supervisor endpoint). Not available on Docker, Podman, or stock Kubernetes container drivers.
  • No Landlock enforcement: Policies with landlock.compatibility: hard_requirement or unrestricted network mode are refused at attach. filesystem_policy is enforced by BPF LSM rather than Landlock.
  • Scoped binary attribution: Executable attribution is authoritative only for binaries under paths held read-only by filesystem_policy (and not subject to LD_PRELOAD from writable paths). Binaries in writable directories remain advisory; network destination rules always apply to the whole workload.
  • Guest console output is diagnostic only: Authoritative audit events come from the sealed shim's BPF ringbuf and supervisor OCSF streams, never the VM serial console.

Support matrix

Runtime / Driver Host boundary Guest mechanism Supervisor transport Status in this issue
VM driver (openshell-driver-vm / libkrun, Firecracker) Hypervisor + no NIC True guest root + boot-once BPF LSM (shim seal, file/process rules, telemetry) + seccomp_notify vsock Supported
KubeVirt (openshell-driver-kubernetes VM runtime with hardened kernel) Hypervisor + NetworkPolicy fence (drift-checked) True guest root + boot-once BPF LSM + seccomp_notify TCP (fenced control NIC) Supported (requires hardened CONFIG_BPF_LSM=y guest kernel)
Kubernetes with Kata Containers (runtimeClassName + hardened guest kernel) Hypervisor + NetworkPolicy fence (drift-checked) True guest root + boot-once BPF LSM + seccomp_notify TCP (fenced control NIC) Supported (requires hardened CONFIG_BPF_LSM=y Kata kernel)
Docker / Podman / stock Kubernetes (hostUsers: false) Outer userns (shared host kernel) Nested userns root (no BPF LSM) TCP / UDS Out of scope (rejected with clear error; potential follow-up)
Stock privileged containers (shared host kernel) None N/A N/A Unsupported (breaks host isolation)

Suggested UX (notional)

Create a privileged sandbox with --privileged (alias --priv):

openshell sandbox create --name dev [--privileged | --priv] --policy policy.yaml -- bash

The VM driver launches the runtime binary with the matching flag:

openshell-sandbox --bootstrap /run/openshell/bootstrap/boundary.json --privileged

Drivers that do not support privileged mode (Docker, Podman, stock Kubernetes) reject --privileged at creation with a clear error. Inside a supported VM sandbox, workloads run as real root (apt-get, bubblewrap, dockerd, strace/gdb) while external egress, filesystem_policy, and process rules stay enforced by the supervisor and in-guest BPF LSM. Policies requiring hard Landlock fail closed at attach.

Acceptance Criteria

  • openshell sandbox create --privileged (and its --priv alias) creates a privileged sandbox on VM drivers with a hardened CONFIG_BPF_LSM=y kernel and an outer network fence (vsock or fenced control NIC over TCP), and fails closed with a clear error on unsupported drivers.
  • Existing capability-free sandboxes and drivers continue working unchanged by default.
  • openshell-sandbox and the supervisor fail closed if the --privileged flag, protected bootstrap, supervisor runtime descriptor, or confirmation audit evidence disagree.
  • Main, exec, PTY, and SFTP processes run as guest UID 0 inside the workload's mount, PID, cgroup, and loopback-only network namespaces and cannot signal, trace, read memory/fds of, or modify the shim, its /run/openshell mounts, its freezer cgroup, or its control transport (AF_VSOCK or initial-netns NIC), nor load/detach BPF programs.
  • BPF LSM enforces filesystem_policy (read-only, read-write, denied paths, and bind-mount/remount bypass prevention) and process execution rules against guest UID 0, supports live policy map reload, and emits kernel-sourced process/file/denial telemetry via BPF ringbuf.
  • Privileged workloads can install packages, create mounts, run nested containers (dockerd with bridge networking), and use strace/gdb while external TCP and DNS traffic stays governed by supervisor policy with connect-time denies.
  • Outside-the-guest controls hold as defense in depth: outer network fence (with drift checks on TCP/KubeVirt/Kata), ephemeral root overlay wiped across stop/start, host-side bootstrap detach where supported, and generation termination + VM halt on duplicate boundary attach / guest reset.
  • Losing the supervisor freezes the workload cgroup (verified by startup canary qualification) or terminates the workload / halts the VM if freezing is unavailable.
  • Policies with landlock.compatibility: hard_requirement or unrestricted network mode are rejected at attach; in-guest provider files/env vars are refused by default in favor of supervisor-side L7 credential injection.
  • Existing SandboxProtocol and IsolationBackend contracts remain backwards-compatible, and both shared and dedicated supervisor topologies are supported.

Alternatives Considered

  • Untrusted-guest / outside-only root mode (no in-guest kernel enforcement, nftables transparent relay + external NetworkPolicy). Works on stock distro kernels without BPF LSM and keeps the entire security boundary outside the VM, but requires rejecting filesystem_policy, process, and binary rules completely, removes kernel-level instrumentation (leaving only untrusted guest-reported events), requires a dedicated supervisor per sandbox, does not naturally fit vsock-only VMs or dockerd's bridge/iptables networking, and degrades TCP denials to post-handshake RSTs. We adopt its outside-the-guest defense-in-depth controls (fence drift checks, ephemeral root overlay, reset-halt handling, host-side bootstrap hygiene, supervisor-only secret injection) while keeping the guest kernel trusted and instrumented via BPF LSM.
  • User-namespace root (namespace_root) without BPF LSM. Works on stock kernels without BPF LSM, but does not give true guest root. It blocks workloads that need real CAP_NET_ADMIN / CAP_SYS_ADMIN (such as Docker bridge networking and iptables) or ptrace tooling (strace/gdb), and still requires kernel hardening filters around nested namespaces.
  • Grant root directly inside the current capability-free runtime. Without kernel-enforced BPF LSM isolation and separate runtime/workload roots, a guest root workload can read runtime secrets, kill or trace openshell-sandbox, or bypass mediation over AF_VSOCK.
  • Implement privileged mode as an external isolation backend. Possible via IsolationBackend, but duplicates the boundary server, protocol handling, exec/PTY/SFTP lifecycle, and networking broker already in openshell-sandbox.
  • Use providers, middleware, or gateway interceptors. Those operate at the gateway/supervisor layer and cannot change guest kernel isolation or process privilege boundaries inside the VM.

Agent Investigation

  • Checked crates/openshell-driver-vm/runtime/kernel/openshell.kconfig: the pinned libkrunfw Linux 6.12 kernel already includes bpf in CONFIG_LSM (CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,ipe,bpf").
  • Reviewed BPF LSM seal semantics against openshell-sandbox: because OpenShell controls the VM kernel, boots openshell-sandbox as PID 1, and only needs a boot-once BPF LSM (no dynamic signed BPF loading after boot, no TPM), the shim seal plus workload file/process enforcement and ringbuf telemetry work on mainline Linux 6.12 without custom kernel patches. Dropping CAP_PERFMON from the workload bounding set closes the upstream mm_access() read gap without a kernel patch.
  • Compared with the KubeVirt untrusted-guest PoC (jhjaggars/OpenShell@kubevirt-compute-driver-sandboxed): confirmed that outside-the-guest hardening (default-deny + drift-verified NetworkPolicy fences, ephemeral RAM-overlay root wiped across boots, P1/R3 duplicate-attach reset-halt, host-side bootstrap detach to avoid /sys/bus/pci/rescan, and supervisor-only credential injection) composes cleanly as defense in depth alongside an instrumented BPF LSM guest kernel.
  • Confirmed existing SandboxProtocol and IsolationBackend RPCs do not need wire changes: binding the isolation profile into BoundaryConfig and SandboxRuntimeDescriptor with matching audit validation at Confirm supports both capability-free and privileged sandboxes.
  • Verified cgroup.freeze qualification against a SIGCONT canary on Linux under Firecracker in the local spike, and confirmed that seccomp_notify network mediation remains irreversible for UID 0 workload processes.

Implementation plan

  1. Proto, CLI, gateway, and compute-driver contract.
    • Add bool privileged to SandboxSpec (proto/openshell.proto) and DriverSandbox / CreateSandboxRequest (proto/compute_driver.proto), plus a privileged-support capability flag on DriverInfo.
    • Add #[arg(long, visible_alias = "priv")] privileged: bool to openshell sandbox create (crates/openshell-cli) and thread it through openshell-sdk.
    • Fail closed in crates/openshell-server when privileged is requested on drivers that do not advertise support (openshell-driver-docker, openshell-driver-podman, openshell-driver-kubernetes without a supported hardened-kernel VM runtime).
  2. Backend profile, audit, and policy contract (crates/openshell-sandbox-backend, crates/openshell-supervisor).
    • Bind the optional privileged guest profile into BoundaryConfig and SandboxRuntimeDescriptor without changing SandboxProtocol or IsolationBackend wire RPCs.
    • Validate confirmation audit evidence against the supervisor's admitted profile (bpf_lsm_sealed, bpf_policy_enforced, init_net_isolated, vsock_blocked, standing_freeze, workload_uid == 0, landlock_applied == false, scoped executable attribution), allowing workload_uid == 0 only when privileged mode was admitted.
    • Refuse landlock.compatibility: hard_requirement, unrestricted network mode, and default in-guest provider secrets in privileged mode; enforce duplicate-attach / reset generation termination + host-side VM halt.
  3. VM kernel configuration (crates/openshell-driver-vm and KubeVirt/Kata guest kernel builds).
    • Pin CONFIG_BPF_SYSCALL=y, CONFIG_BPF_JIT=y, CONFIG_BPF_LSM=y, and CONFIG_DEBUG_INFO_BTF=y in crates/openshell-driver-vm/runtime/kernel/openshell.kconfig, and disable CONFIG_MODULES, CONFIG_KEXEC, CONFIG_KEXEC_FILE, CONFIG_HIBERNATION, CONFIG_DEVMEM, CONFIG_DEVKMEM, CONFIG_PROC_KCORE, CONFIG_BLK_DEV_WRITE_MOUNTED, and CONFIG_UPROBES.
    • Assert those options in tasks/scripts/vm/build-libkrun.sh after olddefconfig.
  4. Boot-once BPF LSM, policy enforcement, telemetry, and privileged placement (crates/openshell-sandbox).
    • Build and embed a BPF LSM program with BPF_MAP_TYPE_TASK_STORAGE (shim mark + process lineage), a frozen seal config map (runtime_sb_dev, freezer_cgroup_id, init_net_ino), live-reloadable policy maps (filesystem rules + process rules), and a telemetry ringbuf.
    • Attach shim-seal hooks (lsm/bpf, lsm/ptrace_access_check, lsm/perf_event_alloc, lsm/task_kill, lsm/task_setrlimit, lsm/socket_create, lsm/sb_remount, lsm/sb_umount, lsm/locked_down), workload filesystem/mount hooks (lsm/file_open, lsm/inode_create, lsm/inode_unlink, lsm/inode_rename, lsm/inode_setattr, lsm/sb_mount), and process/instrumentation hooks (lsm/bprm_check_security, lsm/task_alloc, lsm/task_free). Keep bpf_link FDs owned by guest PID 1.
    • Add --privileged (alias --priv) to openshell-sandbox and fail closed on flag/bootstrap mismatches.
    • Boot PID 1 from a read-only runtime root (ro,nodev,nosuid), stage bootstrap/TLS into private /run/openshell tmpfs, detach the config disk, attach and seal the BPF LSM, then place workload processes as guest UID 0 inside private mount (pivot_root + MS_REC | MS_PRIVATE), PID, cgroup, and loopback-only network (CLONE_NEWNET) namespaces.
    • Drop only CAP_SYS_MODULE, CAP_SYS_RAWIO, CAP_SYS_BOOT, CAP_BPF, and CAP_PERFMON from the bounding set, install the networking-only seccomp_notify filter (with io_uring blocked), qualify cgroup.freeze against the SIGCONT canary, and dial inbound forwards/exposed services through the workload netns fd.
  5. VM driver wiring, outside-the-guest hardening, and E2E verification.
    • Update crates/openshell-driver-vm (and KubeVirt/Kata VM paths) to boot privileged VMs with separate read-only runtime and ephemeral writable workload overlays, host-side one-shot bootstrap detach where supported, outer network fencing with drift checks on TCP paths, --privileged launch, and admitted profile population in BoundaryConfig and SandboxRuntimeDescriptor.
    • Add unit tests for flag/profile/audit mismatch rejection and VM E2E coverage for positive root workloads (apt-get, mount, dockerd with bridge networking, strace, mediated TCP/DNS, openshell forward, live file/process policy enforcement and reload, supervisor-loss freeze), adversarial root escape checks (BPF LSM seal, bind-mount/remount escapes, io_uring, guest reset / duplicate attach), hard-Landlock refusal, and non-VM driver rejection.

Checklist

  • I've reviewed existing issues and the published docs
  • This is a design proposal, not a "please build this" request

Activity

  1. self-assigned this
    on Nov 24, 2026
  2. added theissue type on Nov 24, 2026
  3. added
    state:accepted
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

state:accepted

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions