Repository navigation
docs(spec,adr): per-workload sandboxes and storage (/workloads phase 2) - #553
Conversation
Design for rossoctl#476: a separate moca-provisioner creates each workload's sandboxes, the relay sets workload and owner labels from a signed binding token rather than from Hello, and workload sandboxes mount the workload's Context PVC (read-only, or a seeded writable tree). ADR-0043 records the provisioner decision. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Jeremy Cohn <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Design review of the phase 2 spec and ADR-0043. I checked its §1.1 facts against main cb7b5a9: Hello labels are stored as sent (relay.ts:188), dashed ids fall through to the shared token, selection filters on tier only, ReadWriteOnce is hard-coded (context-service.ts:160), the field allow-lists and statuses match workloads.ts, and automountServiceAccountToken: false is set on supervisor, relay and sandbox. They all hold. The core choices hold up: a separate provisioner, workload and owner labels taken from a signed token rather than from Hello, removing those labels from shared-pool Hellos, provisioning at activation, and mounting only moca-workspace/ on writable workloads. §9 is candid about what is still not a boundary.
Nothing blocks. Three suggestions for the spec before PR 1 and PR 3 are built: (1) the .moca-seeded re-seed path can be steered to write into .context-service/; (2) a leaked attach token never expires, has no bound on the ordinal and has no kid; (3) the provisioner should derive wl from the verified owner. Three nits follow.
Author: moonlight16 (MEMBER — maintainer)
Areas reviewed: Docs (spec, ADR, indexes), checked against main cb7b5a9
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: passing (all 14 checks)
| exactly what export streams. A writable mount of the revision directory, or of the claim root, | ||
| would let model code change a revision behind its id or rewrite revision history. So "writes stop | ||
| being copies" holds per run, not per workload: an init container (MOCA's image, not model code) | ||
| copies the frozen revision into `moca-workspace/` once, when that directory has no |
There was a problem hiding this comment.
suggestion: the re-seed path lets model code write into .context-service/. The .moca-seeded marker lives in the tree that model code can write. A run can delete it and plant symlinks in moca-workspace/ (for example a -> ../.context-service/materialized/<rev>/a). On the next pod restart the init container sees no marker and copies the revision into moca-workspace/. If it has the claim root mounted read-write (it has to, to reach both directories), a cp -r follows those destination symlinks and overwrites revision files behind their digest. That breaks the invariant §5.3 opens with. Suggested fixes: have the init container mount the revision read-only through its own subPath and moca-workspace as a separate mount, so .context-service/ is never writable in that container. Keep the seeded flag outside the model-writable tree (on the workload record or a pod annotation, not a file). Refuse to seed into a non-empty directory, or seed into a temp dir and rename it. §11 should get a test for this.
There was a problem hiding this comment.
Agreed, thanks. Fixed in 7ee44d7 (§5.3): the init container mounts the revision read-only through its own subPath and moca-workspace separately, the seeded flag is a pod annotation (moca.dev/seed-revision) rather than a file, and the seed refuses a non-empty directory, copies into a temp dir without following symlinks, and renames into place. §11 has a test for the planted-symlink case.
|
|
||
| ### 3.2 What the relay does on `Hello` | ||
|
|
||
| - **Token is an attach token.** The relay requires `sandboxId` to match `^<wl>-[0-9]+$`, then |
There was a problem hiding this comment.
suggestion: say how far a leaked attach token reaches. A workload sandbox can read its own SANDBOX_TOKEN. commandEnv strips it from the command's env, but the worker process runs as the same UID 1001 in the same container, so /proc/<worker pid>/environ is readable. The token has no exp, no ordinal bound and no kid, and ^<wl>-[0-9]+$ accepts any ordinal. So one prompt injection could register <wl>-7, or take <wl>-0 during a pod restart, from any host that can reach the relay's attach endpoint (OCP exposes it through a Route for P4 hosts). From then on it receives the workload's later runs until the workload is deleted, and selection picks it like a real pod. This crosses no user boundary, but it does turn a one-off injection into persistent capture of that workload. Consider: limit the ordinal to < count (carry n or count in the token, or have the relay check the record), add exp plus a rotation story (or a projected, pod-bound credential), and a kid so the provisioner's key can rotate. Then record what is left in §9.
There was a problem hiding this comment.
Agreed. Done in 7ee44d7 (§3.1, §3.2, §9): the token now carries n (the sandbox count) and the relay accepts only ordinals below it; it has a kid and a required exp (MOCA_ATTACH_TOKEN_TTL_S, default one day), re-minted by the provisioner into a mounted Secret file the worker re-reads on each dial; the relay closes attach streams at exp. §3.1 notes the same-UID /proc read, and §9 records the residual same-workload capture, bounded by one TTL.
| **Caller authentication.** The worker presents a service token (`MOCA_PROVISIONER_TOKEN`, one | ||
| caller credential per `/internal` endpoint, MI1 I8) **and** forwards the caller's own API token. | ||
| The provisioner verifies that token with `SH_SESSION_TOKEN_PUBLIC_KEYS`, as the supervisor already | ||
| does, and takes the owner from it. A compromised worker can then provision only for users whose |
There was a problem hiding this comment.
suggestion: the provisioner should derive wl itself, not trust it from the path. wl = w- + sha256(owner\0name\0generation) (workloads.ts:95). If the worker sends {name, gen} and the provisioner recomputes wl from the verified token's owner, then a compromised worker holding Alice's token can only mint bindings for Alice's own workloads. As written, PUT /internal/v1/workloads/{wl} takes wl from the caller, so it could bind Bob's workload key to Alice's owner scope. That would create pods labelled with Bob's moca.dev/workload that Bob's runs then select. §9 already concedes a compromised worker routes anywhere, so this is not a new hole. But it would make the claim in this paragraph ("only for users whose tokens it currently holds") true. Selection (§3.3) could also require moca.dev/owner to match, as a second check.
There was a problem hiding this comment.
Agreed. Done in 7ee44d7 (§4.1, §3.3): the internal API is now /internal/v1/workloads/{name}/{generation}, and the provisioner derives wl from the verified token's owner. Selection also requires moca.dev/owner to match the run's owner.
|
|
||
| A loop in the provisioner, every `MOCA_PROVISIONER_RECONCILE_S` (default 300). It lists the | ||
| workload StatefulSets, Services and Secrets in `moca-sandbox` and reads each one's record key from | ||
| its annotation, using a read-only Redis connection. It deletes the objects when the record is |
There was a problem hiding this comment.
nit: "a read-only Redis connection" conflicts with §3.1 (L119-120), which says the deployment has no Redis ACL users, and the base Redis uses only requirepass. Either this needs an ACL user (say so, and list it in PR 2 or PR 4), or drop "read-only". The reconciler also trusts records that workers can write. A forged or deleted record lets a compromised worker get the reconciler to delete another workload's objects (DoS only). That belongs in §9's "not a boundary" list.
There was a problem hiding this comment.
Done in 7ee44d7: dropped "read-only" (no ACL users exist), and §9 now notes that a compromised worker can get the reconciler to delete another workload's objects (DoS only).
| ## 2. Design overview | ||
|
|
||
| ``` | ||
| [Flow diagram placeholder: create, activate, provision, register, run and delete, with the |
There was a problem hiding this comment.
nit: the flow diagram is still a placeholder ("An SVG replaces this block"). Either add it before merge or note that it will follow.
There was a problem hiding this comment.
Noted in 7ee44d7: the SVG follows in a separate docs change before PR 2.
| ``` | ||
|
|
||
| - `sandboxes` selects phase 2. `count` is 1 to `MOCA_WORKLOAD_MAX_SANDBOXES`; `tier` defaults to | ||
| the deployment's default tier. |
There was a problem hiding this comment.
nit: "tier defaults to the deployment's default tier", but only container is accepted. On a deployment whose default tier is microvm (P4), a create that leaves out tier would get 400 sandbox_tier_unavailable. Defaulting to container would be clearer, at least until a host-side provisioner exists.
There was a problem hiding this comment.
Done in 7ee44d7: tier defaults to container until a host-side provisioner exists.
- Seed writable workspaces with the revision mounted read-only, the seeded flag as a pod annotation, and a temp-dir rename, so the seed cannot write into .context-service/. - Bound the attach token: sandbox count n with ordinals < n, kid, required exp with re-minting, and closing attach streams at exp; document same-workload capture in section 9. - The provisioner derives the workload key from the verified owner; selection also matches moca.dev/owner. - Drop the read-only Redis claim and note the reconciler's DoS limit; note the diagram follows; tier defaults to container. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Jeremy Cohn <[email protected]>
Design for #476 (phase 2: per-workload sandboxes and storage), which also takes the long-term threads from #517 (seed sandbox files before a leaf runs). Phase 1 (#482, #494, #534 and follow-ups) runs every workload on MOCA's shared sandboxes. Phase 2 gives each workload its own sandboxes and mounts its Context's PVC, so users are isolated from each other.
docs/specs/2026-10-16-workload-sandboxes-design.mdmoca-provisioneris the only MOCA component that creates workload sandboxes.Key decisions
Hello) states its own labels, and today the relay records them as sent. Phase 2 labels decide whose sandbox it is, so the relay instead takes the workload and owner from a token the provisioner signs, and ignores any such labels a sandbox claims itself. A workload's runs go only to its own sandboxes.Implementation is four PRs (§8): relay trusted labels → provisioner and RBAC → PVC mount → Alice/Bob multi-user Kind demo. Open questions are in §10, including the four raised on #476.
🤖 Generated with Claude Code