Add microVM isolation mode for project labs via Kata Containers#25
Conversation
|
Pushed Generated by Claude Code |
|
Update: the That unblocking revealed a separate, pre-existing failure underneath, unrelated to this PR's changes: This fails consistently across all 3 attempts (2 configured CI retries). The test fully mocks its API calls via This is the first time this Playwright suite has run to completion in CI — every previous run failed earlier at the Generated by Claude Code |
Adds a `microvm` LabIsolationMode alongside the existing container boundary: docker-plan.ts registers a `--runtime <kata-class>` OCI runtime and audit labels, service.ts threads the choice through create/start/restart (persisted in lab metadata like networkProfile), and runtime.ts fails closed with MicrovmRuntimeUnavailableError rather than silently downgrading isolation when the requested Kata runtime class is not registered with the Docker daemon. Documents setup requirements and limitations in docs/lab-runtime-hardening.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FYzvg68ntwkoSEQJ1NkC6a
LibSQLStore fails with ConnectionFailed(...code: 14) when the parent directory of a local sqlite file (e.g. the default .data/mastra.sqlite, which is gitignored) doesn't exist yet, breaking Playwright's webServer boot on a fresh checkout/CI runner. Create the directory first for file: URIs before constructing the store. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FYzvg68ntwkoSEQJ1NkC6a
5916346 to
8f6713e
Compare
Description
The project lab runtime (
src/server/labs/) already provisions Kali lab containers with strong Linux-namespace hardening (--cap-drop ALL,no-new-privileges, resource limits, egress iptables). That still shares the host kernel with every lab, so a container escape lands on the host. This adds amicrovmLabIsolationModealongside the existingcontainermode: the lab container runs under a Kata Containers OCI runtime class (kata-fcby default, orkata-qemu/kata-clh), giving each lab its own guest kernel via hardware virtualization (Firecracker/QEMU/Cloud Hypervisor), on top of the existing capability/network/resource hardening.hardening.ts:LabIsolationModeresolution helpers, Kata runtime class constants, and a safe-name validation regex.docker-plan.ts:buildRunLabCommandadds--runtime <class>andexploit-hunter.isolation/exploit-hunter.microvm-runtime-classlabels when microVM isolation is requested; a newbuildMicrovmRuntimeCheckCommandbuilds adocker infoavailability check.runtime.ts:ProjectLabRuntime.start()runs that availability check before provisioning and fails closed — throwsMicrovmRuntimeUnavailableErrorrather than silently falling back to weaker container isolation — if the requested Kata runtime class isn't registered with the Docker daemon. Dry-run mode surfaces the check command in the plan without executing/enforcing it.service.ts: threadsisolation/microvmRuntimeClassthrough create/start/restart, mirroring the existingnetworkProfilepattern (per-request override, persisted in lab metadata for restarts).types.ts: adds theLabIsolationModetype andisolation/microvmRuntimeClassfields toLabCreateInput/LabContainerOptions.docs/lab-runtime-hardening.md: new "MicroVM Isolation (Kata Containers)" section covering enablement (per-lab input orPROJECT_LAB_ISOLATION_MODE/PROJECT_LAB_MICROVM_RUNTIME_CLASSenv vars), fail-closed behavior, and host prerequisites (KVM/nested virtualization + a Kata Containers install) — cross-referenced from the existing Limitations section.Default behavior is unchanged:
isolationdefaults to"container", so existing labs and callers are unaffected unless they opt in.Note on testing environment: this sandbox has no
/dev/kvmand no Kata Containers install, so I could not do an end-to-end run of an actual microVM lab. The change is scoped so the code paths are fully exercised via the existingdry-run/fake-runner test harness (see below); real end-to-end verification needs a KVM-capable Docker host with Kata Containers installed, per the new docs section.Type of change
How Has This Been Tested?
pnpm typecheck— no new errors in touched files (ran targetedtsc --noEmit; this sandbox has pre-existing unrelated@types/node/native-module gaps from a constrained, script-skippedpnpm install)pnpm test(targeted) —tests/security-chat/lab-runtime.test.ts,project-lab.test.ts,docker-lab-target.test.tsall pass (37 tests), including 7 new tests covering: default stays oncontainerisolation with no--runtimeflag,--runtime/labels added formicrovm, custom runtime class override, unsafe runtime class name rejection, dry-run plan includes the availability check, fail-closed when the Docker daemon doesn't have the runtime registered, and successful start once it is registered.Checklist
docs/lab-runtime-hardening.md)Security Considerations
This directly affects sandboxing. The key security property is fail-closed: if
microvmisolation is requested but the Docker daemon doesn't have the corresponding Kata runtime class registered, lab startup is refused withMicrovmRuntimeUnavailableErrorrather than silently running with weaker container isolation. Default behavior (containerisolation) is unchanged, so this is opt-in and additive to the existing capability-drop/network/resource hardening — it does not replace or weaken any of it.Generated by Claude Code