Skip to content

feat(deploy/vm): GitHub OAuth app on the VM path + two-user acceptance runbook (#367 items 1, 2, 4) - #403

Merged
pdettori merged 6 commits into
rossoctl:mainfrom
pdettori:feat/367-vm-demo-b-oauth-runbook
Oct 1, 2026
Merged

pdettori merged 6 commits into
rossoctl:mainfrom
pdettori:feat/367-vm-demo-b-oauth-runbook

Conversation

@pdettori

@pdettori pdettori commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Part of #367 (VM demo B). Item 3, the automated two-subject test, shipped in #371. This PR covers item 1 and the written parts of items 2 and 4. The live two-account acceptance run is still to be done, using the runbook added here.

Item 1: the GitHub OAuth app on deploy/vm

  • setup-vm.sh accepts SH_GITHUB_CLIENT_ID and SH_PUBLIC_HARNESS_URL from its environment, as deploy/compose/install.sh does for the client id.
    • Both, because the control plane starts only with both.
    • Because sudo drops the environment, the documented form is sudo env SH_GITHUB_CLIENT_ID=… SH_PUBLIC_HARNESS_URL=… ./deploy/vm/setup-vm.sh.
    • A value only fills an empty slot in control-plane.env. An operator's existing value is kept, with a warning when the environment disagrees.
    • Both values are validated before either is written: set_env_line writes the value verbatim, so a newline in it would inject an env line.
    • The client id must have GitHub's shape (letters and digits, at most one inner dot), so the docs' Ov23li... placeholder is refused rather than stuck in the file.
    • The URL check is an allowlist of URL characters, so a trailing backslash (a line continuation to EnvironmentFile=), $ and backticks are refused. The URL is then parsed with node's URL, as the control plane does at boot, so a value it would crash-loop on is refused at setup.
    • Seeded before require_relay_token, so a first run that stops at that check keeps them.
  • deploy/vm/README.md gains "The GitHub OAuth app":
    • create the app, tick Enable Device Flow (off by default, and the likeliest first-run failure), no client secret;
    • the read:user scope and the numeric-id subject;
    • outbound github.com/api.github.com from the VM, and users' browsers reaching github.com/login/device;
    • who can log in: anyone who reaches the control plane, since there's no allowlist.
  • "What round one does not claim" now states that users share sandbox containers on the container tier (MI1 S5).

Items 2 and 4: docs/demos/vm-two-user-acceptance.md

Boot contracts touched

Artifact Change
deploy/vm/setup-vm.sh two optional env inputs; new step seed_control_plane_env after install_env
deploy/vm/env/control-plane.env.example comment only
systemd units, TS entrypoints, Go launchers none

Testing

  • deploy/vm/tests/setup-vm.test.sh: new cases for filling empty slots, keeping and warning on existing values, silence when the environment agrees, refusing whitespace/newline/non-http values whole (a bad URL next to a good id writes neither), and main() ordering. The full suite passes.
  • Also covered: placeholder and malformed client ids (Ov23li..., Iv1., Ov23_li) and URLs that new URL refuses (http://a%, http://h:99999) are refused; GitHub's real id shapes and IPv6/https/path URLs pass (both checks mutation-checked); a quoted file value that agrees with the environment is silent; a commented-out slot is filled; a real first main() run that stops at the relay-token check keeps both settings (mutation-checked: moving the seed after that check fails the test); the unconfigured closing message names the sudo env route and no longer offers a bare systemctl start.
  • shellcheck and make lint (pre-commit, all files) pass.

Remaining on #367

The live run with two real GitHub accounts on an item-A VM, following the runbook and recording the results table.

🤖 Generated with Claude Code

@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.

The setup-vm.sh seeding is careful — both values validated before either is written, existing values kept with a warning on disagreement, placed before require_relay_token so a first run keeps them, and the tests cover each case. The two must-fixes are in the runbook, where a precondition and a cross-user check can each pass without testing anything: the unprivileged greps with an || echo fallback (Act 0a), and the never-assigned session ids (Act 2b). The suggestions are doc accuracy: the login error for a mistyped id, where onboarding appears, and two README spots the new env path didn't reach.

Advisory: commit 0760dfc's subject is 100 characters.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell, shell tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 3 commits, all signed-off: yes
CI status: passing

Comment thread docs/demos/vm-two-user-acceptance.md Outdated
./deploy/vm/setup-vm.sh
curl -s 127.0.0.1:8090/readyz; echo
grep -E '^SH_REQUIRE_AUTH=' /etc/serverless-harness/supervisor.env
grep -hE '^MOCA_TENANCY=' /etc/serverless-harness/*.env || echo 'MOCA_TENANCY unset'

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 — /etc/serverless-harness is created install -d -m 0750 and its env files 0640, both root-owned (setup-vm.sh:193, :201). As the non-root operator this block assumes (line 38 needs sudo), line 41 prints Permission denied.

Line 42 is worse: the shell can't expand *.env inside a directory it can't read, so grep fails and || echo 'MOCA_TENANCY unset' prints exactly the expected output. The precondition this page leans on hardest then passes whatever the VM is set to.

sudo grep alone doesn't fix it, since the unprivileged shell still does the glob. Something like

sudo sh -c 'grep -hE "^MOCA_TENANCY=" /etc/serverless-harness/*.env; [ $? -eq 1 ] && echo "MOCA_TENANCY unset"'

prints "unset" only on grep's no-match exit (1), not its error exit (2). Line 41 needs sudo too.

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 fda37d5, then tightened in 1ffe3e5. 0a no longer reads the env files at all. It reads the running supervisor's /proc/<pid>/environ under sudo sh <<'EOF', so root's shell does any expansion. The script exits before printing if it can't find or read the process, so MOCA_TENANCY unset means "read, and not there". That also catches a supervisor that was never restarted, and settings from a drop-in.

And because a file read never proved the harness behaves that way, 0a now ends with a token-less turn that must get {"error":"token_required",…} 401. 2c's session_mismatch appears in either auth mode, so on its own it never proved auth was on.

Comment thread docs/demos/vm-two-user-acceptance.md Outdated
Expected: `{"subject":"github:<numeric id>","tenant":"github:<numeric id>","roles":[]}`. The two
users' subjects differ.

Exchange session ids: user 1's is `$MINE` on user 1's laptop and `$THEIRS` on user 2's, and vice

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 — $MINE and $THEIRS are never assigned in a snippet, and if either is empty, 2b passes without testing ownership. /v1/sessions/ and /v1/sessions//token match no route (routes.ts anchors params as [^/]+), so the router's generic 404 answers (packages/control-plane/src/server.ts:79, {"error":"not_found"}). The fourth line 404s regardless, so the run shows "404 four times" without assertOwner ever running — and -o /dev/null throws away the body that would show the difference (not_found from the router vs session_not_found from the ownership check).

Suggest an explicit assignment with a guard, e.g. MINE=<your id>; THEIRS=<their id>; : "${MINE:?}" "${THEIRS:?}", and checking the body on the first three calls, e.g. curl -s -H @"$API_HDR" "$CP/v1/sessions/$THEIRS" | jq -r .error → session_not_found.

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 fda37d5 and 1ffe3e5.

  • Ids are assigned explicitly. A probe <method> <id> [suffix] helper refuses an empty or unedited (<…>) id. The id is its own argument, so "$THEIRS/token" can't smuggle an empty id past the check.
  • probe prints the body, and 2b expects {"error":"session_not_found","sessionId":…} 404, so the router's not_found is distinguishable.
  • Same failure class, found in self-review: a mistyped THEIRS also gets session_not_found (no such record). So each user first runs probe GET "$MINE", sees 200, and sends the sessionId from that output. 2b then compares the id echoed in each 404 with the one shown working, and the post-DELETE check repeats the same 200.
  • 2c is chained behind ids_set and a non-empty-mint check.

Comment thread docs/demos/vm-two-user-acceptance.md Outdated
```

> If it prints `login failed: github device code failed: device_flow_disabled`, the OAuth app's
> **Enable Device Flow** box is unticked. `incorrect_client_credentials` means

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 mistyped client id doesn't look like it produces incorrect_client_credentials at this step. identity.ts:99-102 forwards GitHub's body.error from /login/device/code verbatim, and a POST there with a nonexistent client_id came back HTTP 404 {"error":"Not Found"} — so the user would see login failed: github device code failed: Not Found, which this page never mentions. The same claim is in packages/mocactl/QUICKSTART.md:134 and fix-list row 4, and #405 as titled would map the wrong code. Worth confirming live with a deliberately wrong id before the acceptance run.

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.

Confirmed live: POST https://github.com/login/device/code with a nonexistent client_id returns HTTP 404 {"error":"Not Found"}, so the user sees login failed: github device code failed: Not Found. I fixed it in the runbook (1a), in packages/mocactl/QUICKSTART.md, in fix-list row 4 and in the deploy/vm/README.md OAuth steps. #405's title and body are corrected to map Not Found, and to prefer a distinct control-plane error code over string-matching GitHub's text.

Comment thread docs/demos/vm-two-user-acceptance.md Outdated

### 1b. Store an inference credential

Start `mocactl` (the first run is onboarding), or open **Credentials** with `ctrl+x k`, and add

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 — By this point Act 0b has exported SH_CONTROL_PLANE_URL and 1a has logged in, so mocactl opens straight to chat: initialOverlay (packages/mocactl/src/app.tsx:67-69, pinned by test/app.test.tsx:119) shows onboarding only on --setup or with no control-plane URL. Suggest mocactl --setup, or lead with ctrl+x k.

Also, QUICKSTART step 4 shows only a bearer example; an api-key credential needs endpoint https://api.anthropic.com and the API-key field (credential-form.ts) — worth a line here, since the page offers both kinds.

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, initialOverlay goes straight to chat once there's a URL and a login. 1b now leads with ctrl+x k (or mocactl --setup for onboarding). It also gives the api-key credential's fields: host api.anthropic.com, endpoint https://api.anthropic.com with no /v1, secret field key=. It notes that the form refuses an sk-ant-api… key stored as bearer.

Comment thread deploy/vm/README.md

The control-plane pair can instead be passed to either run, as
`sudo env SH_GITHUB_CLIENT_ID=… SH_PUBLIC_HARNESS_URL=… ./deploy/vm/setup-vm.sh`. The script
writes each one only where `control-plane.env` has none (see "The GitHub OAuth app" below).

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 — The "in this order" list just below (line 106) wasn't updated for the new step: between 1 (write env files) and 2 (relay-token check), seed_control_plane_env now writes SH_GITHUB_CLIENT_ID / SH_PUBLIC_HARNESS_URL into control-plane.env's empty slots. It's the one boot-contract change in the PR (per its own table), and this list is where an operator reads what a run writes.

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.

Done. Step 1 of the list now says that, after writing the env files, the script fills control-plane.env's empty client id / harness URL from its environment. Both values are checked first, an existing value is never replaced, and a disagreement is warned about. I folded it into step 1 rather than renumbering, since it runs right after install_env.

Comment thread deploy/vm/README.md Outdated
`setup-vm.sh` writes each value only where `control-plane.env` has none. It never replaces one
you have already set, and warns if the environment disagrees with the file.

- or by hand: set `SH_GITHUB_CLIENT_ID=` in `/etc/serverless-harness/control-plane.env` and

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 — The by-hand path names only SH_GITHUB_CLIENT_ID, but cp_configured needs SH_PUBLIC_HARNESS_URL too. Set only the id and re-run, and start_services only try-restarts the unit, so nothing starts; the systemctl restart alternative boots it advertising no harness, and doctor fails at check 5. The bullet above says the control plane "starts only once it has both" — this one should too.

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. The by-hand bullet sets both, and explains what happens with only the client id: the script leaves the control plane stopped, and a manual restart boots it advertising no harness, so doctor fails at check 5. The same mistake was in setup-vm.sh's unconfigured closing message, which offered systemctl start sh-control-plane.service. It now names both settings and the sudo env route, with a test that the bare systemctl start is gone.

Comment thread deploy/vm/README.md Outdated

**Network.** The VM must reach `https://github.com` (the device-code and token endpoints) and
`https://api.github.com` (`/user`) outbound. Each user's browser must reach
`https://github.com/login/device`. The laptop running `mocactl` talks only to the control plane,

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 — mocactl also talks to the harness on :8080 (doctor checks 5–7, every turn), as "Reaching it" below says. Maybe "talks only to the control plane and the harness it advertises, never to GitHub".

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.

Done: "talks only to the control plane and the harness it advertises, never to GitHub".

Comment thread docs/demos/vm-two-user-acceptance.md Outdated
400
```

The same token with `sessionId: $MINE` runs a normal turn. The harness checks exactly one rule,

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 — "The same token … runs a normal turn" holds within the session token's 300 s TTL (SH_SESSION_TOKEN_TTL_SECONDS); a presenter who pauses between the mint and this call gets 401 token_expired. Worth a parenthetical.

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.

Added: the same token runs a normal turn "within the token's lifetime (300 s, SH_SESSION_TOKEN_TTL_SECONDS)", and after a longer pause you get 401 token_expired and mint a fresh one.

Comment thread deploy/vm/tests/setup-vm.test.sh Outdated
sum_before="$(cksum <"$cpf")"
for bad in $'Ov23li\nSH_ALLOW_OPERATOR_FALLBACK=true' 'Ov23 li' 'Ov23li"'; do
rc=0; seed_out="$(SH_ENV_DIR="$SC" SH_GITHUB_CLIENT_ID="$bad" seed_control_plane_env 2>&1)" || rc=$?
((rc != 0)) || fail "a client id with whitespace was accepted: $(cat "$cpf")"

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 — The loop also covers 'Ov23li"' (a quote, no whitespace), so this message misnames that case: "a malformed client id was accepted".

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.

Renamed to "a malformed client id was accepted". Separately, I replaced the URL check's denylist with an allowlist of URL characters. The old pattern accepted http://x\ (a trailing backslash is a line continuation to EnvironmentFile=), $ and backticks. Those are now test cases.

…om env

rossoctl#367 item 1. deploy/vm/README.md gains "The GitHub OAuth app": creating it, ticking Enable Device
Flow (off by default, and the likeliest first-run failure), no client secret, the read:user scope,
outbound github.com/api.github.com from the VM, the laptops' browser reaching
github.com/login/device, and who can log in (anyone who reaches the control plane). "What round one
does not claim" now says sandboxes are shared between users on the container tier (MI1 S5).

setup-vm.sh accepts SH_GITHUB_CLIENT_ID and SH_PUBLIC_HARNESS_URL from its environment, as
deploy/compose/install.sh does for the client id -- both, because the control plane starts only with
both. Each fills control-plane.env's empty slot only; an operator's value is kept, with a warning
when the environment disagrees. Both are validated before either is written, since set_env_line
writes the value verbatim as one env line. Seeded before require_relay_token, so a first run that
stops there keeps them.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…items 2 and 4)

vm-two-user-acceptance.md: two GitHub users on their own laptops log in with mocactl (device
flow), pass all seven doctor checks and run a turn, then prove disjoint session lists, 404 for
another user's session on GET/DELETE/token re-mint (the same as a nonexistent id), and 400
session_mismatch for a session token presented against another session. States the tenancy it runs
under (MOCA_TENANCY unset, no first-subject pin yet) and what it does not claim (sandbox isolation
between users, direct credential mode, open egress, plain HTTP). Ends with a results table for the
live run and the fix list, each item checked against current main.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…misparse

Runbook (docs/demos/vm-two-user-acceptance.md):
- Act 0a: the env files are root-only, so both greps run under sudo, and the MOCA_TENANCY glob is
  expanded by root's shell. "unset" prints only on grep's no-match exit (1), never on its error
  exit (2), so an unreadable file can no longer pass the precondition.
- Act 2: MINE/THEIRS are assigned explicitly. A probe helper refuses an empty or unedited id and
  prints the body, so 2b expects session_not_found from the ownership check. The router's
  not_found for an empty path segment can no longer read as a pass. 2c is chained behind the same
  guard and an empty-mint check.
- 1a: a mistyped client id is GitHub's `Not Found` (checked against /login/device/code), not
  incorrect_client_credentials. Same fix in QUICKSTART and fix-list row 4.
- 1b: plain `mocactl` with a URL and a login opens chat, so lead with ctrl+x k (or --setup); add the
  api-key credential's fields.
- 2c: the session token's 300 s lifetime.

deploy/vm/README.md: the step list names the env seeding; the by-hand path needs both settings;
mocactl talks to the harness too; the mistyped-id symptom.

setup-vm.sh: SH_PUBLIC_HARNESS_URL is checked against an allowlist of URL characters. The old
denylist accepted a trailing backslash (a line continuation to EnvironmentFile=), `$` and
backticks. Test cases added; the client-id refusal message is now "malformed".

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…irst-run seed

From a self-review after the rossoctl#403 review, same failure class:
- 2b: a mistyped THEIRS gets the same session_not_found as a refusal. Each user now proves their
  own id with `probe GET "$MINE"` (200) and sends the sessionId from that output. 2b compares the
  id echoed in each 404 with the one shown working, and the post-DELETE check repeats that 200.
- 0a: SH_REQUIRE_AUTH and MOCA_TENANCY are read from the running supervisor's /proc environ, not
  the env file. "unset" prints only after a successful read. A token-less turn must get 401
  token_required: 2c's session_mismatch appears in either auth mode, so it alone never proved auth
  was on. The first-run note says this is the second run on a fresh VM.
- Code blocks carry no `#` comments, which macOS's zsh pastes as commands.

setup-vm.sh: the unconfigured closing message no longer offers `systemctl start` (the unit cannot
boot with a setting missing, or boots advertising no harness); it and install_env's hint name the
`sudo env` route. Tests: a quoted file value that agrees is silent, a commented-out slot is
filled, a real first main() run that stops at the relay token keeps both settings (checked by
mutation: moving the seed after the check fails it), and the closing message.

README: admins need a control-plane restart and a fresh login (roles live in the API token);
callback-URL wording.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori force-pushed the feat/367-vm-demo-b-oauth-runbook branch from 3c8a53d to 1ffe3e5 Compare October 1, 2026 01:32
@pdettori

pdettori commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Thanks @huang195. All nine comments are addressed (inline replies on each), plus one more round from a self-review hunting the same failure class.

Your must-fixes

  • 0a: now reads the running supervisor's environment, and prints "unset" only after a successful read.
  • 2b: explicit, guarded ids, and the checks assert the error code (session_not_found vs the router's not_found).

Found in self-review

  • 2b, mistyped id: a mistyped THEIRS passed just as an empty one did. Each user now proves their own id answers 200 before sending it, and 2b compares the echoed ids.
  • 2c doesn't prove auth is on: 2c passes with SH_REQUIRE_AUTH off, because a presented token is checked in either mode. 0a now adds a token-less turn that must get 401 token_required.
  • setup-vm.sh URL check: the old denylist accepted a trailing backslash, $ and backticks. It is now an allowlist.
  • Closing message: the unconfigured message offered systemctl start, which cannot work with a setting missing.
  • zsh paste: code blocks had # comments, which macOS's zsh runs as commands when pasted.
  • Test gaps: a real first-run main() and quoted/commented env slots are now covered.

History: following your advisory, I rebuilt the branch on the same base (6836941) to shorten 0760dfc's subject (now 0866938, 75 chars). The tree before and after the rebuild is identical: git diff between the old and new heads is empty. The two review rounds are fda37d5 and 1ffe3e5.

setup-vm.test.sh passes (70 checks), shellcheck is clean, and make lint passes.

@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.

Both round-1 must-fixes are properly fixed. 0a now reads the running supervisor's environment — the right process, since workers are forked with {...process.env} — and the token-less turn's token_required 401 body is exactly what writeAuthError produces. 2b can no longer pass vacuously: empty ids are refused, ids are exchanged only after their owner shows a 200, and the session_not_found bodies match assertOwner/writeError byte for byte.

One new must-fix: the runbook's headline claim doesn't hold against a participant holding the SSH account it requires, because loopback Redis (the ownership index) is unauthenticated, and the page doesn't say so. The suggestions are a credential-form instruction that stores a broken key if followed literally, a THEIRS == MINE paste that deletes your own session, a placeholder client id that passes validation and sticks, and a tunnel block that doesn't run as pasted.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell, shell tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 5 commits, all signed-off: yes
CI status: passing

- **Open egress.** Sandboxes reach the internet, including cloud instance metadata unless IMDSv2
with hop limit 1 is enforced on the host (#357).
- **Plain HTTP.** The tunnel is the confidentiality. The allowlist topology sends tokens in clear.
- **Anyone with a GitHub account who can reach the control plane can log in.** There is no user

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 — The SSH account Act 0b requires is also loopback access to every service bound on the VM, and two of them are unauthenticated: Redis on 127.0.0.1:6379 (no password, ACL or TLS — setup-vm.sh:209-235 says so itself), which holds the control plane's ownership index, and the supervisor's admin listener on :8081.

So a participant can, with a nologin shell, run ssh -N -L 6379:127.0.0.1:6379 <vm> and then HSET sh:cp:session:<theirs> owner github:<me> (ownership.ts:54). assertOwner (handlers.ts:89-91) then passes, and they can read, delete, or mint a turn token for the other user's session. The page's headline claim — "neither can see or reach the other's" — doesn't hold against a hostile participant, and this section is where that should be said.

Suggest a bullet here (and in the README's "Who may log in", which names the SSH tunnel as the gate) that SSH users are trusted with every loopback service, or restricting the tunnel accounts in sshd:

Match User <tunnel users>
  PermitOpen 127.0.0.1:8090 127.0.0.1:8080
  AllowStreamLocalForwarding no
  PermitTTY no

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 8f73b8e, in both of the places you name, and the runbook now enforces the restriction as well as stating it.

  • 0a installs your Match block, appended to the end of sshd_config (a Match runs to end of file), plus AllowTcpForwarding local, AllowAgentForwarding no, X11Forwarding no and ForceCommand /usr/sbin/nologin. ForceCommand also covers sftp and commands, which a nologin shell alone leaves to internal-sftp.
  • 0b checks it from each laptop: ssh <vm> true must print This account is currently not available., and printf 'PING\r\n' | ssh -W 127.0.0.1:6379 <vm> must say administratively prohibited, not +PONG. Both are in the Act 3 table.
  • The claim at the top now says it holds through the API, and that 0a is what closes the loopback route.
  • "Not claimed" and the README ("Who may log in", topology (a), "What round one does not claim") say that an unrestricted SSH account or a shell is trusted with every session on the VM.

Comment thread docs/demos/vm-two-user-acceptance.md Outdated
- **A gateway token** (LiteLLM and the like): kind `bearer`, with the fields in
`packages/mocactl/QUICKSTART.md`, step 4.
- **An Anthropic API key** (`sk-ant-api…`): kind `api-key`, destination host `api.anthropic.com`,
gateway endpoint `https://api.anthropic.com` (no `/v1`), secret field `key=<your key>`. The form

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 — "secret field key=<your key>" doesn't match the form. For kind api-key it shows a single masked field labelled API key (KNOWN_KINDS in credential-form.ts), and toPutRequest stores whatever is typed there verbatim. Typing key=sk-ant-… stores the key= prefix as part of the key: the sk-ant-api shape check never fires, doctor still passes (check 4 only looks for a credential, check 7 never calls the model), and the first failure is the model call at 1d.

Suggest "paste the key into the API key field". The bearer bullet above sends readers to QUICKSTART step 4, whose Secret fields | token=<your key> row (QUICKSTART.md:97, not in this diff) has the same problem — the field there is Token.

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 8f73b8e. 1b now says to paste the key as is into the API key field, and that the form stores it verbatim, so a key= prefix would become part of the key and only 1d would notice. QUICKSTART step 4's row is now Token | your key, as is (… no token= prefix). Onboarding uses the same CredentialsOverlay, so the one row covers both.

Comment thread docs/demos/vm-two-user-acceptance.md Outdated

```bash
probe GET "$THEIRS"
probe DELETE "$THEIRS"

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 refuses THEIRS == MINE: probe checks only for an empty or unedited id, and 2b never calls ids_set. A user who copies their own probe GET "$MINE" output into THEIRS gets a 200 on the first line and then deletes their own session (204) on this one, so 1d has to be redone.

Suggest adding [ "$MINE" != "$THEIRS" ] || { echo 'THEIRS is your own id' >&2; return 1; } to ids_set, and chaining 2b behind it (ids_set && probe GET "$THEIRS" && …).

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 8f73b8e. ids_set now refuses THEIRS == MINE. 2b also runs a new not_mine helper before the DELETE, because MINE != THEIRS still lets through another session you own (an earlier run, a second mocactl run). not_mine runs probe GET "$THEIRS", prints it, and stops the chain unless the status is 404. 2b is now ids_set && not_mine && probe DELETE … && probe POST … /token && probe GET sess-does-not-exist, and its output is the same four lines. I ran it in bash and zsh against a stub curl: the same id, another of my own sessions, and an unedited placeholder all stop before any DELETE, and a real other-user id runs all four.

Comment thread deploy/vm/setup-vm.sh Outdated
# URL characters only (RFC 3986, minus $ ' ( ) *): no whitespace, quote, `$`, backtick or
# backslash -- a trailing backslash continues the line for systemd's EnvironmentFile= parser.
local url_re='^https?://[][A-Za-z0-9._~:/?#@!&+,;=%-]+$'
if [[ -n "${SH_GITHUB_CLIENT_ID:-}" && ! "$SH_GITHUB_CLIENT_ID" =~ ^[A-Za-z0-9._-]+$ ]]; then

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 — The docs' own placeholder passes this check: Ov23li... matches ^[A-Za-z0-9._-]+$, and the examples pair it with a real URL (README.md:218, runbook :40, the header comment at :44). A literal paste writes SH_GITHUB_CLIENT_ID=Ov23li..., and since the seed never replaces a value, a later run with the right id only warns — login fails with Not Found until the file is edited by hand.

Suggest something like ^[A-Za-z0-9]+(\.[A-Za-z0-9]+)?$ (still accepts Ov23li…, legacy 20-hex and Iv1.… GitHub App ids), and adding 'Ov23li...' to the test's bad-value loop.

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 8f73b8e with your pattern, ^[A-Za-z0-9]+(\.[A-Za-z0-9]+)?$. The test's bad-value loop adds Ov23li..., Ov23li…, .Ov23li, Iv1., Ov23_li and -Ov23li. A new positive loop checks that an Ov23li + 14 id, a legacy 20-hex id and Iv1.<16 hex> still pass. Mutation-checked: putting the old character class back fails the test on Ov23li....

Comment thread docs/demos/vm-two-user-acceptance.md Outdated
because the control plane advertises one harness URL to everyone:

```bash
ssh -N -L 8090:127.0.0.1:8090 -L 8080:127.0.0.1:8080 <vm>

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 — ssh -N holds the foreground, so pasted as one block the export SH_CONTROL_PLANE_URL on the next line runs only after the tunnel is closed, and mocactl login then says "missing control-plane URL". Also, if something on the laptop already listens on 8080, ssh only warns and the advertised harness URL reaches that local service instead.

Suggest ssh -f -N -o ExitOnForwardFailure=yes -L 8090:127.0.0.1:8090 -L 8080:127.0.0.1:8080 <vm>, which backgrounds after the forwards are up and fails if either port is taken.

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 8f73b8e. 0b is now ssh -f -N -M -S ~/.ssh/moca-tunnel -o ExitOnForwardFailure=yes -L 8090:… -L 8080:… <vm>. -S names the tunnel, so Cleanup can close it with ssh -S ~/.ssh/moca-tunnel -O exit <vm> (-f alone would leave a background ssh to find by hand). The README's topology (a) uses -f -N -o ExitOnForwardFailure=yes too. The one-machine rehearsal trap now notes that the second tunnel fails because the first holds the ports.

Comment thread docs/demos/vm-two-user-acceptance.md Outdated
"read, and not there". The last line is the behaviour itself: a turn with no token is refused.

> Say: `SH_REQUIRE_AUTH=true` is what makes the harness demand a session token on every turn.
> Without it, that last turn would have been accepted. 2c's `session_mismatch` would still appear

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 — "Without it, that last turn would have been accepted" isn't quite what happens: with SH_REQUIRE_AUTH off, resolveTurnAuth returns null and /turn runs with createIfAbsent:false (run-turn.ts:703), so this request gets {"error":"session_not_found",…} 404. The check itself (401 vs 404) is fine — maybe "…would have passed authentication and failed only because no such session exists (404)".

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.

Reworded in 8f73b8e: with auth off, the turn "would pass authentication and fail only because no such session exists (session_not_found, 404)".

Comment thread docs/demos/vm-two-user-acceptance.md Outdated
gateway endpoint `https://api.anthropic.com` (no `/v1`), secret field `key=<your key>`. The form
refuses an API key stored as `bearer`, because the key is sent as `x-api-key`.

> Say: each user's turns spend **their own** credential. The operator-key fallback is off.

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 — "The operator-key fallback is off" is said but never checked. The same /proc/<MainPID>/environ read as 0a, against sh-control-plane.service, would make it a check (SH_ALLOW_OPERATOR_FALLBACK).

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.

Made it a check in 8f73b8e. 0a's root script reads SH_ALLOW_OPERATOR_FALLBACK from sh-control-plane.service's /proc/<MainPID>/environ, with the same exit-before-printing guard. Expected output is SH_ALLOW_OPERATOR_FALLBACK unset, and the page notes that =false also passes, since main.ts enables it only on === 'true'. It has a row in the Act 3 table, and 1b's "Say" now points back to 0a.

Comment thread deploy/vm/setup-vm.sh
local f="$SH_ENV_DIR/control-plane.env" key want have
# URL characters only (RFC 3986, minus $ ' ( ) *): no whitespace, quote, `$`, backtick or
# backslash -- a trailing backslash continues the line for systemd's EnvironmentFile= parser.
local url_re='^https?://[][A-Za-z0-9._~:/?#@!&+,;=%-]+$'

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 — The allowlist bounds the characters but not the shape: http://a% passes here, then the control plane's new URL refuses it at boot (packages/control-plane/src/main.ts:42-45), so the result is a crash loop under Restart=always rather than a refusal at setup time. node is already a required command, so node -e 'new URL(process.argv[1])' "$SH_PUBLIC_HARNESS_URL" alongside the character check would close it.

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 8f73b8e. After the character allowlist, the seed runs node -e with new URL(argv[1]) and requires an http:/https: protocol, matching urlEnv. node is in require_cmds, and the regex runs first, so nothing that does not start with http(s):// reaches node's argv. New bad cases: http://a%, http://[::1 and http://h:99999. New good cases: http://[::1]:8080, https://harness.example.com/ and a URL with a path. Mutation-checked: replacing the node check with a no-op fails the test on http://a%.

Comment thread deploy/vm/README.md Outdated
The login asks for the `read:user` scope only. The subject is the **numeric** GitHub user id
(`github:<id>`), never the login name, and GitHub's access token is used once, to read that id, and
then dropped. To make someone an admin (`GET /v1/sessions?owner=…`), put their subject in
`SH_ADMIN_SUBJECTS` and restart the control plane. Roles are computed at login and carried in the API token, so the user must then log in again (`mocactl login`). `GET /v1/me` with the new token shows the role.

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 sentence is one ~200-character line; the rest of the file wraps at 100.

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.

Wrapped at 100 in 8f73b8e.

…ossoctl#403 round 2)

The runbook's claim held only through the API: an SSH account reaches
unauthenticated loopback Redis, which holds the ownership index. 0a now
installs a Match block (PermitOpen 8090/8080 only, ForceCommand nologin)
and 0b checks it from each laptop; README and "not claimed" say so.

- 2b: ids_set refuses THEIRS == MINE, and not_mine stops the chain
  unless THEIRS answers 404, so the DELETE never hits your own session.
- 0b: the tunnel is backgrounded with ExitOnForwardFailure, named with
  -S so cleanup closes it.
- 0a: checks SH_ALLOW_OPERATOR_FALLBACK in the running control plane;
  the auth-off wording now says 404, not "accepted".
- 1b and QUICKSTART: the secret goes into the API key / Token field as
  is; a key= or token= prefix would be stored as part of it.
- setup-vm.sh: a client id must be letters and digits with at most one
  inner dot, so the docs' Ov23li... placeholder is refused; the harness
  URL is also parsed with node's URL, as the control plane does at boot.
  Tests cover both, and accept GitHub's real id shapes.

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

Round 2 is addressed in 8f73b8e, with a reply on each of the nine threads.

Must-fix: loopback access. The runbook no longer just states the trust boundary, it enforces it:

  • 0a installs a Match block for the participants' accounts: PermitOpen to 8090/8080 only, no stream-local or agent forwarding, and ForceCommand nologin, which also covers sftp.
  • 0b checks the block from each laptop: no shell, and a forward to Redis is administratively prohibited.
  • The claim, "not claimed" and the README say that an unrestricted SSH account or a shell is trusted with every session.

Suggestions

  • The secret goes into the API key / Token field as is. Fixed in the runbook and in QUICKSTART step 4.
  • THEIRS == MINE: ids_set refuses it. A new not_mine gate also covers another of your own sessions: it stops 2b before the DELETE unless THEIRS answers 404.
  • Client ids must have GitHub's shape, so Ov23li... is refused.
  • The tunnel is ssh -f -N -M -S … -o ExitOnForwardFailure=yes, and Cleanup closes it.

Nits

  • The auth-off wording now says 404.
  • SH_ALLOW_OPERATOR_FALLBACK is read from the running control plane.
  • The harness URL is also parsed with node's URL, as urlEnv does.
  • The README line is wrapped.

Self-review, same failure class:

  • With ssh -f, the tunnel is a background process with no handle, so it now has a control socket.
  • The one-machine rehearsal opens a single tunnel.
  • The client-id and URL checks have positive cases, so that a tighter pattern doesn't refuse real ids or IPv6 URLs.

setup-vm.test.sh (71 checks) and make test-deploy pass, as do make lint and shellcheck. Both new checks are mutation-tested.

Not changed here: deploy/compose/install.sh seeds SH_GITHUB_CLIENT_ID without any shape check, so the same Ov23li... paste sticks there. It is outside this PR's files, so I'm leaving it for a follow-up.

@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.

All nine round-2 threads are addressed. I checked the loopback fix against a real sshd rather than just reading it. With this page's Match block on OpenSSH 9.6 (Ubuntu 24.04):

  • ssh <vm> true prints This account is currently not available.
  • ssh -W 127.0.0.1:6379 prints exactly the two lines 0b expects.
  • A forward to 6379 is reset, and sftp is refused.
  • The 8090 forward works through the -M -S tunnel, and -O exit closes it.

The sandbox route to the same Redis was already closed: moca_sandbox's input chain drops everything from the bridge except the relay port and DNS. So 0a really does close what round 2 flagged. SH_ALLOW_OPERATOR_FALLBACK is read from the right process (it lives in control-plane.env; main.ts:87 checks === 'true'). The node check matches urlEnv, and replacing it with true fails the suite on http://a%.

One suggestion, and it corrects a suggestion I made in round 2: ExitOnForwardFailure doesn't catch a laptop port that is already held on 127.0.0.1 only, so the tunnel needs explicit 127.0.0.1: bind addresses. Plus two nits.

Advisory: the subjects of 8f73b8e and 1ffe3e5 are 83 and 82 characters.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell, shell tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: passing

Comment on lines +126 to +127
ssh -f -N -M -S ~/.ssh/moca-tunnel -o ExitOnForwardFailure=yes \
-L 8090:127.0.0.1:8090 -L 8080:127.0.0.1:8080 <vm>

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 — ExitOnForwardFailure doesn't catch the case the paragraph below names, in its commonest form: a laptop service that listens on 127.0.0.1:8080 only.

With no bind address, -L 8080:… binds localhost, which means both 127.0.0.1 and [::1]. The IPv4 bind fails and the IPv6 one succeeds, which is enough for ssh to count the forward as up. It prints bind [127.0.0.1]:8080: Address already in use, goes to the background, and exits 0. mocactl then dials 127.0.0.1 (the advertised http://127.0.0.1:8080), which still reaches the local service.

I reproduced this with the OpenSSH 10.3p1 (macOS) and 9.6p1 (Ubuntu) clients against this page's Match block. curl 127.0.0.1:<port> was answered by the laptop's service, and curl [::1]:<port> by the VM.

Binding the IPv4 side explicitly makes the conflict fatal. Same setup, rc=255, Could not request local forwarding.:

ssh -f -N -M -S ~/.ssh/moca-tunnel -o ExitOnForwardFailure=yes \
  -L 127.0.0.1:8090:127.0.0.1:8090 -L 127.0.0.1:8080:127.0.0.1:8080 <vm>

deploy/vm/README.md:300-302 has the same form and makes the same claim. This one's on me: it's the command I suggested in round 2.

```

`ForceCommand` refuses a shell, a command and `sftp` alike. `PermitOpen` matches the destination
as written, so `localhost:6379` or `[::1]:6379` is refused as well. 0b checks it from each

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 — The same literal match also refuses localhost for the two permitted ports. A participant who types -L 8080:localhost:8080 gets a tunnel that opens without error, but every connection through it is reset (I reproduced this against this block). Maybe: "…is refused as well, and so is localhost:8080: paste 0b's forwards as written."

```

Expected: `This account is currently not available.`, then a line ending
`administratively prohibited: open failed`, and `stdio forwarding failed`. No message from the first, or `+PONG` (Redis answering) from 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.

nit — This line is 141 characters. The reflow left it unwrapped in a paragraph that otherwise wraps at 100.

@pdettori
pdettori merged commit f8d0e6c into rossoctl:main Oct 1, 2026
13 checks passed
@pdettori
pdettori deleted the feat/367-vm-demo-b-oauth-runbook branch October 1, 2026 02:59
pdettori added a commit to pdettori/moca that referenced this pull request Oct 1, 2026
Resolves deploy/vm/README.md (the egress bullet beside rossoctl#403's two isolation bullets) and
deploy/vm/tests/setup-vm.test.sh (the operator-fallback section beside rossoctl#403's
seed_control_plane_env section): both sides kept.

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.

2 participants