Repository navigation
Description
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:
- In-guest kernel plane: a hardened mainline
CONFIG_BPF_LSM=yVM kernel + boot-once BPF LSM enforcing shim isolation, workloadfilesystem_policy/processrules, and kernel-sourced telemetry, paired withCLONE_NEWNET+seccomp_notify(ADDFD) network mediation. - 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 0inside its own mount namespace (pivot_rootinto the writable workload rootfs withMS_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 (eth0for TCP orvsock), 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-sandboxboots 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 inBPF_MAP_TYPE_TASK_STORAGE, and the LSM covers three planes without requiringno_new_privs:- Shim seal:
lsm/bpfblocks unmarked tasks from callingbpf()(locking down further loads/detaches without signed BPF loaders or custom kernel patches).lsm/ptrace_access_check,lsm/perf_event_alloc,lsm/task_kill, andlsm/task_setrlimitblock process tampering against marked shim tasks.lsm/socket_createblocksAF_VSOCKand non-loopbackinit_netsockets/netlink from unmarked tasks.lsm/file_open,lsm/inode_*,lsm/sb_remount, andlsm/sb_umountprotect the runtime/run/openshellsuperblock (TLS CA and runtime state) and the runtime-owned workload freezer cgroup.lsm/locked_downenforces kernel lockdown.
- Workload
filesystem_policyenforcement:lsm/file_open,lsm/inode_create,lsm/inode_unlink,lsm/inode_rename,lsm/inode_setattr, andlsm/sb_mountenforce read-only, read-write, and denied path rules even against guestUID 0(CAP_DAC_OVERRIDE).- Rules evaluate against kernel inode ancestry / superblocks and gate
lsm/sb_mountso 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_policyupdates support live reload without restarting the workload.
- Workload
processrules and kernel instrumentation:lsm/bprm_check_securityenforcesprocessexecution rules against real kernel inodes/paths.lsm/task_alloc/lsm/task_freemaintain trusted kernel-side process lineage inBPF_MAP_TYPE_TASK_STORAGEand stream non-spoofable process, file, and denial telemetry toopenshell-sandboxover a BPF ringbuf.- When
filesystem_policyholds system binary directories read-only (enforced againstUID 0by BPF LSM), binary attribution for executables under those paths remains trustworthy; executables in writable paths are treated as advisory.
- Shim seal:
- 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, andCONFIG_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_notifyfilter (withio_uringblocked so async socket ops cannot bypass mediation) beforeexec. Linux does not allow evenUID 0to remove a seccomp filter. BecauseNetworkBrokercreates mediated TCP and loopback DNS (127.0.0.53:53) sockets in the shim'sinit_netand injects them viaADDFD, external connections and DNS work cleanly across the workload'sCLONE_NEWNETboundary over bothvsockand TCP, with connect-time denies and no collision withdockerdbridges 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
vsockVMs (openshell-driver-vm/ Firecracker), or a default-deny floor plus per-sandboxNetworkPolicyallowing 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
--privilegedtoopenshell-sandboxand binds the privileged profile in bothBoundaryConfigandSandboxRuntimeDescriptor.openshell-sandboxand the supervisor fail closed on mismatches and validate privileged audit evidence atConfirm. Losing the supervisor freezes the runtime-owned workload cgroup (cgroup.freeze, qualified at startup against aSIGCONTcanary), 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=yand an outer network fence (vsockwith 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_requirementor unrestricted network mode are refused at attach.filesystem_policyis 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 toLD_PRELOADfrom 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 -- bashThe VM driver launches the runtime binary with the matching flag:
openshell-sandbox --bootstrap /run/openshell/bootstrap/boundary.json --privilegedDrivers 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--privalias) creates a privileged sandbox on VM drivers with a hardenedCONFIG_BPF_LSM=ykernel and an outer network fence (vsockor 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-sandboxand the supervisor fail closed if the--privilegedflag, protected bootstrap, supervisor runtime descriptor, or confirmation audit evidence disagree. - Main, exec, PTY, and SFTP processes run as guest
UID 0inside 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/openshellmounts, its freezer cgroup, or its control transport (AF_VSOCKor 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) andprocessexecution rules against guestUID 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 (
dockerdwith bridge networking), and usestrace/gdbwhile 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_requirementor 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
SandboxProtocolandIsolationBackendcontracts 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,
nftablestransparent relay + externalNetworkPolicy). Works on stock distro kernels without BPF LSM and keeps the entire security boundary outside the VM, but requires rejectingfilesystem_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 fitvsock-only VMs ordockerd'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 realCAP_NET_ADMIN/CAP_SYS_ADMIN(such as Docker bridge networking and iptables) orptracetooling (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 overAF_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 inopenshell-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 pinnedlibkrunfwLinux 6.12 kernel already includesbpfinCONFIG_LSM(CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,ipe,bpf"). - Reviewed BPF LSM
sealsemantics againstopenshell-sandbox: because OpenShell controls the VM kernel, bootsopenshell-sandboxas 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. DroppingCAP_PERFMONfrom the workload bounding set closes the upstreammm_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-verifiedNetworkPolicyfences, 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
SandboxProtocolandIsolationBackendRPCs do not need wire changes: binding the isolation profile intoBoundaryConfigandSandboxRuntimeDescriptorwith matching audit validation atConfirmsupports both capability-free and privileged sandboxes. - Verified
cgroup.freezequalification against aSIGCONTcanary on Linux under Firecracker in the local spike, and confirmed thatseccomp_notifynetwork mediation remains irreversible forUID 0workload processes.
Implementation plan
- Proto, CLI, gateway, and compute-driver contract.
- Add
bool privilegedtoSandboxSpec(proto/openshell.proto) andDriverSandbox/CreateSandboxRequest(proto/compute_driver.proto), plus a privileged-support capability flag onDriverInfo. - Add
#[arg(long, visible_alias = "priv")] privileged: booltoopenshell sandbox create(crates/openshell-cli) and thread it throughopenshell-sdk. - Fail closed in
crates/openshell-serverwhenprivilegedis requested on drivers that do not advertise support (openshell-driver-docker,openshell-driver-podman,openshell-driver-kuberneteswithout a supported hardened-kernel VM runtime).
- Add
- Backend profile, audit, and policy contract (
crates/openshell-sandbox-backend,crates/openshell-supervisor).- Bind the optional privileged guest profile into
BoundaryConfigandSandboxRuntimeDescriptorwithout changingSandboxProtocolorIsolationBackendwire 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), allowingworkload_uid == 0only 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.
- Bind the optional privileged guest profile into
- VM kernel configuration (
crates/openshell-driver-vmand KubeVirt/Kata guest kernel builds).- Pin
CONFIG_BPF_SYSCALL=y,CONFIG_BPF_JIT=y,CONFIG_BPF_LSM=y, andCONFIG_DEBUG_INFO_BTF=yincrates/openshell-driver-vm/runtime/kernel/openshell.kconfig, and disableCONFIG_MODULES,CONFIG_KEXEC,CONFIG_KEXEC_FILE,CONFIG_HIBERNATION,CONFIG_DEVMEM,CONFIG_DEVKMEM,CONFIG_PROC_KCORE,CONFIG_BLK_DEV_WRITE_MOUNTED, andCONFIG_UPROBES. - Assert those options in
tasks/scripts/vm/build-libkrun.shafterolddefconfig.
- Pin
- 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). Keepbpf_linkFDs owned by guest PID 1. - Add
--privileged(alias--priv) toopenshell-sandboxand fail closed on flag/bootstrap mismatches. - Boot PID 1 from a read-only runtime root (
ro,nodev,nosuid), stage bootstrap/TLS into private/run/openshelltmpfs, detach the config disk, attach and seal the BPF LSM, then place workload processes as guestUID 0inside 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, andCAP_PERFMONfrom the bounding set, install the networking-onlyseccomp_notifyfilter (withio_uringblocked), qualifycgroup.freezeagainst theSIGCONTcanary, and dial inbound forwards/exposed services through the workload netns fd.
- Build and embed a BPF LSM program with
- 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,--privilegedlaunch, and admitted profile population inBoundaryConfigandSandboxRuntimeDescriptor. - Add unit tests for flag/profile/audit mismatch rejection and VM E2E coverage for positive root workloads (
apt-get,mount,dockerdwith 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.
- Update
Checklist
- I've reviewed existing issues and the published docs
- This is a design proposal, not a "please build this" request
Activity