Skip to content

VM demo A: run the MU1 control plane on deploy/vm (systemd unit, generated secrets) #366

Closed

Description

@pdettori

Part of the VM demo epic (#370). Item A: the other items depend on it.

Goal

sudo ./deploy/vm/setup-vm.sh should also install and start the MU1 control plane next to sh-supervisor and sh-relay, so that mocactl can log in and create sessions against a single P6 VM. Today that can't happen: deploy/vm has no control plane at all.

This is item 1 of #362, narrowed for the demo: the file credential store is the default, and Vault is an option documented as a follow-up.

Current state (verified on main @ 73f1bf4)

  • deploy/vm/systemd/ holds only sh-supervisor.service, sh-relay.service and moca-sandbox-firewall.service, and setup-vm.sh installs only those.
  • deploy/vm/env/supervisor.env.example:30-40 carries the MU1 settings commented out:
    • SH_SESSION_TOKEN_PUBLIC_KEYS
    • SH_CONTROL_PLANE_URL=http://127.0.0.1:8090
    • SH_EXCHANGE_TOKEN
    • SH_REQUIRE_AUTH=false
  • The control plane is packages/control-plane/src/main.ts, run as node --import tsx src/main.ts.
    • It listens on SH_CONTROL_PLANE_PORT (default 8080, which collides with the supervisor, so use 8090 as compose does).
    • It refuses to start without SH_SESSION_TOKEN_PRIVATE_KEY, SH_GITHUB_CLIENT_ID, SH_CREDENTIAL_KEK and SH_EXCHANGE_TOKEN (main.ts:58-65).
    • Optional settings: SH_PUBLIC_HARNESS_URL, SH_DEFAULT_INFERENCE_ENDPOINT, SH_ALLOW_OPERATOR_FALLBACK with SH_OPERATOR_INFERENCE_TOKEN, REDIS_URL, SH_ADMIN_SUBJECTS, and SH_CREDENTIAL_STORE=kubernetes|file|vault (main.ts:88-132).
  • Key generation: packages/control-plane/src/genkeys.ts prints the four MU1 secrets on stdout. The private key and KEK go to the control plane, the public keyset to the supervisor, and the exchange token to both.
  • The model to copy is compose (feat: MU1 control plane in the compose trial, with file and Vault credential stores (#348) #364):
    • deploy/compose/install.sh:170-243 generates the keys once and turns the profile on only when SH_GITHUB_CLIENT_ID is set;
    • deploy/compose/docker-compose.yml:113-156 holds the control-plane service;
    • deploy/compose/tests/compose.test.sh has the var-for-var mirror check.
  • Precedent for secrets that are generated once and never rotated: setup-vm.sh's handling of MOCA_RELAY_EXEC_TOKEN (README "Bring it up", step 3).
  • Precedent for the Redis dependency: Redis already runs as a podman container published on 127.0.0.1:6379.
  • Session-scoped discovery: /v1/sessions/{id}/resources shells out to kubectl (handlers.ts:389). On a VM it answers with an error shape. It must not crash anything, and mocactl should degrade gracefully. Check this.

Scope

  1. deploy/vm/systemd/sh-control-plane.service, hardened like the others (User=harness, ProtectSystem=strict, NoNewPrivileges, …).
    • WorkingDirectory is the checkout's packages/control-plane.
    • StateDirectory= holds the file credential store (SH_CREDENTIAL_DIR).
    • The supervisor is ordered only After=network-online.target today. Decide whether the control plane also needs Redis ordering (for example After=podman-restart.service), since it cannot serve without Redis.
  2. deploy/vm/env/control-plane.env.example, with every setting documented.
    • SH_CONTROL_PLANE_PORT=8090
    • SH_CREDENTIAL_STORE=file
    • REDIS_URL
    • SH_PUBLIC_HARNESS_URL: must be the harness URL as clients reach it, so the default is empty and required.
    • SH_GITHUB_CLIENT_ID: its value is item B's concern, but the slot is here.
  3. setup-vm.sh
    • Install the new unit and env file. Like the existing env files, an operator-edited file is never clobbered.
    • Generate the MU1 secrets once, with genkeys.ts run by the checkout's own node. Write each half into the file that needs it: control plane or supervisor.env.
    • A re-run never rotates them. A half-migrated pair of files stops with a message naming both.
    • Uncomment and set the supervisor's MU1 lines and SH_REQUIRE_AUTH=true.
    • Restart what it owns, using the same restart and try-restart rules as today.
    • Decide and document: is the control plane opt-in (SH_GITHUB_CLIENT_ID present, like compose), or always installed?
  4. Secrets custody: follow MI1 §6.7 ("secrets are files, never env vars") where it's cheap, meaning LoadCredential= for the private key, KEK and exchange token. If the control plane can't read secrets from files yet, record that as a follow-up rather than blocking the demo, and say so in the README.
  5. Network exposure: the supervisor (0.0.0.0:8080) and the control plane speak plain HTTP.
    • Document the supported demo topology: an SSH tunnel from each user's laptop, or a cloud firewall allowlist.
    • Say which ports clients need: the control plane, plus the harness via SH_PUBLIC_HARNESS_URL.
    • TLS termination is out of scope, but state it as a limit.
  6. Tests: extend deploy/vm/tests/setup-vm.test.sh:
    • the unit is installed;
    • secrets are generated once and survive a re-run unrotated;
    • both halves agree (the kid in the public keyset matches the private key);
    • the migration path from an existing VM without a control plane works.
  7. Docs: add a deploy/vm/README.md section, a "Upgrading an existing VM" note, and fix packages/mocactl/README.md's troubleshooting text, which says the example does not include the MU1 vars.

Acceptance

  • On a fresh VM, following the README's first-run flow (two invocations), all three units are active and curl -s 127.0.0.1:8090/readyz succeeds.
  • mocactl --control-plane-url http://<vm-or-tunnel>:8090 doctor reports "harness located" and "harness trusts this control plane". It needs a token from item B, or the api token minted as in deploy/compose/smoke.sh:176-185, which is acceptable at this stage.
  • A re-run of setup-vm.sh leaves every secret unchanged.
  • An existing VM without a control plane upgrades by re-running setup-vm.sh.

Out of scope

References

Working conventions (for a fresh session)

  • Workspace: git fetch, then create a worktree from rossoctl/main (never local main), under .worktrees/. Populate and build pi-fork (git submodule update --init --recursive && cd pi-fork && npm ci && npm run build), then pnpm install. A worktree without the pi-fork build does not typecheck.
  • Plans: write the plan with superpowers:writing-plans into docs/plans/<date>-<slug>.md. Plans are gitignored and never committed. Write it in chunks, one append per task. Use docs/plans/2026-09-28-mi1-s1-hardening.md as the model for style and granularity, if you have it locally.
  • Pre-flight table: list every process entrypoint, systemd unit, env example and shell/Go launcher whose boot contract changes, not only TypeScript call sites.
  • Tests: Redis on 6379 must be up. Use each package's own node_modules/.bin/vitest. vitest can exit non-zero with every test green, so grep the log for Errors. Redirect long output to /tmp/kagenti/.... make lint skips untracked files.
  • Commits: git commit -s with Assisted-By: Claude (Anthropic AI) <[email protected]>, never Co-Authored-By.
  • Shared KVM rig ([email protected]): the owner runs tutorials on it. Alert the owner before using it, record a manifest of what you install, and verify cleanup. The rig's podman is a static build (Amazon Linux 2023 packages none).
  • Don't push or open PRs without the owner's go-ahead.

Activity

  1. added
    enhancement
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions