Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/identity-gate-holder-death.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-sdk": patch
---

A separate-UID worker launch whose identity coordinator dies before releasing the start gate no longer starts its payload (#3402). The coordinator's gate is bubblewrap's `--block-fd`, which starts the sandbox on end-of-file. Every separate-identity payload now also waits behind the trusted stdin gate, a complete `go` line that the server writes only after the coordinator confirms the release. The identity helper protocol is unchanged, and payload stdin after the gate line is byte-identical.
6 changes: 3 additions & 3 deletions docs/decisions/container-fresh-proc.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A fresh /proc for agent workers in a container

The agent worker launcher gives every worker its own user and PID namespaces
and a fresh procfs (`workerCommand`, `packages/ui-sdk/src/server/worker-launcher.ts:518-698`).
and a fresh procfs (`workerCommand`, `packages/ui-sdk/src/server/worker-launcher.ts:534-714`).
Under Docker's default masked `/proc` paths the kernel refuses that procfs
mount, so every turn on such a host refuses with
`bwrap: Can't mount proc on /newroot/proc: Operation not permitted` (#1622,
Expand All @@ -22,7 +22,7 @@ does not change.
/proc because the parent /proc has masked or covered paths; in Docker, run
the container with --security-opt systempaths=unconfined", followed by
bubblewrap's own line. Every other launch failure keeps the generic list
(`FRESH_PROC_REFUSED`, `packages/ui-sdk/src/server/worker-launcher.ts:1650`).
(`FRESH_PROC_REFUSED`, `packages/ui-sdk/src/server/worker-launcher.ts:1668`).
The match is on bubblewrap's literal message, not a guess from the
environment: a host that refuses for another reason is not told to change
Docker options.
Expand Down Expand Up @@ -145,7 +145,7 @@ most host-global `/proc` files check only the file mode, not a capability.
**Ruling on #1629 (2026-10-11): a root-run server's worker gets its whole
`/proc` read-only. Root servers still qualify.** `workerCommand` adds
`--remount-ro /proc` after `--proc /proc` when the server's uid or effective
uid is 0 (`rootProcCover`, `packages/ui-sdk/src/server/worker-launcher.ts:343-345`).
uid is 0 (`rootProcCover`, `packages/ui-sdk/src/server/worker-launcher.ts:359-361`).
Measured as container root with `systempaths=unconfined` and the seccomp
profile above, with bubblewrap `0.9.0` from the image and the host's `0.12.0`,
each in the ordinary and the restricted mode:
Expand Down
24 changes: 12 additions & 12 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ lists the keys each first-party command reads. The launcher withholds every
provider credential in the subprocess descriptor from a governed or strict
turn worker, except what its backend declares for its own inference and what
an operator admits (`const turnProfile`,
`packages/ui-sdk/src/server/worker-launcher.ts:689-699`). A relayed turn keeps no
`packages/ui-sdk/src/server/worker-launcher.ts:705-715`). A relayed turn keeps no
key. An unrelayed one keeps only its runtime's own inference credential, under
the 2026-10-22 ruling that hosts without managed native storage keep today's
inference credentials; pi resolves its own credentials there, so it keeps all
Expand Down Expand Up @@ -1029,7 +1029,7 @@ worker's command starts, the server opens that tmpfs from outside through the
sandbox's `/proc/<pid>/root`. It waits until the path is a tmpfs of exactly
the allowance on another device than the server's own `/tmp`, and keeps the
descriptor
(`function* openPrivateTurnTempSteps`, `packages/ui-sdk/src/server/worker-launcher.ts:1150-1178`).
(`function* openPrivateTurnTempSteps`, `packages/ui-sdk/src/server/worker-launcher.ts:1166-1194`).
Every later read goes through that descriptor, after the worker's namespace
is gone as well, and never enters another mount, so runtime state below
`/tmp` is never read as turn temp. The allowance (256 MiB by default,
Expand Down Expand Up @@ -2190,7 +2190,7 @@ a filesystem socket that is visible through the read-only host root: a Docker
socket, a session bus, an SSH agent or a host proxy. Each of those is an
unrecorded way out, and some reach privileged host effects. The launcher
already masks `.git` in restricted workers for exactly this reason
(`function maskedGit`, `packages/ui-sdk/src/server/worker-launcher.ts:235`).
(`function maskedGit`, `packages/ui-sdk/src/server/worker-launcher.ts:251`).

`governed` and `strict` workers therefore mask the host's runtime and state
directories with empty read-only tmpfs mounts. Maintenance workers share the
Expand All @@ -2208,7 +2208,7 @@ The worker's private `/tmp` and the other host masks remain in place.

After the masks, the launcher re-binds only the explicit runtime inputs the
worker needs, read-only, with the same resolution the restricted envelope uses
(`export function restrictedReadPaths`, `packages/ui-sdk/src/server/worker-launcher.ts:1925`):
(`export function restrictedReadPaths`, `packages/ui-sdk/src/server/worker-launcher.ts:1944`):

- the Bun executable;
- the backend entry's package, its `node_modules` chains and linked workspace
Expand All @@ -2232,7 +2232,7 @@ such ancestor with empty tmpfs instead; it never binds that ancestor's real
contents. Search permission uses the helper's primary shared group class when
that group owns the directory, including when only the other class has execute
permission. Existing canonical aliases and nested masks fold into that cover
(`maintenanceMounts`, `packages/ui-sdk/src/server/worker-launcher.ts:394-453`).
(`maintenanceMounts`, `packages/ui-sdk/src/server/worker-launcher.ts:410-469`).

This supports disjoint private-state layouts, including a nested operational
database below a server-owned `0700` parent. New ancestor coverage that would
Expand Down Expand Up @@ -2308,9 +2308,9 @@ and subdirectories through retained aliases. It does not restore unrelated
host-temp siblings or make runtime bytes writable.

The concrete checks and mounts are in (`validateRuntimePlacement`,
`packages/ui-sdk/src/server/worker-launcher.ts:618-624`),
(`temporaryRuntimeMounts`, `packages/ui-sdk/src/server/worker-launcher.ts:645-684`)
and (`runtimeMaskOverlays`, `packages/ui-sdk/src/server/worker-launcher.ts:800-818`).
`packages/ui-sdk/src/server/worker-launcher.ts:634-640`),
(`temporaryRuntimeMounts`, `packages/ui-sdk/src/server/worker-launcher.ts:661-700`)
and (`runtimeMaskOverlays`, `packages/ui-sdk/src/server/worker-launcher.ts:816-834`).
Alias restoration recognizes names already supplied by a read-only bind or an
explicit system-view symlink. It does not mount a canonical executable over an
existing alias such as `/bin/sh`; missing owned temporary paths still receive
Expand Down Expand Up @@ -3341,7 +3341,7 @@ before mounting them: both belong to the server, helper mode uses its primary
GID and exact `0750`/`0660` modes, and no-helper mode retains exact
`0700`/`0600`. Missing endpoints, aliases, non-sockets, foreign ownership and
wider modes refuse before payload execution
(`function restrictedMounts`, `packages/ui-sdk/src/server/worker-launcher.ts:259-293`).
(`function restrictedMounts`, `packages/ui-sdk/src/server/worker-launcher.ts:275-309`).
This compatibility check does not change default autonomous admission or add
another route.

Expand Down Expand Up @@ -3479,11 +3479,11 @@ An ordinary group-shared directory was accessible, but the worker's private
mount and namespace links through `/proc/<pid>` were denied. Changing the
private directory to `0770` did not remove that process-access barrier. The
current launcher opens mounts directly (`function openPrivateState`,
`packages/ui-sdk/src/server/worker-launcher.ts:1113-1141`;
`packages/ui-sdk/src/server/worker-launcher.ts:1129-1157`;
`function* openPrivateTurnTempSteps`,
`packages/ui-sdk/src/server/worker-launcher.ts:1150-1176`) before population and
`packages/ui-sdk/src/server/worker-launcher.ts:1166-1192`) before population and
start-gate release (`function* launchAgentWorkerSteps`,
`packages/ui-sdk/src/server/worker-launcher.ts:1339-1427`). Group modes and a uid
`packages/ui-sdk/src/server/worker-launcher.ts:1355-1443`). Group modes and a uid
switch alone therefore cannot implement the selected cross-uid lifecycle.

**Authority and launch.** One trusted external supervisor owns each worker
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/managed-worktrees.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Each governed or strict turn whose journal is recording opens one worker
generation, and every worker of that turn binds the generation's root-owned
directory whole at `/tmp/brain-worktrees`, inside the turn's own `/tmp`
(`// Managed worktrees (#2430): a journaled turn's workers bind one empty generation.`, `packages/ui-server/src/ws/run-session.ts:570-582`;
`// Managed worktrees (#2430): the whole access generation`, `packages/ui-sdk/src/server/worker-launcher.ts:861-872`).
`// Managed worktrees (#2430): the whole access generation`, `packages/ui-sdk/src/server/worker-launcher.ts:877-888`).
A granted worktree appears there as `/tmp/brain-worktrees/<worktree id>/` on the
worker's next path lookup; the worker cannot create entries beside it, and a
restricted worker never binds a generation. Nothing returns a host path to the
Expand Down Expand Up @@ -212,7 +212,7 @@ nothing.
**Shared source is read through views.** Each such turn's workers bind the
public view and their principal's private view whole and read-only at
`/tmp/brain-reference/public` and `/tmp/brain-reference/private`
(`// Shared reference source (#2432)`, `packages/ui-sdk/src/server/worker-launcher.ts:873-884`).
(`// Shared reference source (#2432)`, `packages/ui-sdk/src/server/worker-launcher.ts:889-900`).
A view the domain has not published to yet is opened empty first, so the turn
sees its own first acquisition
(`async bindable(principalId: string`, `packages/ui-server/src/brain/reference-source.ts:741-753`).
Expand Down
64 changes: 58 additions & 6 deletions docs/decisions/policy-write-boundary.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,13 @@ sessions.
before the runtime starts and read it after the worker is gone, while the
tmpfs is reachable only inside the worker. The launcher does both from the
host (`function* launchAgentWorkerSteps`,
`packages/ui-sdk/src/server/worker-launcher.ts:1339-1595`):
`packages/ui-sdk/src/server/worker-launcher.ts:1355-1613`):

1. It finds the sandbox's first process from the kernel's record of
bubblewrap's only child, then opens the tmpfs root through
`/proc/<pid>/root` and keeps that directory descriptor
(`function openPrivateState`,
`packages/ui-sdk/src/server/worker-launcher.ts:1113-1137`). bubblewrap's
`packages/ui-sdk/src/server/worker-launcher.ts:1129-1153`). bubblewrap's
process exists before its mounts do, so the open is accepted only once the
path is its own mount (a device other than its parent's), a tmpfs of
exactly the allowance, and empty; until then it would name the host's
Expand All @@ -513,7 +513,7 @@ host (`function* launchAgentWorkerSteps`,
code: the absolute `/bin/sh` reads one line from the worker's stdin with
its `read` builtin, which only the server writes, and then becomes the
command; closed stdin or any other line ends the worker unstarted
(`const STATE_GATE`, `packages/ui-sdk/src/server/worker-launcher.ts:54`).
(`const STATE_GATE`, `packages/ui-sdk/src/server/worker-launcher.ts:57`).
The gate runs no `PATH` lookup, so nothing in the worker's environment or
the brain can stand in for it, and the shell reads a pipe a byte at a time,
so the runtime's own input is untouched. The server copies the snapshot in
Expand Down Expand Up @@ -692,7 +692,7 @@ as fd 4 after the bootstrap's descriptor filter. bubblewrap passes it into the
sandbox, where the trusted absolute `/bin/sh` reads one line from it, requires
exactly `go`, closes fd 4 and only then execs the payload. EOF, a partial line
or any other line ends the sandbox with exit 125. `release()` writes `go\n`
(`const START_GATE`, `packages/ui-sdk/src/server/worker-launcher.ts:65`).
(`const START_GATE`, `packages/ui-sdk/src/server/worker-launcher.ts:68`).

**Why.** bubblewrap proceeds past `--block-fd` on EOF: its sandbox child reads
one byte and ignores the result. That child arms `PR_SET_PDEATHSIG` only after
Expand Down Expand Up @@ -750,5 +750,57 @@ with descriptors 0-2 only and stdin byte-identical.

**Not covered.** The separate-UID identity helper gates with its own
`--block-fd` pipe. Whether its death fails closed is tracked in
[#3402](https://github.com/schlessera/brain-kit/issues/3402). Post-release
server death is unchanged.
[#3402](https://github.com/schlessera/brain-kit/issues/3402), and the next
section rules on it. Post-release server death is unchanged.

### The identity helper's start gate fails closed too — 2026-11-03

Ruling on [#3402](https://github.com/schlessera/brain-kit/issues/3402), applying
the decision above to the separate-UID launch.

**The hole.** A separate-identity launch does not use the server's fd 4 gate.
Its same-UID coordinator (`WORKER_IDENTITY_SUPERVISOR`) holds the only writer
of its own gate pipe. The helper protocol puts that pipe on bubblewrap's
`--block-fd` and the helper refuses a launch without it
([the host protocol](../hosting/agent-workers.md#separate-worker-identity)).
The launcher also removed `STATE_GATE` from these payloads. So the payload's
only gate was `--block-fd`, which opens on end-of-file. Probed on a Linux host
with bubblewrap 0.11.1, using the real launcher and coordinator against a
same-UID stand-in helper: a coordinator SIGKILLed after spawn and before
release started the payload, both during setup and after it, for synchronous
and asynchronous launches. A server and coordinator killed together also
started the payload. The helper's parent-death signal kills the outer
bubblewrap but not its sandbox child, as above.

**Decision.** Every separate-identity payload now runs behind `STATE_GATE`, the
trusted absolute `/bin/sh` that reads one complete `go` line from stdin and
refuses end-of-file or anything else with exit 125
(`function identityStartGate`,
`packages/ui-sdk/src/server/worker-launcher.ts:79`). That covers launches with
and without runtime state. The server writes that line only after the
coordinator has confirmed its release, and it holds stdin's only writer. So the
payload starts only when both holders have authorised it. If either dies before
release, the payload stays out. If only the coordinator dies, `--block-fd`
opens, but the gate shell still waits on the server, which never writes the
line. The synchronous host probe's identity path does the same.

**Why stdin and not the fd 4 gate.** The fd 4 gate needs bubblewrap to run
without `--block-fd` and a descriptor that survives into the sandbox. The
helper protocol is a published contract: it requires `--block-fd`, and the
helper closes every other descriptor before it execs bubblewrap. Changing that
would break every installed helper. The protocol never constrains the command
after `--`, so a stdin gate there needs no helper change. This is the original
runtime-state gate (step 2 above), and it reads a byte at a time, so payload
stdin after the gate line is unchanged.

**Proof.** `packages/ui-sdk/tests/identity-gate-holder-crash.test.ts` runs the
real launcher and coordinator in a separate server process, against
`tests/fixtures/identity-gate-helper.py`. That fixture implements the launch,
mount, signal and cleanup operations as the server's own UID. It SIGKILLs the
coordinator during setup, after setup before release (synchronous,
asynchronous and without runtime state), and together with the server. It also
kills the server alone. Each case waits until every process of the launch is
dead and requires no payload marker. The released control starts the payload
once, with descriptors 0-2 only and stdin byte-identical. The stand-in drops no
identity: the cross-UID behaviour stays proven by the disposable-container
qualification.
6 changes: 3 additions & 3 deletions docs/decisions/worker-writable-areas.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ on the transcript persist path and is not part of this record.

**One resolution, two consumers.** `prepareWorkerSandbox` resolves the
areas and per-turn XDG layout once per worker
(`export function prepareWorkerSandbox`, `packages/ui-sdk/src/server/worker-launcher.ts:910-951`).
(`export function prepareWorkerSandbox`, `packages/ui-sdk/src/server/worker-launcher.ts:926-967`).
The backend passes the result both to the launcher, which turns it into
bubblewrap arguments, and to `workerSandboxNote`, which renders the agent's
note (`export function workerSandboxNote`, `packages/ui-sdk/src/server/worker-sandbox.ts:592-657`).
The launcher re-checks the resolved layout against the actual launch: the
same brain and envelope, each writable area still a real directory at its
own path in the brain. The backend selects runtime HOME separately.
A mismatch refuses the launch instead of binding something the note does not
describe (`function sandboxMounts`, `packages/ui-sdk/src/server/worker-launcher.ts:832-862`).
describe (`function sandboxMounts`, `packages/ui-sdk/src/server/worker-launcher.ts:848-878`).
A launch without a resolved layout keeps the 0.41 view: only the per-turn
scratch is writable.

Expand Down Expand Up @@ -153,7 +153,7 @@ through the roadblock path. This is a worker write boundary, not an immutable
view: host-side changes to that directory remain visible. A backend may select a different runtime HOME
as described below; it does not make the host home writable. `prepareWorkerSandbox` resolves this same XDG mode on every eligible
host (`export function prepareWorkerSandbox`,
`packages/ui-sdk/src/server/worker-launcher.ts:910-951`). Host-backed overlay
`packages/ui-sdk/src/server/worker-launcher.ts:926-967`). Host-backed overlay
uppers cannot live on the worker's private tmpfs; keeping them would leave
an unbounded write area. Tools reading XDG config see the per-turn directory,
while direct reads of real HOME retain the read-only host view.
Expand Down
12 changes: 11 additions & 1 deletion docs/hosting/agent-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ fixed worker-UID raw reading and owned cleanup. SCM_RIGHTS transfers only explic
descriptors; unexpected handles, substituted roots, wrong filesystem/size,
malformed status, stale identities and unrelated targets refuse.

The coordinator's gate pipe is not the payload's only gate. bubblewrap starts
its sandbox when that pipe reads end-of-file, which happens when the
coordinator dies. So every separate-identity payload also runs behind the
trusted stdin gate: an absolute `/bin/sh` that needs one complete `go` line
before it becomes the command. The server writes that line only after the
coordinator confirms the release. A coordinator or server that dies before
release never starts the payload. Helpers see no protocol change, because the
gate is part of the command after `--`
([the ruling](../decisions/policy-write-boundary.md#the-identity-helpers-start-gate-fails-closed-too--2026-11-03)).

Before releasing bubblewrap's private start gate, the coordinator retains
verified runtime-state and turn-temp directory handles. Their tmpfs
superblocks must represent both outside UIDs: creating them in a user
Expand Down Expand Up @@ -91,7 +101,7 @@ owner-only `0700`/`0600` modes. Before mounting the proxy, the launcher checks
canonical paths, server ownership, the expected helper group, exact modes and
socket type. Missing entries, symlinks and widened permissions refuse before
the payload starts (`if (input.egress)`,
`packages/ui-sdk/src/server/worker-launcher.ts:561-576`). This does not select
`packages/ui-sdk/src/server/worker-launcher.ts:577-592`). This does not select
the ordinary inference route or enable the proxy by default.

Native output stages use the existing manager's active stage identity. The
Expand Down
Loading
Loading