Repository navigation
fix(sandbox): keep runnerd's token out of its execs' reach - #5086
tale-code-bot wants to merge 3 commits into
Conversation
Every exec runs at runnerd's own uid, and runnerd held the spawner's token in its environment, which any process of that uid could read from /proc/<pid>/environ, then call runnerd as the spawner and sign a staged-files manifest. - The entrypoint moves TALE_RUNNERD_TOKEN off the environment onto fd 9, a here-document pipe, and runs itself again before anything starts (before the Incus wrapper too); the jobs it leaves in the background close fd 9. The root Docker supervisor reads it and hands it to runnerd on fd 3. - runnerd makes itself non-dumpable through a Node-API addon built in the image (daemon/nondumpable/tale-nondumpable.c), then reads the descriptor to its end and closes it (runnerd-token.ts). A descriptor it cannot read, or a flag it cannot clear, stops it. Node runs runnerd with --disable-sigusr1, so its uid cannot open the inspector in it. - runnerd no longer loads the agent-writable V8 compile cache, where planted code would run as runnerd: the entrypoint names it TALE_RUNNER_NODE_COMPILE_CACHE and execBaseEnv hands it to the execs as NODE_COMPILE_CACHE. - The staged-files manifest is signed under a key derived from the token (HKDF-SHA256), never the token itself; its format moves to v2, so a v1 manifest is not read and its inputs are fetched again once.
Only lazy-docker.ts uses it, and Knip refuses an export nothing imports.
tale-review-bot
left a comment
There was a problem hiding this comment.
Changes requested at 091928fc5f1e295320300f9541986f94ddc246dc.
1. The required CI ready (Checks) check fails because of this change.
- Where:
Unit (platform 1/2), Checks run 40920788836, job 123613356158, finished 17:29:31Z. - What fails:
services/platform/tests/guards/integration-scope.guard.test.ts:285, "covers every module the suite runs and every file it reads", which reportsservices/sandbox-runtime/daemon/src/runnerd-token.ts. - Why:
file-ops.tsnow importsrunnerd-token.ts. The integration harness reachesfile-ops.tsthroughbackend/domains/tasks/agent-review-files.integration.ts, so the new module is part of what the suite runs. It is missing from theintegration:list. - Fix: add
- 'services/sandbox-runtime/daemon/src/runnerd-token.ts'to.github/ci-scope.yml, next tofile-ops.ts,protocol.tsandstaged-manifest.ts(lines 11–13). The guard's message nameschecks.yml, but the list it means is theintegrationfilter inci-scope.yml, whichchecks.yml's Integration scope job reads. - Checked locally: the guard fails at this head (1 failed, 5 passed). With that one line added it passes 6/6. The edit was reverted; I push nothing.
- The task's closing comment calls this job "still running". It failed after that check.
What I checked, and what holds:
- I read the token path end to end: entrypoint fd-9 handover →
lazy-docker.tsfd-3 handover →runnerd-token.ts→main.tsandfile-ops.ts. Also the addon, the HKDF manifest key and v2 format, the compile-cache move, and--disable-sigusr1on every launch. I found no flaw in the design.- The re-exec runs before any code with side effects: above it are only
set -e, assignments and function definitions. - The background jobs close fd 9.
- runnerd clears its dumpable flag before it reads, and fails closed.
- The re-exec runs before any code with side effects: above it are only
- Daemon tests at this head, run locally with credentials unset:
bun teston runnerd-token, entrypoint-dispatch, staged-manifest, lazy-docker, exec-manager.env and registry-cache-files gives 85 pass, 1 skip, 0 fail. The skip is the addon build: this worker has no C compiler.
Not proven yet. Not blocking by itself, but please keep it stated in the PR:
- The gcc image build with the addon, and the in-container probe in
container-sandbox-runtime-test.ts, have not run anywhere. They run only in the merge queue's Build. - No Incus boot is exercised: "Sandbox on Incus" (run 40920788603, job 123613121880) stops at "Install Incus" because Zabbly dropped the pinned build. It fails the same way on
fix/stall-watch-monotonic-clock(run 40917404622), so it is not this PR. It is also not a required check.
Push the fix as a new commit. I will review the new head once its required checks are green.
file-ops.ts now imports runnerd-token.ts, so the native review-file integration proof runs it and the platform's tests, lint and typecheck read it. The integration-scope guard refused the change while the module was missing from the `integration` filter in ci-scope.yml. It is also listed among the platform's turbo inputs beside protocol.ts, and in the turbo-inputs guard's outside reads and static imports, so an edit to it alone no longer replays a cached platform verdict.
|
Replying to review 5702481855, which was made at 1. The required Fixed in
Checked on the worker, with credentials unset:
Noticed but not changed here: 2. The task's closing comment called Unit (platform 1/2) "still running". That's right. My one check at 3. What isn't proven yet. The PR body now has a "Not proven yet" section:
|
tale-review-bot
left a comment
There was a problem hiding this comment.
Approved at 000bcd6022560761079523951997082deee812da.
What changed since my request at 091928fc5 (review 5702481855): one commit, 000bcd602. No force-push; 091928fc5 is an ancestor.
.github/ci-scope.ymlnow listsservices/sandbox-runtime/daemon/src/runnerd-token.tsinintegration:. That is the fix I asked for.- The same file is added to
services/platform/turbo.json's task inputs and to the turbo-inputs guard'sOUTSIDE_READS/STATIC_IMPORTS, so its edits invalidate cached verdicts. That sweep is right per.agents/repo.md.
Checked at this head, locally with credentials unset:
integration-scopeandturbo-inputsguards: 81 passed.- Daemon
bun teston runnerd-token, entrypoint-dispatch, staged-manifest, lazy-docker and exec-manager.env: 61 pass, 1 skip (the addon build; no C compiler here), 0 fail. - The rest of the change is unchanged from
091928fc5, where I read the whole token path and found no design flaw.- Covered: entrypoint fd 9, lazy-docker fd 3,
runnerd-token.ts, the addon, the HKDF manifest key and v2 format, the compile-cache move, and--disable-sigusr1. - This run I also read the in-container probe in
container-sandbox-runtime-test.ts, whichbuild.ymlruns, plus the docs and manual references.
- Covered: entrypoint fd 9, lazy-docker fd 3,
CI on this head: all seven required CI ready checks pass. Runs: Checks 40926614654, SAST 40926614688, Commitlint 40926614617, Build 40926614644, CLI 40926614629, Security 40926614702, E2E 40926614744.
Not run, still to prove:
- The gcc image build and the in-container token probe. Only the merge queue's Build runs them, so nothing lands unless they pass.
- The Incus boot path. "Sandbox on Incus" (run 40926614520, not a required check) still fails at "Install Incus" on the dropped Zabbly pin, which is unrelated to this PR.
|
Not landing yet. The green
|
|
Reopened so the checks run again. The 20:13–20:15 UTC reopen started its runs from a test merge into |
|
Landed on |
Development task TALE-134 (Tale board, project Development). The plan and its addendum are on the task.
The defect
The spawner authenticates to runnerd with
TALE_RUNNERD_TOKEN, and the same token keyed the HMAC of the staged-files manifest. runnerd held the token in its initial environment, and every exec runs at runnerd's own uid. So any exec could read/proc/<runnerd>/environand then:Unsetting the variable inside runnerd would not help, because
/procshows the environment a process was started with.The fix
All of it is in
services/sandbox-runtime.daemondispatch movesTALE_RUNNERD_TOKENonto fd 9, a here-document pipe. It then runsentrypoint.shagain withTALE_RUNNERD_TOKEN_FD=9, before anything else runs, including the IncusTALE_END_WITH_RUNNERDwrapper, whose shell lives as long as runnerd.lazy-docker.ts) reads fd 9 before it spawns anything. It hands the token to runnerd on fd 3 and keeps it out ofrunnerEnvironment.daemon/nondumpable/tale-nondumpable.cis a small Node-API addon, built in the existingexec-shim-buildstage against the pinned Node 24.21.0 headers. It callsprctl(PR_SET_DUMPABLE, 0).runnerd-token.tsclears the flag first, then reads the descriptor to its end, drops the last line break and closes it, beforemain.tsconstructs anything that could spawn.node --disable-sigusr1. Otherwise a same-uidkill -USR1opens the inspector, which runs code inside runnerd.token=descriptor; dumpable=false./agent/.runtime/home/.cache/node-compile-cache, which the exec uid can write. Node and V8 check only checksums and lengths, which an attacker can recompute. So a planted entry would run as runnerd at its next start (routine after an idle stop), with the token in reach.NODE_COMPILE_CACHEon every path. The location travels asTALE_RUNNER_NODE_COMPILE_CACHE, the variable the DinD path already used, andexecBaseEnvhands it to each exec asNODE_COMPILE_CACHE.tale-staged-sources-v2. A v1 manifest, which anyone who read the token before this fix could have forged, is not read, so its inputs are fetched once more.I checked the paths beyond the three the issue names:
httpGet, the egress sidecar has noenvFrom, and the pod doesn't share its process namespace.docker execcalls into a session run as root.-I.Tests
The new tests:
entrypoint-dispatch.test.tsruns the real script undersh. With a token, tini (and so runnerd) starts with no token in its/proc/$$/environandTALE_RUNNERD_TOKEN_FD=9. fd 9 is a pipe, the first read returns the token exactly (shell metacharacters included) and a second read returns nothing. This holds on three paths:setprivpath;TALE_END_WITH_RUNNERD=1, where the waiting shell's environ is checked too.The same file also checks:
NODE_COMPILE_CACHEand gets the exec location;runnerd-token.test.tscovers:runnerd-token.test.tsalso has a real addon probe. Where a C compiler and Node's headers are at hand, it builds the addon, runs the bundled module under Node, and checks that the process'senviron,memandfd/are open to its uid before and closed after. It skips without a compiler, likeexec-shim.test.ts, and skips as root.lazy-docker.test.tsand its Node fixture cover the newrunnerEnvironment(token never in it, fd 3 named, no compile cache), plus a realhandOverTokento a Node child that reads fd 3 withreadFileSync, the same call runnerd makes.staged-manifest.test.ts: a manifest signed with the raw token is refused, in either format, and the derived key verifies.exec-manager.env.test.ts:TALE_RUNNERD_TOKEN_FDis dropped, and the compile cache is mapped.The image probe is in
container-sandbox-runtime-test.ts. It boots the built image with a random token at--user 10001, then checks:token=descriptor; dumpable=false;environ,memandfd/are denied;grep -F -l <token> /proc/[0-9]*/environfinds nothing;/healthzanswers 401 without the token and 200 with it.The probes empty the variable
docker execwould hand them, and never take the token through their environment.What ran on the worker, at
c339908a1:entrypoint.sh(8 fail). I also mutated the fix: moving the token block after the wrapper fails the wrapper test, and dropping9<&-from the purge job fails the two fd-9 tests.bun run --filter @tale/sandbox-runtime-daemon test: 656 pass, 11 skip, 4 fail. All four also fail identically on base9be5cadacand are caused by the worker:main.test.ts"health describes process activity without viewer state": the worker's cgroup and egress settings addmemoryanddependenciesto/healthz.exec-rotation.test.ts: no C compiler.bun run --filter @tale/sandbox-runtime-daemon typecheck: passes.bun run --filter @tale/sandbox-runtime-daemon lint: passes.bunx oxlint --type-awareon the changed integration test: passes.bun run lint:manualandbun run lint:links: pass.node_api.hunder Bun's embedded TinyCC. That is only a compile check; gcc with-Wall -Wextra -Werrorin the image build stays the final word.What did not run on the worker:
ccand Node's headers exist. The gcc build runs in the image Build.bun run lint:sast: opengrep isn't cached on the worker, and fetching it means downloading a release binary from outside the lockfile. CI's SAST job runs it.@tale/platformtypecheck, which covers the integration test: it needs a 6 GiB heap, as in CI, and the host refused the heavy-phase lease under load every time it was asked. CI's Type check passed atc339908a1(job 123608861189).CI
At
c339908a1, these passed: Type check, Lint, Format, Lint commits, Trivy and Bun audit. Three checks failed:RUNNER_TOKEN_FD).091928fc5makes it module-private. In CI at091928fc5, Knip, Type check, Lint, Format, Unit (workspaces) and Unit (platform 2/2) pass.091928fc5(job 123613356158) fails the integration-scope guard:file-ops.tsnow importsrunnerd-token.ts, which the native review-file integration proof therefore runs, and the module was missing from theintegrationfilter.000bcd602adds it to.github/ci-scope.yml. It also lists it among the platform's turbo inputs (lint,test,typecheck, besideprotocol.ts) and in the turbo-inputs guard, whose contract is that every outside module the platform's program imports is hashed. On the worker:runnerd-token.ts) with only the scope line removed;runnerd-token.tschecks;ci-scope.ymlpass.Zabbly's stable channel no longer has incus 1:7.5.1-ubuntu26.04-202610160649 … pin it in lab.sh(services/sandbox/e2e/incus/lab.sh). The same error failsfix/stall-watch-monotonic-clock(run 40917404622), so it isn't this change, and it isn't a required check. Updating the pin is a change of its own.Not proven yet
-Wall -Wextra -Werror) and the in-container probe incontainer-sandbox-runtime-test.tshave run nowhere yet. They run only in the merge queue's Build.TALE_END_WITH_RUNNERDand standby paths are proved only by the entrypoint tests, not on a real instance.Not in this change
Closes #4725