Skip to content

feat(microvm): authenticated mocactl turns on the P4 tier (#369) - #409

Merged
pdettori merged 6 commits into
rossoctl:mainfrom
pdettori:feat/369-p4-authenticated-turn
Oct 1, 2026
Merged

pdettori merged 6 commits into
rossoctl:mainfrom
pdettori:feat/369-p4-authenticated-turn

Conversation

@pdettori

@pdettori pdettori commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR covers the part of #369 that #376 left: a logged-in user's mocactl run on the P4 microVM tier, on a deploy/vm host with the control plane (#366) and SH_REQUIRE_AUTH=true.

#376 verified P4 only through the unauthenticated /turn, which a current deploy/vm install closes. Its runbook told you to turn auth off to run the check.

What's in it

p4-turn-smoke.sh --auth checks the P4 tier with auth left on.

  • It stands in for mocactl login the way deploy/compose/smoke.sh does. It mints one api token per subject (p4smoke:a, p4smoke:b) with the control plane's own signing key.
  • It stores a bearer inference credential that points at the loopback mock-anthropic.mjs.
  • It drives every turn through the real mocactl run.
  • Session B belongs to the second subject. Each subject must read its own session (200), and the second must get a 404 on session A: the control plane also answers 404 for an unknown id, so the 404 counts only next to the two 200s.
  • The existing checks run over it unchanged: workspace survival, separate workspaces, journal workspace_key/vm= evidence, and the failure paths.
  • node writes the token straight into 0600 files under a 0700 directory. The token never appears on an argv or in a shell variable.
  • Each mocactl run is bounded by timeout(1) (SMOKE_TURN_TIMEOUT, 300s, the same bound as the unauthenticated path's curl), with --foreground so Ctrl-C reaches it. A hung turn shows up as timed-out.
  • The default --out is a fresh mktemp -d. With --auth, a named --out must not exist yet: the run creates it 0700 (mkdir without -p), so an existing path, such as /tmp under sudo, or a symlink is refused.
  • The default, unauthenticated mode is unchanged.

CI: deploy-scripts runs without pnpm install, so there the --auth block skips and says why. The check job, which has tsx, runs the suite with P4_SMOKE_REQUIRE_AUTH=1, where a skip is a failure.

The test (p4-turn-smoke.test.sh):

  • The fake supervisor turn is factored into one fake-turn script, shared by the curl mock and a new mocactl mock.
  • The mocactl mock decodes the minted token and checks its subject and scope.
  • The mocks model what the checks depend on:
    • the mocactl mock records who created each session, and applies loadAuth's exact controlPlaneUrl match;
    • the curl mock decodes the caller from the -H @file token, serves GET /v1/sessions/<id> to its owner only, checks the credential body's shape, and logs its whole argv.
  • Cases:
    • the --auth happy path with failure paths, using a --control-plane URL with a trailing slash;
    • a hung turn times out, by name;
    • an unreadable signing key fails at the mint, by name;
    • an existing --out (a sticky directory, left untouched) and a symlinked one are refused, and a new one is created 0700;
    • directory and file modes.
  • Mutants that must fail, kept in the suite: every turn as subject a; the token on curl's argv; b's credential stored with a's token; a credential the control plane would refuse.

P4-ON-P6.md:

Verified

Locally:

  • make lint passes.
  • All six deploy/microvm/tests/*.test.sh pass.
  • shellcheck is clean.
  • Two deliberate breaks of the driver both fail the test.
  • The control-plane half ran against a real local control plane:
    • the real mocactl accepted the minted auth.json;
    • credential PUT, and session create with --option;
    • the owners' 200s and the cross-subject 404;
    • a --control-plane URL with a trailing slash;
    • a re-run;
    • the runbook's cleanup deletes, all 204.
  • That run caught a wrong mock: PUT /v1/credentials returns 204, not 200.

On the KVM rig, the same m8i.xlarge host as #376, 2026-09-30, this branch at fd6fed2:

  • setup-vm.sh was re-run with SH_SANDBOX_COUNT=0. It installed the control plane, generated its keys and set SH_REQUIRE_AUTH=true. An unauthenticated /turn now gets 401.
  • setup-microvm.sh was re-run and printed nothing to change. The worker re-attached by itself after each relay restart.
  • p4-turn-smoke.sh --auth --failure-paths passed 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_key is the control-plane session id that mocactl printed;
    • 4 Execs ran in 4 distinct VMs;
    • turn 2 read turn 1's file and repo;
    • subject b's session saw neither, and has its own /srv/workspaces/<id>;
    • subject b got a 404 on A's session;
    • a worker restart gave worker disconnected, and a killed VM gave vsock-short-response: vmpool: guest closed before End: EOF.
  • Cleanup on the rig: the mock unit, the supervisor drop-in, the test credentials and subject records, this run's workspaces and the token-bearing output were removed. The control plane is left installed for the real login below. The runbook's cleanup now also deletes the run's sessions, and prints each delete's HTTP code.

Re-run on the rig after review, 2026-10-01, at cf094b5: --auth --failure-paths passed 34/34.

  • The owners' 200s and the cross-subject 404 held.
  • The output dir, the config dirs, auth.json and api.hdr were 0700/0700/0600/0600.
  • 4 Execs ran in 4 distinct VMs.
  • The runbook's cleanup block, run as written, got four 204s and left nothing of the run behind.
  • The rig was returned to the state it was found in.

The real login: verified 2026-10-01

The owner ran the steps below from a laptop over the SSH tunnel and reported them complete:

  • a real GitHub OAuth app with device flow on;
  • SH_REQUIRE_AUTH=true;
  • no supervisor drop-in, so no mock model.

The rig's journal for session 4e696222-746d-4e3c-9ffc-a6132b9f112e shows:

  • two turns: 2 Execs at 01:31, then 1 Exec at 01:32:57;
  • 3 Execs in 3 distinct microVMs (vm-13, vm-15, vm-17), all under that control-plane workspace_key (a UUID, not anon:);
  • its own /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:

# 1. A GitHub OAuth app with "Enable Device Flow" ticked (its client id is not a secret).
sudo sed -i 's/^SH_GITHUB_CLIENT_ID=.*/SH_GITHUB_CLIENT_ID=<client id>/' /etc/serverless-harness/control-plane.env
sudo systemctl restart sh-control-plane
curl -s 127.0.0.1:8090/readyz                           # ok
grep -E '^SH_REQUIRE_AUTH' /etc/serverless-harness/supervisor.env   # true

On the laptop, from a checkout that has packages/mocactl installed (pnpm install):

# 2. Tunnel both ports. The advertised harness URL is http://127.0.0.1:8080, so forward that exact port.
ssh -i <key> -N -L 8090:127.0.0.1:8090 -L 8080:127.0.0.1:8080 ec2-user@<rig> &

# 3. Log in (GitHub device flow: open the URL, enter the code).
M="node packages/mocactl/bin/mocactl.mjs --control-plane-url http://127.0.0.1:8090"
$M login
  1. Store an inference credential. Start $M (the interactive UI), press ctrl+x k, and add one. For a direct Anthropic key, use:

    • name anthropic
    • kind api-key
    • consumer inference
    • destination host api.anthropic.com
    • endpoint https://api.anthropic.com
    • secret key=<sk-ant-…>

    A gateway token uses kind bearer, token=… and the gateway's origin instead.

  2. Check the setup, then run two multi-tool turns on one session:

$M doctor                                                # all seven checks
$M run "In your sandbox: write uname -a and python3 --version to notes.txt, git init, commit it, and tell me the hash." \
  --option inferenceCredential=anthropic                 # prints "session <id>" on stderr
$M run "Show git log --oneline and notes.txt." --session <id>

Back on the rig, the acceptance evidence:

# 6. One line per Exec under the session's id, each with its own vm=.
sudo journalctl -u microvm-worker --since -15min | grep 'vmpool: exec' | grep 'workspace_key="<id>"'
sudo ls /srv/workspaces/                                 # <id> is there

Expect:

  • turn 2 shows turn 1's commit;
  • the guest's uname -a reads Linux (none) 6.18.44+, not the host kernel;
  • every journal line names <id> with a distinct vm=.

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.sh mid-demo (the Redis limit above).

Closes #369. Refs #370, #367, #410.

🤖 Generated with Claude Code

…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]>
@pdettori

pdettori commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

manual verification has been completed and work as expected

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread deploy/microvm/p4-turn-smoke.sh Outdated
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 \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 decoded sub to $STATE/owner-<sid>.
  • The curl mock reads the bearer token from the -H @file it is given, decodes its sub, 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread deploy/microvm/P4-ON-P6.md Outdated
| ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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`) |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread deploy/microvm/P4-ON-P6.md Outdated
sudo systemctl stop p4-mock-anthropic
```

After an `--auth` run, delete each subject's mock credential while its token is still valid, then the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-smoke

The workspaces under /srv/workspaces and the subject records you removed on the rig each need a line too, or a note that they stay.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ;;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pdettori pdettori Oct 1, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • deleteSession answers 202 or 204 (handlers.ts:329);
  • the file store names a record sha256(subject)[0:16].json under /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

Comment thread deploy/microvm/p4-turn-smoke.sh Outdated
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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 it

Suggest: 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this repeats the mode() helper defined four lines up. "$(mode "$TMP/out3/xdg-a/mocactl/auth.json")" does the same thing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@pdettori
pdettori merged commit c77c3d2 into rossoctl:main Oct 1, 2026
13 checks passed
pdettori added a commit to pdettori/moca that referenced this pull request Oct 1, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VM demo D: wire the P4 microVM worker into P6 and run its first real harness turn

2 participants