Repository navigation
feat(deploy/vm): run the MU1 control plane on the P6 VM (#366) - #374
Conversation
…llback Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…HOST
Pins that /v1/sessions/{id}/resources answers phase unknown on a host
with no kubectl, as on deploy/vm.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Supervisor workers on deploy/vm can now read SH_EXCHANGE_TOKEN as a systemd credential (loaded via LoadCredential=SH_EXCHANGE_TOKEN in the unit file), falling back to the environment variable for other deployment modes. This change updates two components: - turnAuthDepsFromEnv: reads the exchange token per-request via credentialValue - prepareServerProcess: resolves the credential at boot so both-set or empty credentials fail the process startup, not the first authenticated turn Both code paths use the same credentialValue resolver from @moca/control-plane, which validates the credential and ensures consistency across the harness. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Secrets arrive by LoadCredential=, never an env line; the supervisor loads the same exchange-token file. supervisor.env.example now dials the control plane on loopback :8090 and requires auth; compose.test.sh records that compose keeps SH_REQUIRE_AUTH=false as a deliberate divergence from that template. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…al files Refuses a half keypair, an empty file, a secret also set as an env line, and a garbled generator, writing nothing. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
wire_supervisor_mu1 writes SH_CONTROL_PLANE_URL (from SH_CONTROL_PLANE_PORT) and SH_REQUIRE_AUTH=true only on the run that generated the MU1 signing keypair; later runs leave both to the operator, except re-adding a missing SH_CONTROL_PLANE_URL. An empty or non-numeric SH_CONTROL_PLANE_PORT is refused. Tests cover the upgrade from the pre-control-plane template. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Under a caller's || (errexit suspended), a failing awk or mktemp emptied the env file and set_env_line still returned 0. Each step now checks its result and returns 1, leaving the file untouched; tests stub awk and mktemp. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Started once SH_GITHUB_CLIENT_ID and SH_PUBLIC_HARNESS_URL are set; enabled and try-restarted until then. Secrets are generated before the units that load them are installed. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
deploy/vm/README.md now describes sh-control-plane.service as setup-vm.sh installs it: the three-file first run, the MU1-secrets step and the control plane's start rule, a new "The control plane" section (file store, the credential table, rotation by delete-and-re-run, the not-a-uid-boundary limit, the operator-key drop-in, the SSH-tunnel and allowlist topologies, /readyz and doctor, and an api-token mint that keeps the key in its root-only file), and the upgrade path's SH_REQUIRE_AUTH=true switch and its refusals. mocactl's Troubleshooting points VM operators at a setup-vm.sh re-run instead of hand-written supervisor.env lines. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ensure_mu1_secrets called write_secret as `[[ -z "$kek" ]] || write_secret ...`, which runs it with errexit suspended: a failed printf (ENOSPC on /etc) followed by a successful mv renamed an empty secret into place and returned 0. write_secret now checks mktemp, the write and the rename itself and removes its temp file on failure, and every write_secret / set_env_line call in ensure_mu1_secrets propagates a failure. Tests: a failing write (printf stubbed for write_secret only), mktemp and mv each fail ensure_mu1_secrets, leave no secret and no temp file, and leave supervisor.env unchanged. A stand-in generator garbled only in its last value (SH_EXCHANGE_TOKEN) refuses and writes nothing -- the existing garbled case failed on the second value, so it could not tell "checked before the first write" from "checked before its own write". Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ensure_mu1_secrets generated any missing secret, the KEK included. With credential-kek gone but the file store (SH_CREDENTIAL_DIR in control-plane.env, default /var/lib/moca-control-plane) holding records, that silently made every stored credential undecryptable. It now stops first -- a pre-write check, before the credentials dir is created -- naming the KEK path, the store and the two ways out: restore the KEK from a backup, or empty the store deliberately. Tests: a store with one record refuses and writes nothing; an empty store generates the KEK; a full store with the KEK present still generates a missing exchange token. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
The units load the MU1 secrets with LoadCredential=, new in systemd 247. An older systemd (RHEL 8's 239) ignores the key with a warning: the control plane dies on a missing SH_SESSION_TOKEN_PRIVATE_KEY and the supervisor runs with SH_REQUIRE_AUTH=true and no exchange token. require_systemd <min> reads the first integer after "systemd" on `systemctl --version`'s first line and refuses, naming the found version, the needed 247 and why, or an unreadable version. main() runs it right after require_cmds. README Prerequisites says so. Tests: the systemctl mock now answers --version (a 252 by default, MOCK_SYSTEMCTL_VERSION overrides) through one write_systemctl_mock helper, which the podman-restart test reuses; 252 passes, 239 refuses naming 239/247/LoadCredential=, garbled and empty output refuse, and main() runs the check right after require_cmds. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…setup-vm.sh The "harness trusts this control plane" fix still told VM operators to set SH_EXCHANGE_TOKEN, which setup-vm.sh now refuses as an env line (it is a systemd credential). On the VM path the hint now says to re-run `sudo ./deploy/vm/setup-vm.sh`, which installs the control plane and wires the harness. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
README: - the auth.json step creates the config dir first and honours XDG_CONFIG_HOME, as mocactl's own config.ts does; - LoadCredential= keeps secrets out of child processes' environments, not out of children, which inherit CREDENTIALS_DIRECTORY and the uid; - an upgraded supervisor.env keeps the old MU1 comment block and a commented #SH_EXCHANGE_TOKEN= line, both inert; - an enabled but unconfigured control plane starts on every boot, fails on the missing SH_GITHUB_CLIENT_ID, trips the default start limit under Restart=always and leaves the system degraded, until configured and re-run; `systemctl disable` opts out until the next re-run. setup-vm.sh: SH_CRED_DIR is marked test-only (the units hardcode /etc/serverless-harness/credentials); stale "supervisor/relay env files" and "both units" comments name all three. setup-vm.test.sh: non-empty guards on the main.ts mirror and on every line in main()'s order check; the control-plane unit's LoadCredential= count is pinned to MU1_CREDENTIALS; the vacuous "none in any recorded argv" check is dropped, with why; the header names all three units. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
821cf53 to
7daeb31
Compare
…rvisor Found on a live Amazon Linux 2023 run of rossoctl#366: - sudo's secure_path drops /usr/local/bin, where a static podman build installs (AL2023 packages none). require_cmds now says where the tool is and prints the `sudo env PATH="/usr/local/bin:$PATH"` re-run; the README's prerequisites say the same. - On a re-run with the supervisor running (every upgrade), the closing message still said to set SH_TURNS_PER_WORKER and start it. It now asks systemd and reports a running supervisor as running. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Live acceptance on a real VMHost: Amazon Linux 2023 (kernel 6.18), systemd 252, Node 22.23, pnpm 9.15. podman: the static podman-static 6.1.2 build (netavark 2.1.0); AL2023 packages no podman. Its signature verifies against the project's documented key 0CCF102C… (signed by its subkey 6E8EF2F5…), and the installed binary matches the tarball. nftables: from AL2023's own repo. The checkout was this branch, at 821cf53. Fresh install, following the README's first-run flow (two invocations, then
|
| Check | Result |
|---|---|
| Invocation 1 | writes supervisor.env, relay.env and control-plane.env, then stops at SH_RELAY_TOKEN (exit 1), as documented |
| Invocation 2 | exit 0: relay restarted, control plane started (configured), supervisor enabled but not started |
systemctl is-active relay, supervisor, control plane, firewall |
all active |
curl 127.0.0.1:8090/readyz |
ok, HTTP 200 |
GET /v1/discovery |
{"harnessUrl":"http://127.0.0.1:8080"} |
| Control-plane listener | 127.0.0.1:8090 only |
/etc/serverless-harness/credentials |
dir 0700 root; credential-kek, exchange-token, session-token-private-key each 0600 root |
LoadCredential= delivery |
/run/credentials/sh-control-plane.service/ holds all three and /run/credentials/sh-supervisor.service/ holds the exchange token, each 0400 harness |
Secrets in /proc/<pid>/environ (control plane, supervisor) |
none |
| Forked supervisor workers (5) | each inherits CREDENTIALS_DIRECTORY and can read SH_EXCHANGE_TOKEN as harness inside the unit's mount namespace |
File credential store under ProtectSystem=strict |
PUT /v1/credentials/… returns 204; the record lands in /var/lib/moca-control-plane (0700 harness) |
supervisor.env |
public keyset, SH_CONTROL_PLANE_URL=http://127.0.0.1:8090, SH_REQUIRE_AUTH=true; no exchange-token line |
Bare POST /turn |
401 |
mocactl --control-plane-url http://127.0.0.1:8090 doctor from a laptop, through ssh -N -L 8090:… -L 8080:…, with an API token minted by the README's snippet |
before a credential: ✓1–3, ✗4 "inference credential present", as documented. After one: ✓ all 7, including "harness located" and "harness trusts this control plane" |
Re-run
| Check | Result |
|---|---|
sha256 of the three credential files, supervisor.env, control-plane.env and relay.env, before and after setup-vm.sh |
all identical; nothing generated |
| Key id | 65b74a6593910926, unchanged |
doctor afterwards |
✓ all 7 |
Upgrade from upstream/main @ 73f1bf4 (no control plane)
| Check | Result |
|---|---|
| Base | relay and supervisor active; SH_REQUIRE_AUTH=false; MU1 lines commented out; bare /turn gets past auth (503) |
| Checkout of this branch, then one re-run | installs control-plane.env and the unit, generates the three secrets and wires supervisor.env (SH_REQUIRE_AUTH=true). The operator's SH_TURNS_PER_WORKER=2 is kept and relay.env is untouched (sha256). The running supervisor is restarted onto its new unit. The control plane stays enabled but not started until configured, with a closing message that says so |
After SH_GITHUB_CLIENT_ID and SH_PUBLIC_HARNESS_URL are set, one more re-run |
control plane active; readyz 200; bare /turn 401 |
doctor |
✓ all 7 |
Found on the rig, fixed in 40411b0
- sudo drops the static podman: AL2023's
sudosecure_pathleaves out/usr/local/bin, where the static podman installs, sosetup-vm.shstopped with a bare "missing required commands: podman". It now names where the tool is and prints thesudo env PATH="/usr/local/bin:$PATH" ./deploy/vm/setup-vm.shre-run. The README's prerequisites say the same. - Wrong closing message on re-runs: on a re-run with the supervisor running (every upgrade), the closing message still said to set
SH_TURNS_PER_WORKERand start it. It now asks systemd and reports a running supervisor as running.
Cleanup
Everything installed for the test was recorded in a manifest and then removed, and the rig was checked afterwards:
- the units and their symlinks;
- the containers, network and nft tables;
- podman storage and every file from the podman-static tarball;
- the
nftablespackage and theharnessuser and group; - the checkout, the logs and the manifest itself.
/usr/local/bin is back to its original contents, and no MOCA ports are listening.
Also: d13851a's trailer was reworded to Assisted-By, and the branch was force-pushed. The tree is unchanged.
…d host CodeQL js/clear-text-logging (high): the startup line logged `host`, which main.ts reads from the env copy withCredentials returns -- the same object that carries the resolved secrets. The host is not a secret, but nothing read from that object should reach a log line. Log server.address() instead; `host` only decides whether an address is shown, so the output is unchanged (`127.0.0.1:<port>`, or `:<port>` with no host) and now pinned by tests. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
mrsabath
left a comment
There was a problem hiding this comment.
Reviewed the credential handling, the systemd units, setup-vm.sh, and the upgrade path. No must-fix. Approving.
The CodeQL alert is already fixed
Worth stating up front, since the alert is still showing on this PR: code-scanning alert #70 (js/clear-text-logging, high, packages/control-plane/src/server.ts:149) is stale, not outstanding. Its most recent instance is commit 8231368d — the merge for 40411b08, one commit before the fix — and 86197db1 is the fix. CodeQL passes on HEAD.
I checked the fix is genuine rather than a cosmetic silencing: the startup line now logs server.address(), the socket's own bound address, instead of the host string that came from the same env copy carrying the resolved secrets. Output is unchanged (127.0.0.1:<port>, or :<port> with no host) and both cases are now pinned by new tests.
What I verified
Credential design — the part that carries the risk here:
credentialValuerefuses a secret set both ways, refuses an empty credential file, and correctly distinguishes ENOENT (fall back to env, which is what Knative and compose keep doing) from any other read error (throw). All seven behaviours have tests.- Secrets are resolved into a copy —
withCredentialsatmain.ts:179— so they never enterprocess.env. That is the detail that matters, given kubectl children inherit it. - Names agree across all three places they appear:
MU1_CREDENTIALSin the script,LoadCredential=in both units, andCONTROL_PLANE_SECRETSin code. The exchange token is literally the same file for both tiers, so the two cannot drift. SH_OPERATOR_INFERENCE_TOKENis in the secrets list with noLoadCredential=, which I checked rather than assumed: it is optional, the env fallback works, andREADME.md:229ships a commented-outLoadCredential=line for an operator who wants it. Correct asymmetry.prepareServerProcessresolving the exchange token at boot so a both-set or empty credential fails the boot rather than the first authenticated turn is the right call.
setup-vm.sh:
ensure_mu1_secretsextracts and validates every value before the first write, and clearsGENERATEDon each failure path — so a bad generator run leaves nothing half-written. All five documented refusals are present.- The lost-KEK guard is the best thing in this script: refusing to regenerate a KEK when the store already holds records sealed under the old one. A new KEK there silently bricks every stored credential, and that is exactly the class of failure nobody notices until they need the data.
set_env_linestages through/tmpbut only ever writes non-secrets (the public keyset, the URL,true), andcat >preserves the target's 0640. Fine.- Modes are right throughout: credentials dir 0700, secret files 0600 via
umask 077+ mktemp, env files 0640, units 0644. sh-control-plane.servicehardening matches the other two units —ProtectSystem=strict,NoNewPrivileges,SystemCallFilter=@system-service,StateDirectoryMode=0700,RestrictAddressFamilies. TheAfter=podman-restart.service-as-ordering-only reasoning is sound.
The SH_REQUIRE_AUTH=true upgrade break is a real behavioural change, and it is handled the way I would want: wire_supervisor_mu1 forces it only on the run that generates the keypair, so an operator's later false survives re-runs, and the README calls it out prominently under "Upgrading an existing VM". The compose divergence (SH_REQUIRE_AUTH=false) is deliberate, explained, and pinned by compose.test.sh:268.
Also clean: bash -n on both shell files, no secrets in the diff (test fixtures correctly marked # notsecret), no workflow changes, 16 commits all signed-off and all using Assisted-By per this repo's CLAUDE.md — no Co-Authored-By anywhere.
What I could not run myself
Stating this rather than implying broader verification than I did: this host has bash 3.2 (no mapfile) and no pnpm or installed dependencies, so I could not complete deploy/vm/tests/setup-vm.test.sh or the TypeScript suites locally. The partial shell run passed 7 assertions before hitting mapfile.
That gap is environmental rather than a portability defect, which I did check: the production script uses no bash-4 features — only the test file does — and CI's deploy-scripts job runs on ubuntu-latest. So the suite results rest on CI, which is green across all 13 checks.
I also have not independently confirmed the live-VM acceptance run described in the body; I am taking that as reported.
Areas reviewed: Shell (setup-vm.sh + tests), systemd units, TypeScript (control-plane, knative-server, mocactl), env templates, docs
Commits: 16, all signed-off
CI: all 13 checks passing
Verdict: APPROVE
Closes #366 (VM demo A, epic #370).
Summary
sudo ./deploy/vm/setup-vm.shnow installs and runs the MU1 control plane (sh-control-plane.service) next tosh-supervisorandsh-relay.mocactlcan then log in and create sessions against a single P6 VM.Decisions (the ones #366 asked for)
control-plane.envare installed and the secrets are generated on every VM. The unit is started only onceSH_GITHUB_CLIENT_IDandSH_PUBLIC_HARNESS_URLare set; until then it is enabled and try-restarted, following the supervisor's rule.LoadCredential=now.credentialValue/withCredentialsinpackages/control-plane/src/systemd-credentials.ts, resolves$CREDENTIALS_DIRECTORY/<NAME>first and falls back to the env var.SH_CONTROL_PLANE_HOST; the VM ships127.0.0.1:8090.SH_PUBLIC_HARNESS_URL).After=podman-restart.service, as ordering only.setup-vm.sh
ensure_mu1_secretsgenerates the secrets once with the checkout's owngenkeys.ts. They go into root-only files (dir 0700, files 0600) under/etc/serverless-harness/credentials/, and a re-run never rotates one. It refuses, writing nothing, when:require_systemd 247guardsLoadCredential=.wire_supervisor_mu1writes the public keyset,SH_CONTROL_PLANE_URLandSH_REQUIRE_AUTH=trueintosupervisor.env, only on the run that generates the keypair. An operator's laterSH_REQUIRE_AUTH=falsesurvives re-runs.set_env_lineandwrite_secretare all-or-nothing, even when errexit is suspended./v1/sessions/{id}/resourceson a VM answersphase: "unknown"(no kubectl), which is now pinned by a test. mocactl doesn't use it.Upgrade note
An upgraded VM refuses
/turnwithout a session token (SH_REQUIRE_AUTH=true). Drivers that call it bare, such as E8, needSH_REQUIRE_AUTH=falseset back.deploy/vm/README.mdcovers this under "Upgrading an existing VM".Pre-flight: boot contracts that changed
packages/control-plane/src/main.tswithCredentials(a copy, never written back toprocess.env); newSH_CONTROL_PLANE_HOSTpackages/control-plane/src/server.tsstartControlPlane(deps, port, host?)packages/knative-serverturn-auth / server-processSH_EXCHANGE_TOKENviacredentialValue, with a boot-time checkdeploy/vm/systemd/sh-control-plane.servicedeploy/vm/systemd/sh-supervisor.service+LoadCredential=SH_EXCHANGE_TOKENdeploy/vm/env/control-plane.env.exampledeploy/vm/env/supervisor.env.exampleSH_REQUIRE_AUTH=true, exchange-token line removeddeploy/compose/tests/compose.test.shSH_REQUIRE_AUTH=false(compose behaviour unchanged)packages/mocactlsetup-vm.sh; README troubleshooting fixedKnative and compose set no
CREDENTIALS_DIRECTORYand noSH_CONTROL_PLANE_HOST, so their code paths are unchanged.Test plan
make test(all packages plusmake test-deploy) greenmake typecheck,make lint,shellcheckondeploy/vm/*.shgreencontrol-plane 390 passed / 3 skipped; knative-server 411 passed; supervisor 117 passed / 2 skipped; mocactl 477 passed / 2 skipped
deploy/vm/tests/setup-vm.test.sh: unit and templates installed; secrets generated once and unchanged on re-run; the realgenkeys.tskid matches its private key (guarded, skipped without tsx); every refusal writes nothing;main()end to end for a fresh install, a re-run and an upgrade from the pre-change templateLive acceptance on a real systemd VM (Amazon Linux 2023, systemd 252, podman-static 6.1.2); results in this comment:
readyz200, andmocactl … doctor✓ all 7, including "harness located" and "harness trusts this control plane";LoadCredential=delivery, file-store writes underProtectSystem=strict, and workers reading$CREDENTIALS_DIRECTORYwere all confirmed.Two issues found there are fixed in 40411b0.
Known limits and follow-ups
LoadCredential=is not a user boundary. All three units run asharness. A dedicated control-plane user is a follow-up.SH_CREDENTIAL_STORE=vault) is not wired here; it's a follow-up under MU1 follow-ups from #348: VM control plane on Vault, dev identity provider, inference-credential binding #362 item 1.supervisor.envconfigured for it.sudo env PATH="/usr/local/bin:$PATH" ./deploy/vm/setup-vm.sh.setup-vm.shnames this fix when it can't find podman.🤖 Generated with Claude Code