Skip to content

openenvd 2/5: cgroups and the isolation preflight - #1385

Open
zkwentz wants to merge 2 commits into
zkwentz/openenvd-k1-contractfrom
zkwentz/openenvd-k3-kernel
Open

zkwentz wants to merge 2 commits into
zkwentz/openenvd-k1-contractfrom
zkwentz/openenvd-k3-kernel

Conversation

@zkwentz

@zkwentz zkwentz commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This layer decides whether openenvd can isolate, and controls each zone's processes when it can.

  • preflight.py. One yes-or-no decision, with the reasons when it's no. Isolation is on when all of these hold:

    • openenvd runs as root;
    • a child process can create user, mount, PID and network namespaces;
    • the cgroup v2 root is writable;
    • an OCI runtime (crun) is installed.

    That's true inside a microVM or a --privileged container. Every failed check says how to fix it, for example (run the container with --privileged).

  • cgroups.py. The unit's cgroup v2 tree (control/, zones/<zone>/<container>):

    • limits;
    • cgroup.freeze;
    • atomic cgroup.kill, so a fork bomb can't outrun it;
    • waiting for populated 0;
    • stats.

This replaces an earlier design that probed the host and picked between three tiers. The deployment assumption makes that unnecessary: production runs in a microVM, and everything else simply runs without isolation.

Test plan

Stack

Part of openenvd on kernel primitives (#1053). Review bottom-up; each PR shows only its own layer.

  1. openenvd 1/5: manifest contract and unit phases #1383: Contract and phases
  2. openenvd 2/5: cgroups and the isolation preflight #1385: cgroups and the isolation preflight ← this PR
  3. openenvd 3/5: confinement (seccomp, OCI, shim, forwarders, custody) #1416: Confinement: seccomp, OCI, shim, forwarders, custody
  4. openenvd 4/5: relays and the external surfaces #1386: Relays and surfaces
  5. openenvd 5/5: unit assembly, daemon, enforcement check and live tests #1387: Unit, daemon, check, live tests

Deployment assumption: openenvd ships in every image. Run privileged (a microVM in production, or docker run --privileged in development) and it isolates. Run any other way and it logs isolation disabled and serves the environment exactly as before.

The trace machinery (hash-chained trace, seal, harness self-report cross-check, /observe) is parked on zkwentz/openenvd-with-trace and is out of this stack's scope.

🤖 Generated with Claude Code


Note

Medium Risk
New kernel-facing cgroup and namespace probing code affects process lifecycle and resource limits; misconfiguration could break isolation or teardown, though preflight is designed to disable isolation when prerequisites fail.

Overview
Adds isolation preflight and a cgroup v2 control layer for openenvd: decide whether the unit can run containers, and manage per-zone process trees when it can.

preflight returns a single enable/disable result with log-friendly failure reasons (Linux, root, namespace creation in a forked child, writable cgroup v2 root, OCI runtime discovery for crun/runc/runsc). Failed checks include hints such as --privileged and --cgroupns=private.

cgroups.CgroupTree owns the unit cgroup namespace: adopt_self into control/, create delegated paths like zones/agent/{env,harness}, apply Resources limits (memory, swap off, pids, cpu), move PIDs, freeze/thaw, kill via cgroup.kill or SIGKILL sweep, async wait for frozen/empty, stats, and subtree removal.

Tests cover fake cgroupfs behavior plus an optional root-only Linux lifecycle test.

Reviewed by Cursor Bugbot for commit eb77c21. Bugbot is set up for automated code reviews on this repo. Configure here.

@zkwentz
zkwentz force-pushed the zkwentz/openenvd-k3-kernel branch from e438db8 to c0d619d Compare October 12, 2026 17:35
@zkwentz zkwentz changed the title openenvd 3/5: kernel building blocks (cgroups, probes, seccomp, Landlock, OCI, shim) openenvd 2/4: kernel building blocks (cgroups, probes, seccomp, Landlock, OCI, shim, custody) Oct 12, 2026
@zkwentz
zkwentz changed the base branch from zkwentz/openenvd-k2-trace to zkwentz/openenvd-k1-contract October 12, 2026 17:35
@zkwentz
zkwentz added this pull request to stack #1415 October 12, 2026 18:38
Comment thread src/openenv/core/openenvd/shim.py Fixed
Comment thread src/openenv/core/openenvd/shim.py Fixed
Comment thread src/openenv/core/openenvd/shim.py Fixed
@zkwentz
zkwentz force-pushed the zkwentz/openenvd-k3-kernel branch from c0d619d to 3a6439f Compare October 13, 2026 00:31
@zkwentz
zkwentz removed this pull request from stack #1415 October 13, 2026 00:32
@zkwentz
zkwentz added this pull request to stack #1417 October 13, 2026 00:32
@zkwentz zkwentz changed the title openenvd 2/4: kernel building blocks (cgroups, probes, seccomp, Landlock, OCI, shim, custody) openenvd 2/5: host probes, cgroups and process trees Oct 13, 2026
@zkwentz
zkwentz force-pushed the zkwentz/openenvd-k3-kernel branch from 3a6439f to 4b8b997 Compare October 13, 2026 01:09
@zkwentz zkwentz changed the title openenvd 2/5: host probes, cgroups and process trees openenvd 2/5: cgroups and the isolation preflight Oct 13, 2026
body()
msg = ""
status = 0
except BaseException as exc: # noqa: BLE001 - report, never propagate
for pid in pids:
try:
os.kill(pid, signal.SIGKILL)
except (ProcessLookupError, PermissionError):
return f"cgroup root is not writable ({exc.strerror})"
try:
probe.rmdir()
except OSError:
Part 2 of 5 of openenvd on kernel primitives (#1053).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zkwentz
zkwentz force-pushed the zkwentz/openenvd-k3-kernel branch from 4b8b997 to 902f6ff Compare October 13, 2026 14:23
cgroup_of_pid and is_within lost their only caller with peercred. The
fake-cgroupfs removal now lives in the test fixture instead of cgroups.py.
The real-kernel test can adopt the cgroup root when a throwaway container
opts in, so it runs instead of skipping in privileged Docker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zkwentz
zkwentz marked this pull request as ready for review October 13, 2026 17:36
@burtenshaw burtenshaw added feature size: large Large pull request labels Oct 13, 2026 — with Cursor

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

feature size: large Large pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants