Repository navigation
feat(microvm): authenticated mocactl turns on the P4 tier (#369) - #409
Conversation
…subjects (rossoctl#369) With the control plane on deploy/vm, SH_REQUIRE_AUTH=true closes the unauthenticated /turn the P4 check used, so checking the P4 tier meant turning auth off. --auth keeps it on: it stands in for mocactl login by minting an api token per subject with the control plane's own key (the deploy/compose/smoke.sh pattern), stores a bearer inference credential aimed at the loopback mock model, and runs every turn through the real mocactl run. Session B belongs to a second subject, which must get a 404 on session A. The token goes from node straight into 0600 files, never onto an argv. The test's fake supervisor turn is shared by the curl and mocactl mocks. The control-plane half (mint, PUT 204, session create, cross-subject 404) was also run against a real local control plane. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ossoctl#369) P4-ON-P6.md gains p4-turn-smoke --auth (keep SH_REQUIRE_AUTH=true, two minted subjects, the mock credential, cleanup of the tokens) and the rig results with the control plane installed: 34/34 checks through mocactl run, workspace_key = the control plane's session id, a second subject 404s on the first's session, and the installers' re-runs leave the tier attached. What stays unverified is the real device-flow login and a real model through a stored credential. Limits gains one line: a setup-vm.sh re-run recreates sh-redis with no volume, so the control plane's session and ownership index is lost. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…soctl#409) deploy-scripts runs make test-deploy with no pnpm install, so the --auth block could not load the control plane's signer (Cannot find package 'tsx'). The block now skips, by name, when tsx is absent, and the check job, which has the dependencies, runs the suite with P4_SMOKE_REQUIRE_AUTH=1, where a skip is a failure. The block keeps using the real signer rather than a copy of the token format. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
|
manual verification has been completed and work as expected |
huang195
left a comment
There was a problem hiding this comment.
Summary
Checked against source and correct: the mint input matches token.ts, the key path matches the unit's LoadCredential, auth.json matches mocactl's CachedAuth (with expiresAt in seconds), the session <id> stderr line matches headless.ts, and PUT /v1/credentials returns 204. The suite passes locally with P4_SMOKE_REQUIRE_AUTH=1.
One blocker. The cross-subject 404 has no positive control, so it can pass without testing isolation, and nothing checks the PR's claim that session B belongs to the second subject. Two test checks cannot fail for the regression they name (repros inline). There are also two doc fixes and a nit.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell, CI/GitHub Actions, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 3 commits, all signed-off: yes
CI status: passing
| check "b1 did not see A's repo" "$(has b1 continuity-missing)" "yes" | ||
| if [ "$AUTH" = 1 ]; then | ||
| # Session B is a second subject's, not a second session of one: B's owner cannot even read A's. | ||
| check "subject b cannot read subject a's session (404)" "$(curl -sS --max-time 10 -o /dev/null \ |
There was a problem hiding this comment.
must-fix: this 404 also comes back when isolation was never tested. The control plane returns 404 for three different things:
- another subject's session (
assertOwner); - an id it has never seen;
- an empty
$A, because/v1/sessions/matches no route (packages/control-plane/src/server.ts:79).
So this check cannot tell "b cannot read A" apart from "A is not a control-plane session" or "the route moved". It also says nothing about the claim that session B is subject b's: b's token gets the same 404 on A no matter who ran b1.
Suggest positive controls next to it, the same rule absent() applies above:
check "subject b reads its own session B (200)" "$(curl -sS --max-time 10 -o /dev/null \
-w '%{http_code}' -H @"$OUT/xdg-b/api.hdr" "$CP/v1/sessions/$B" 2>/dev/null)" "200"
check "subject a reads its own session A (200)" "$(curl -sS --max-time 10 -o /dev/null \
-w '%{http_code}' -H @"$OUT/xdg-a/api.hdr" "$CP/v1/sessions/$A" 2>/dev/null)" "200"With those, the 404 can only mean b is not A's owner.
There was a problem hiding this comment.
Fixed in cf094b5. Two positive controls now sit next to the 404: subject a reads A (200), subject b reads B (200), then subject b on A must be 404. An empty id is reported as no-id rather than sent to /v1/sessions/. Against a real local control plane: 200 / 200 / 404.
| rc=$? | ||
| check "exit 0" "$rc" "0" | ||
| [ "$rc" = 0 ] || sed -n '/FAIL/p' "$TMP/run3.log" | ||
| check "session B was subject b's" "$(grep -c 'ok: subject b cannot read subject a' "$TMP/out3/SUMMARY")" "1" |
There was a problem hiding this comment.
This check cannot fail. The curl mock returns 404 to every GET /v1/sessions/* (line 49). The mocactl mock decodes the subject but never records it, so nothing in the test knows who owns which session.
Repro: hard-wire turn_mocactl to local dir="$OUT/xdg-a", so every turn runs as subject a. The whole suite still passes.
Suggest two mock changes:
- After
fake-turn, the mocactl mock writes the decodedsubto$STATE/owner-<sid>. - The curl mock reads the bearer token from the
-H @fileit is given, decodes itssub, and returns 200 to the session's owner and 404 to anyone else.
Then the positive controls suggested on the driver have something real to check, and the mutation above fails.
There was a problem hiding this comment.
Fixed in cf094b5, as you suggested. The mocactl mock writes $STATE/owner-<sid> from the decoded sub, and the curl mock decodes the bearer from the -H @file and serves GET /v1/sessions/<id> to its owner only. Your repro (every turn as subject a) is now a mutant inside the suite and has to fail on "subject b reads its own session B". The same mocks also catch bs
| check "session B was subject b's" "$(grep -c 'ok: subject b cannot read subject a' "$TMP/out3/SUMMARY")" "1" | ||
| check "each subject stored the mock credential" "$(grep -c '^credential-put .*/v1/credentials/p4-smoke-mock$' "$MOCK_LOG")" "2" | ||
| check "every turn went through mocactl" "$(grep -c '^mocactl run ' "$MOCK_LOG")" "5" | ||
| check "no api token on any argv" "$(grep -c 'eyJ' "$MOCK_LOG")" "0" |
There was a problem hiding this comment.
This only checks mocactl's argv. The curl mock throws away every -H value (line 37) and logs only credential-put $url, so a token on curl's command line never reaches MOCK_LOG.
Repro: change store_credential to -H "$(cat "$OUT/xdg-$1/api.hdr")". This check still passes.
Suggest echo "curl $*" >>"$MOCK_LOG" at the top of the curl mock. The -H @file form logs only the path, so the current driver stays clean.
There was a problem hiding this comment.
Fixed in cf094b5. The curl mock logs curl $* first. Your -H "$(cat …)" repro is a mutant in the suite now, and it must show eyJ in the log.
| | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | Installing the control plane leaves the microVM tier attached | `setup-microvm.sh` re-run: `moca_microvm_0 is attached to the relay`, `nothing to change`. The worker reconnected by itself within seconds of each relay restart | | ||
| | The unauthenticated `/turn` is closed | `POST /turn` without a token: 401 | | ||
| | `mocactl run` as a logged-in user runs multi-tool turns in microVMs | `p4-turn-smoke.sh --auth --failure-paths`: 34/34 checks, `SH_REQUIRE_AUTH=true` throughout. Every turn went through `mocactl run` with a minted api token (the stand-in for `mocactl login`) | |
There was a problem hiding this comment.
32 checks, not 34. p4-turn-smoke.sh has not changed since fd6fed2, and on --auth --failure-paths it makes 32 check calls: 2 preconditions, 5 control-plane, 6 for a1, 3 for a2, 5 for b1, 5 journal/workspace and 6 failure-path. When I ran this suite locally, out3/SUMMARY had exactly 32 ok: lines. The PR body says 34/34 as well. This is the evidence row, so either correct the number or say what else ran on the rig.
There was a problem hiding this comment.
Right, 32. I miscounted. Fixed in the runbook and the PR body. With the two positive controls added in this round, a run now makes 34 checks; the rig row still says 32/32, which is what that run made.
| sudo systemctl stop p4-mock-anthropic | ||
| ``` | ||
|
|
||
| After an `--auth` run, delete each subject's mock credential while its token is still valid, then the |
There was a problem hiding this comment.
This cleanup leaves the run's sessions behind. The PR body says the subject records and this run's workspaces were removed, but these steps remove only the credentials and the run's directory. Sessions A and B stay in the control plane's index.
DELETE /v1/sessions/{id} needs the same still-valid token, so it belongs in this loop, before the rm -rf. The ids are already in $OUT/session-a and session-b:
for s in a b; do
h=@/tmp/p4-smoke/xdg-$s/api.hdr id="$(sudo cat /tmp/p4-smoke/session-$s)"
[ -n "$id" ] && sudo curl -s -X DELETE -H "$h" "http://127.0.0.1:8090/v1/sessions/$id"
sudo curl -s -X DELETE -H "$h" http://127.0.0.1:8090/v1/credentials/p4-smoke-mock
done
sudo rm -rf /tmp/p4-smokeThe workspaces under /srv/workspaces and the subject records you removed on the rig each need a line too, or a note that they stay.
There was a problem hiding this comment.
Fixed in cf094b5. The cleanup now deletes each subject's session (by $O/session-<s>), its workspace, its credential and its empty subject record (sha256(subject)[0:16].json, the file store's name), then the directory. Each delete prints its code, and the text says the tokens expire an hour after the run and what a 202 means. Ran against a real local control plane: all 204.
| --failure-paths) FAILURE_PATHS=1; shift ;; | ||
| *) echo "usage: $0 [--supervisor URL] [--out DIR] [--failure-paths]" >&2; exit 2 ;; | ||
| --auth) AUTH=1; shift ;; | ||
| --control-plane) CP="$2"; shift 2 ;; |
There was a problem hiding this comment.
nit: a trailing slash here (--control-plane http://127.0.0.1:8090/) makes every turn fail with "not logged in". mocactl strips trailing slashes from --control-plane-url (normalizeUrl), and loadAuth then requires auth.controlPlaneUrl to equal it exactly (packages/mocactl/src/config.ts:148). But auth.json stores $CP as given. CP="${CP%/}" after the loop fixes it, and also stops curl building //v1/... URLs.
There was a problem hiding this comment.
Fixed in cf094b5: --control-plane and --supervisor lose trailing slashes. The mocactl mock now applies loadAuth's exact-match rule, and the main --auth run passes http://127.0.0.1:8090/. With the strip removed, every turn of that run fails with "not logged in", and the suite fails 3 checks.
…ctl#369) The owner ran the real GitHub device-flow login from a laptop over the SSH tunnel, with SH_REQUIRE_AUTH=true and no mock model. The rig's journal for that session shows two turns, three Execs in three distinct microVMs under one control-plane workspace_key, and its own workspace. What stays unverified is a second real GitHub account (rossoctl#367). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ut, bounded turns (rossoctl#409 review) Review round 1: - The cross-subject 404 now stands next to two positive controls: each subject reads its own session (200). The control plane also answers 404 for an unknown or empty id, so the 404 alone proved nothing. - The test's mocks now model ownership and the call log: mocactl records who created each session, curl serves GET /v1/sessions/<id> to its owner only and logs its whole argv. Mutants for "every turn as subject a" and "the token on curl's argv" are part of the suite and must fail. - --control-plane and --supervisor lose trailing slashes: mocactl's loadAuth compares auth.json's controlPlaneUrl to the normalised flag. - P4-ON-P6.md: the rig run had 32 checks, not 34; the cleanup also deletes the run's sessions, workspaces and empty subject records. Self-review: - `mocactl run` is bounded by timeout(1) (SMOKE_TURN_TIMEOUT, 300s, the curl bound of the other path), with --foreground so Ctrl-C reaches it; a hang is reported as timed-out. - The default --out is a fresh mktemp directory; with --auth a named one must be a non-symlink directory the caller owns, and is made 0700. - The default mocactl command is an array, so a checkout path with a space works. - The test checks the credential body's shape and that each subject's session uses its own stored credential (two more mutants), and the modes of the output and config directories. - The cleanup prints each delete's code, and says the tokens expire an hour after the run and what 202 means. The ownership checks and the cleanup's deletes (all 204) were run against a real local control plane. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
huang195
left a comment
There was a problem hiding this comment.
Summary
Round 2, at cf094b5. All six round-1 comments are fixed, and I checked each:
- the two positive controls sit next to the 404;
- the mocks now model ownership and log curl's argv, and both of my repros are mutants in the suite that fail;
- the evidence row says 32/32;
- the cleanup deletes the sessions, workspaces, credentials and subject records;
- trailing slashes are stripped.
I also checked the new cleanup against source:
deleteSessionanswers 202 or 204 (handlers.ts:329);- the file store names a record
sha256(subject)[0:16].jsonunder/var/lib/moca-control-plane; - deleting the last credential leaves that record behind, empty.
The bad-consumer mutant matches the real parseCredentialBody: egress is not in CONSUMERS. 34 is the right check count for an --auth --failure-paths run. The suite passes locally with P4_SMOKE_REQUIRE_AUTH=1, and the check job's log shows the --auth block and every mutant ran there.
No blockers. There are two suggestions about the --out guard (repros inline) and a nit.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell, CI/GitHub Actions, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 5 commits, all signed-off: yes
CI status: passing
| echo "--out $OUT is a symlink or not owned by $(id -un): it would hold api tokens; pick another" >&2 | ||
| exit 2 | ||
| fi | ||
| chmod 0700 "$OUT" |
There was a problem hiding this comment.
suggestion: A named --out that already exists gets taken over. Under sudo, -O is true for every root-owned directory, so sudo p4-turn-smoke.sh --auth --out /tmp passes this guard and runs chmod 0700 /tmp. The run's files also land among whatever the directory already held, and the runbook's cleanup ends with sudo rm -rf "$O", where $O is the directory the run named.
Repro, with you standing in for root and shared for /tmp:
mkdir shared && chmod 1777 shared && touch shared/someone-elses-file
MOCA_CRED_DIR=/nonexistent MOCACTL=false bash deploy/microvm/p4-turn-smoke.sh --auth \
--out "$PWD/shared" --control-plane http://127.0.0.1:1
ls -ld shared # drwxrwxrwt before, drwx------ after; someone-elses-file is still in itSuggest: with --auth, create the directory yourself, mkdir -m 0700 -- "$OUT" (no -p), and exit 2 if that fails. That matches the runbook's "Each run writes to a fresh private directory". It also replaces both the symlink check and the owner check, because mkdir refuses an existing path, symlink or not. The non-auth path can keep mkdir -p.
There was a problem hiding this comment.
Taken in ae99572. With --auth, a named --out is now created by the run itself, mkdir -m 0700 -- without -p; it exits 2 on any existing path or symlink. That replaces both the symlink check and the owner check. The default is still a fresh mktemp -d, and without --auth a named --out can still exist (mkdir -p). The runbook says so.
| MOCA_ROOT="$DIR/../.." MOCA_CRED_DIR="$TMP/cred" MOCACTL=mocactl bash "$m" --auth --out "$TMP/out9" >"$TMP/run9.log" 2>&1 | ||
| check "the PUT is named as refused" "$(grep -c "FAIL: stored subject a's inference credential (want '204', got '400')" "$TMP/out9/SUMMARY")" "1" | ||
| else check "the bad-consumer mutation applied" no yes; fi | ||
| echo "== --auth refuses an --out that is a symlink (it would hold tokens)" |
There was a problem hiding this comment.
suggestion: Nothing tests the owner half of the guard. Repro: change the driver's line 71 to if [ -L "$OUT" ]; then, dropping || [ ! -O "$OUT" ]. The whole suite still passes with P4_SMOKE_REQUIRE_AUTH=1.
A cheap case when the suite isn't running as root: --out / exists, belongs to root, and must exit 2. If you take the suggestion on the driver's line 75, this becomes "an existing --out is refused" and covers both halves.
There was a problem hiding this comment.
Covered in ae99572: "an existing --out is refused". It uses a sticky 1777 directory with someone else's file in it, which must exit 2 with its mode untouched and nothing minted into it, and then the same through a symlink. A third case checks that a new path is created 0700 and the run passes. Loosening the guard to mkdir -p fails 3 of those checks. Writing this case also caught a bug in my own test: check "… $(basename …)" "$?" read the basename's exit status, not the driver's.
| check "the --out directory is 0700" "$(mode "$TMP/out3")" "700" | ||
| check "each subject's config directory is 0700" "$(mode "$TMP/out3/xdg-a")$(mode "$TMP/out3/xdg-b")" "700700" | ||
| check "api.hdr is 0600" "$(mode "$TMP/out3/xdg-b/api.hdr")" "600" | ||
| check "auth.json is 0600" "$(node -e 'process.stdout.write((require("fs").statSync(process.argv[1]).mode & 0o777).toString(8))' "$TMP/out3/xdg-a/mocactl/auth.json")" "600" |
There was a problem hiding this comment.
nit: this repeats the mode() helper defined four lines up. "$(mode "$TMP/out3/xdg-a/mocactl/auth.json")" does the same thing.
There was a problem hiding this comment.
Fixed in ae99572: it uses mode(). The helper now masks with 0o7777, so the sticky-directory case can check 1777.
…y it creates (rossoctl#409 review) Under sudo, the owner check passed for any root-owned directory, so `--auth --out /tmp` would chmod /tmp 0700 and mix the run's tokens into it. With --auth, a named --out is now created by the run itself, `mkdir -m 0700` without -p, so an existing path or a symlink is refused. The default stays a fresh mktemp directory. The test covers an existing sticky directory (left untouched), a symlink, and a new path (created 0700), and reuses its mode() helper. P4-ON-P6.md records the re-run on the rig at cf094b5: 34/34, the owners' 200s and the 404, the token files' modes, and the cleanup block run as written (four 204s, nothing of the run left behind). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Resolves .github/workflows/ci.yml: rossoctl#409's P4 authenticated-turn step and this PR's research-smoke step both run in the check job, after pnpm install. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Summary
This PR covers the part of #369 that #376 left: a logged-in user's
mocactl runon the P4 microVM tier, on adeploy/vmhost with the control plane (#366) andSH_REQUIRE_AUTH=true.#376 verified P4 only through the unauthenticated
/turn, which a currentdeploy/vminstall closes. Its runbook told you to turn auth off to run the check.What's in it
p4-turn-smoke.sh --authchecks the P4 tier with auth left on.mocactl loginthe waydeploy/compose/smoke.shdoes. It mints one api token per subject (p4smoke:a,p4smoke:b) with the control plane's own signing key.mock-anthropic.mjs.mocactl run.workspace_key/vm=evidence, and the failure paths.0600files under a0700directory. The token never appears on an argv or in a shell variable.mocactl runis bounded bytimeout(1)(SMOKE_TURN_TIMEOUT, 300s, the same bound as the unauthenticated path's curl), with--foregroundso Ctrl-C reaches it. A hung turn shows up astimed-out.--outis a freshmktemp -d. With--auth, a named--outmust not exist yet: the run creates it0700(mkdirwithout-p), so an existing path, such as/tmpundersudo, or a symlink is refused.CI:
deploy-scriptsruns withoutpnpm install, so there the--authblock skips and says why. Thecheckjob, which hastsx, runs the suite withP4_SMOKE_REQUIRE_AUTH=1, where a skip is a failure.The test (
p4-turn-smoke.test.sh):fake-turnscript, shared by the curl mock and a newmocactlmock.mocactlmock decodes the minted token and checks its subject and scope.loadAuth's exactcontrolPlaneUrlmatch;-H @filetoken, servesGET /v1/sessions/<id>to its owner only, checks the credential body's shape, and logs its whole argv.--authhappy path with failure paths, using a--control-planeURL with a trailing slash;--out(a sticky directory, left untouched) and a symlinked one are refused, and a new one is created 0700;P4-ON-P6.md:--authusage and cleanup, plus the verified rows below.setup-vm.shrecreatessh-rediswith--replaceand no volume. So a re-run loses the control plane's session and ownership index, and with it every user's sessions. That belongs to the epic (Epic: VM demo slice — P6 + P4 on one VM, multi-user mocactl login, sandbox research turns #370), not this PR, so it is only documented here and filed as deploy/vm: setup-vm.sh re-run recreates sh-redis (no volume) and loses every session #410.Verified
Locally:
make lintpasses.deploy/microvm/tests/*.test.shpass.mocactlaccepted the mintedauth.json;PUT, and session create with--option;--control-planeURL with a trailing slash;PUT /v1/credentialsreturns 204, not 200.On the KVM rig, the same
m8i.xlargehost as #376, 2026-09-30, this branch atfd6fed2:setup-vm.shwas re-run withSH_SANDBOX_COUNT=0. It installed the control plane, generated its keys and setSH_REQUIRE_AUTH=true. An unauthenticated/turnnow gets 401.setup-microvm.shwas re-run and printednothing to change. The worker re-attached by itself after each relay restart.p4-turn-smoke.sh --auth --failure-pathspassed 32/32, and a second run passed too. That run predates the two positive controls added in review, so it made 32 checks; a run now makes 34:workspace_keyis the control-plane session id thatmocactlprinted;/srv/workspaces/<id>;worker disconnected, and a killed VM gavevsock-short-response: vmpool: guest closed before End: EOF.Re-run on the rig after review, 2026-10-01, at
cf094b5:--auth --failure-pathspassed 34/34.auth.jsonandapi.hdrwere 0700/0700/0600/0600.The real login: verified 2026-10-01
The owner ran the steps below from a laptop over the SSH tunnel and reported them complete:
SH_REQUIRE_AUTH=true;The rig's journal for session
4e696222-746d-4e3c-9ffc-a6132b9f112eshows:vm-13,vm-15,vm-17), all under that control-planeworkspace_key(a UUID, notanon:);/srv/workspaces/<id>.A second real GitHub account was not tried on this tier; that is #367's two-account run. The steps, to repeat it:
On the rig:
On the laptop, from a checkout that has
packages/mocactlinstalled (pnpm install):Store an inference credential. Start
$M(the interactive UI), pressctrl+x k, and add one. For a direct Anthropic key, use:anthropicapi-keyinferenceapi.anthropic.comhttps://api.anthropic.comkey=<sk-ant-…>A gateway token uses kind
bearer,token=…and the gateway's origin instead.Check the setup, then run two multi-tool turns on one session:
Back on the rig, the acceptance evidence:
Expect:
uname -areadsLinux (none) 6.18.44+, not the host kernel;<id>with a distinctvm=.A second GitHub account doing the same gets its own workspace, and gets a 404 on the first account's session (
$M run … --session <first id>).Limits to state in the demo (from the runbook): no guest network (#277), so work on local content; no grant binding (MI1 S4); one VM per tool call (#274); and don't re-run
setup-vm.shmid-demo (the Redis limit above).Closes #369. Refs #370, #367, #410.
🤖 Generated with Claude Code