Public: anyone can read this; the crew can change it.

Forges sharing a machine each get a cgroup and a sandbox, so no neighbour starves or reads another #16938

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This closes only part of #16856, because most of what it asks for was already on main. I added the Landlock read-hiding and two tests. A hosted forge on a host with Landlock but no bwrap is still not held, and that is the main gap.

Notes

opened this

This closes only part of #16856, because most of what it asks for was already on main. I added the Landlock read-hiding and two tests. A hosted forge on a host with Landlock but no bwrap is still not held, and that is the main gap.

Already on main, left as is (checked, not rebuilt):

  • Cells already have CPU, memory, PIDs and IO caps in their own cgroup, with bwrap and a Landlock floor stacked under it.
  • Each cell already listens on its own port behind the parent, through spawn/cell.ts listen.

What changed:

  • Landlock read allow-list. The floor could only make the filesystem read-only; it could not hide anything. src/sandbox/landlock.ts now takes hide and keep paths. Landlock only adds rights, so readRootsAround grants every sibling along the way to a hidden path instead of /. The helper grants those roots, and links are never granted. A hidden path's parent cannot be listed.
  • Checks. A check with no cell, held by the floor alone, can no longer read the forge's data directory (run_tier.ts → apps/process.ts). That covers forge.db, secret.key, other checks' checkouts and neighbours' files. It still reads its own checkout, home, temp and the shared install cache. The run record now says "the forge's data is not readable" where it used to say reads are open (READS_PARTLY).
  • Docs. docs/features/landlock-floor.md is updated to match.

Tests:

  • test/landlock.test.ts: unit tests for the allow-list, plus a real-kernel test that one forge's floor reads its own directory and gets "refused" for its neighbour's directory and the parent's secret.
  • test/boundary-tenancy-limits.test.ts: two watched forges, one pushed past its memory cap, and only that one is stopped.
  • Run here: landlock*, boundary-tenancy-limits and a few others, 76 pass and 1 skip (the bwrap-stacked case). tsc is clean and gate.ts --explain is clean except the full-suite migrations check I did not run. The only gate note was the false positive described below.
  • Not run: the bwrap and cgroup tests that need a real cell. They are skipped in this sandbox, so the forge's check runs them.

What I chose not to do: a hosted child forge that runs under Landlock alone when bwrap is missing. Today it falls back to the hosted placement. A cell without bwrap loses the network namespace its egress policy relies on, so that needs its own design. hide and keep are the read-confinement piece it would use.

  • Gate note: gate.ts flags readRootsAround and its inner walk as 0.55 similar. I left it, since it is one recursive function and its helper.
  • Finding: under the floor, /dev/null is not writable for checks, so a 2>/dev/null redirect fails. I did not change that.

To try: bun test test/landlock.test.ts test/boundary-tenancy-limits.test.ts.

Closes #16856

5 earlier comments
commented

This closes only part of #16856, because most of what it asks for was already on main. I added the Landlock read-hiding and two tests. A hosted forge on a host with Landlock but no bwrap is still not held, and that is the main gap.

Already on main, left as is (checked, not rebuilt):

  • Cells already have CPU, memory, PIDs and IO caps in their own cgroup, with bwrap and a Landlock floor stacked under it.
  • Each cell already listens on its own port behind the parent, through spawn/cell.ts listen.

What changed:

  • Landlock read allow-list. The floor could only make the filesystem read-only; it could not hide anything. src/sandbox/landlock.ts now takes hide and keep paths. Landlock only adds rights, so readRootsAround grants every sibling along the way to a hidden path instead of /. The helper grants those roots, and links are never granted. A hidden path's parent cannot be listed.
  • Checks. A check with no cell, held by the floor alone, can no longer read the forge's data directory (run_tier.ts → apps/process.ts). That covers forge.db, secret.key, other checks' checkouts and neighbours' files. It still reads its own checkout, home, temp and the shared install cache. The run record now says "the forge's data is not readable" where it used to say reads are open (READS_PARTLY).
  • Docs. docs/features/landlock-floor.md is updated to match.

Tests:

  • test/landlock.test.ts: unit tests for the allow-list, plus a real-kernel test that one forge's floor reads its own directory and gets "refused" for its neighbour's directory and the parent's secret.
  • test/boundary-tenancy-limits.test.ts: two watched forges, one pushed past its memory cap, and only that one is stopped.
  • Run here: landlock*, boundary-tenancy-limits and a few others, 76 pass and 1 skip (the bwrap-stacked case). tsc is clean and gate.ts --explain is clean except the full-suite migrations check I did not run. The only gate note was the false positive described below.
  • Not run: the bwrap and cgroup tests that need a real cell. They are skipped in this sandbox, so the forge's check runs them.

What I chose not to do: a hosted child forge that runs under Landlock alone when bwrap is missing. Today it falls back to the hosted placement. A cell without bwrap loses the network namespace its egress policy relies on, so that needs its own design. hide and keep are the read-confinement piece it would use.

  • Gate note: gate.ts flags readRootsAround and its inner walk as 0.55 similar. I left it, since it is one recursive function and its helper.
  • Finding: under the floor, /dev/null is not writable for checks, so a 2>/dev/null redirect fails. I did not change that.

To try: bun test test/landlock.test.ts test/boundary-tenancy-limits.test.ts.

commented

The check failed on a style rule: src/sandbox/landlock.ts:117 had else if on its own line instead of after the closing }. I moved it onto the brace's line, which changes no behaviour, and pushed the fix as d65f3089c.

test/review-dangling-else.test.ts passes locally. I did not run tsc or the rest of the suite, since the one-line formatting change cannot affect them. The forge's check will run the full suite on this push.

commented

Sentinel's five items are addressed, except that I narrowed the pull to checks (item 4) instead of wiring the floor to hosted forges. Hosted child forges are tracked in #16963.

The targeted Landlock, check-floor, review and dead-code tests, tsc and the gate pass locally. I did not run the full suite, so the forge's check will run it on this push.

Changes

  1. Symlinked hide paths. landlockPlan now resolves every hide path with realpathSync. A hidden path that can't be resolved throws, so the plan fails closed. keep paths are resolved too, and a missing one is left out because it grants nothing. A real-kernel test hides data -> real and shows neither name can be read.
  2. /proc. No /proc/<pid> is a read root any more; the other /proc entries stay. The helper allows only its own /proc/<pid>. A real-kernel test shows another pid's environ is refused and the step's own is readable. One cost: a child process can't read its own /proc/self/..., only the step's top-level shell can. READS_PARTLY and the docs now describe what is held.
  3. Tests.
    • Memory-cap test. I dropped it, so test/boundary-tenancy-limits.test.ts is back to main's version. It also no longer appears in the docs.
    • Floor handed to runStep. The check's floor now comes from checkFloor in src/checks/floor.ts, and test/check-floor.test.ts covers its hide, keep and writable. It also checks that landlockPlan turns that floor into narrowed reads. The runStep line itself is not unit-tested; landlock-real.test.ts covers it, and that test is skipped without Landlock.
    • skipIf. The if (!probe.ok) return; lines in test/landlock.test.ts stay only for type narrowing. They sit inside describe.skipIf(!probe.ok), so a kernel without Landlock reports them skipped, not green.
    • landlock-real.test.ts. The no-cell check test now also asserts the forge's data directory and another pid's environ can't be read.
  4. Scope. I narrowed to checks and opened #16963 for hosted child forges on a host with Landlock and no bubblewrap. The docs say plainly that those aren't held yet. Wiring them in needs the hosted-spawn path, which is more than this pull. If you want the title narrowed, that is for a person to do.
  5. Small items.
    • runStep's floor type is now Pick<LandlockWant, …> & { abi }.
    • landlockArgv checks the plan's own paths and ports instead of rebuilding a want.
    • /dev/null is writable in the check floor, so 2>/dev/null works, and run_tier no longer tries to mkdir it.

To try it. Run bun test test/landlock.test.ts test/check-floor.test.ts test/landlock-real.test.ts.

commented

I merged main into the branch and pushed it. The only conflict was in src/checks/run_tier.ts.

  • Resolution: the conflict was in the imports from landlock.ts. This pull uses checkFloor and READS_PARTLY, and main added CHECK_FLOOR_ENV and READS_OPEN. I kept checkFloor, CHECK_FLOOR_ENV and READS_PARTLY there. READS_OPEN is still used in src/crew/sandbox.ts, which merged without a conflict.
  • Checks run: bun x tsc --noEmit is clean. The Landlock and floor tests pass: check-floor, landlock, landlock-real and crew-sandbox-floor gave 28 pass, 1 skip, 0 fail.
  • Not run: the full suite. scripts/fast.ts named 3817 files, about 321 minutes, so I stopped that run. The forge's check on this push will run everything.
commented

This push fixes the dead-code failure on #16856 and adds a small refactor for the dupes gate. I haven't seen the forge's check verdict yet.

What changed

  • Dead code: validWant in src/sandbox/landlock.ts had no caller left in src/. Only tests called it, since the Landlock argv check stopped using it. landlockPlan now calls it first and throws landlock: unsafe request when the request has a relative path, a NUL byte or a bad port. scripts/unused-exports.ts no longer lists it.
  • Gate dupes warning: scripts/gate.ts paired readRootsAround with its inner walk closure as probable duplicates. I moved walk out as a module-level descend function with the same logic, and the warning is gone.

What I checked

  • Run: bun x tsc --noEmit, test/landlock.test.ts, test/check-floor.test.ts, test/unused-exports.test.ts and test/landlock-real.test.ts.
  • Result: no type errors, and the tests pass. One test skips: test/landlock-real.test.ts has a skipped case, and I didn't look into why.
  • The gate reports nothing except an advisory note about long comment lines in src/apps/process.ts. It leaves that to the nightly rewrap on main.

What I left alone

  • The other entries scripts/unused-exports.ts lists belong to other code and are already on main's allow-list.
  • This change doesn't touch the web, API or MCP surface, so no terminal or docs/features/ change was needed.
  • Both commits say "Direction: … (#16856)".

How to try it

  • bun test test/landlock.test.ts test/check-floor.test.ts
  • bun scripts/unused-exports.ts | grep validWant should print nothing.
commented

Left #16856 open: 2 unticked items remain (Each co-hosted forge runs in its own cgroup with CPU, memory, PIDs and IO caps, and under bwrap, or the Landlock floor (#16835) where bwrap cannot run.; Tests: a forge past its memory cap is ended alone; one forge cannot read another's files.).

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs