Skip to content

Compose deployment: add a control plane so mocactl works (credential store without Kubernetes, MU1 auth wiring) #348

Closed

Description

@pdettori

Summary

mocactl (PR #347) cannot be used with the Docker Compose trial deployment (deploy/compose/). The compose stack runs only the harness side: supervisor and workers, relay, Redis and one sandbox. It has no control plane, and mocactl needs one for login, sessions, credentials and session tokens.

Adding a control plane is more than one extra service. This issue lists every gap, most blocking first.

Gaps

1. No control-plane service in compose (blocking, small)

The harness image already contains packages/control-plane, so this is one service:

  • on the shared Redis
  • published on loopback only (e.g. 127.0.0.1:${SH_CP_PORT:-8090}), like the supervisor

2. The control plane can only store credentials in Kubernetes (blocking, the one real code change)

  • depsFromEnv wires K8sSecretStore, which writes Kubernetes Secrets through kubectl. The only other CredentialStore is InMemoryCredentialStore, for tests. Compose has neither Kubernetes nor kubectl.
  • Needed: a CredentialStore that doesn't need Kubernetes, selected by configuration. It should reuse the existing envelope encryption (envelope.ts, SH_CREDENTIAL_KEK).
    • File store on a named volume (recommended): credentials survive docker compose down.
    • Redis store: simpler, but compose's Redis has no volume, so a down wipes every user's credentials.
  • It must keep the store's invariants: exact-name lookup only, and a list that decrypts nothing (credential-store.ts, spec §6.5).
  • Not blocking: the /v1/sessions/{id}/resources sandbox lookup also uses kubectl, but it degrades gracefully and mocactl never calls it.

3. The supervisor lacks the MU1 auth settings, so every mocactl turn fails (blocking)

  • Settings to add: SH_SESSION_TOKEN_PUBLIC_KEYS, SH_CONTROL_PLANE_URL=http://control-plane:8080, SH_EXCHANGE_TOKEN, SH_REQUIRE_AUTH.
  • Why turns fail rather than degrade: resolveTurnAuth (packages/knative-server/src/turn-auth.ts) rejects a present-but-invalid token even with SH_REQUIRE_AUTH=false. mocactl always sends a session token, so turns fail with token_invalid rather than falling back to the operator's key. mocactl doctor check 7 reports exactly this.
  • Fix the VM env too: the compose environment mirrors deploy/vm/env/*.env.example setting for setting, and deploy/compose/tests/compose.test.sh enforces that. So the fix belongs in deploy/vm/env/supervisor.env.example as well. The P6/VM path has this same gap today.

4. install.sh must generate the new secrets (blocking)

It already generates SH_RELAY_TOKEN into .env (mode 0600, written once). It would also need to write:

  • an ed25519 signing key (SH_SESSION_TOKEN_PRIVATE_KEY), with its public half published to the supervisor as SH_SESSION_TOKEN_PUBLIC_KEYS (kid:base64-DER)
  • SH_CREDENTIAL_KEK (32 random bytes, base64)
  • SH_EXCHANGE_TOKEN

It shouldn't assume openssl exists on the host; node inside the image can generate all three. tests/install.test.sh must cover them, including the rule that a re-run never overwrites them.

5. Addressing: set the advertised harness URL

Discovery (GET /v1/discovery, PR #347) makes this one setting on the control plane:

SH_PUBLIC_HARNESS_URL=http://127.0.0.1:${SH_PORT:-8080}

That is the harness as the user reaches it. The supervisor reaches the control plane by service name (item 3). The user then gives mocactl a single URL, http://127.0.0.1:8090.

6. Login requires a GitHub OAuth app (needs a decision)

Device-flow login needs SH_GITHUB_CLIENT_ID, from an OAuth app with device flow enabled (it is off by default), plus internet access. That is real friction for a "five-minute trial". The options:

  • (a) Document the one-time app registration and pass the client ID through install.sh.
  • (b) Add an opt-in, loopback-only, single-user development identity provider for trials.

(b) is security-sensitive. It must never be the default, it must refuse to start on a non-loopback bind, and it needs its own ADR.

7. Model credentials change hands

  • Today: compose passes the operator's ANTHROPIC_API_KEY straight to the workers.
  • Under MU1: each user stores their own inference credential, which mocactl onboarding prompts for.
  • To keep a one-key trial: compose can set SH_ALLOW_OPERATOR_FALLBACK=true, SH_OPERATOR_INFERENCE_TOKEN and SH_DEFAULT_INFERENCE_ENDPOINT on the control plane. The README must say what that fallback means: every user spends the operator's key.

Already fine

  • Streaming: SSE through the supervisor's socket handoff is integration-tested (packages/supervisor/test/handoff.integration.test.ts).
  • Same handler: the supervisor serves POST /v1/turn and GET /health with the same handler as the Knative path.
  • Not yet exercised: deploy/compose/smoke.sh only calls plain /turn. The acceptance criteria below add /v1/turn streaming.

Acceptance criteria

  • install.sh brings up the stack with a control plane, and mocactl --control-plane-url http://127.0.0.1:8090 needs no other URL. Doctor reports "harness located — http://127.0.0.1:8080 (advertised by the control plane)".
  • mocactl login → mocactl doctor passes all 7 checks → mocactl run "hello" streams a reply.
  • A stored credential survives docker compose down && up (if the file store is chosen).
  • compose.test.sh and install.test.sh cover the new service, settings and generated secrets. deploy/vm/env/*.env.example carries the MU1 settings.
  • smoke.sh exercises an authenticated POST /v1/turn with Accept: text/event-stream.

Related: #347 (mocactl, GET /v1/discovery).

Activity

  1. pdettori commented on Sep 29, 2026

    @pdettori
    MemberAuthor

    The multi-user isolation design (MI1) is now public in #350: docs/specs/2026-09-28-moca-multi-user-isolation-design.md. Its §10.3 covers this issue.

    This issue's goal and most of its items stand. Four things change:

    • Placement. The control plane and Redis join the compose moca-brain network only, never the sandbox network. fix: MI1 S1 — multi-user isolation hardening (R1–R8) #350 already splits compose into moca-brain (Redis, supervisor) and moca-sandbox (sandboxes), with only the relay on both.
    • Secrets as files. install.sh should write the session-token signing key, the KEK and the exchange token to files mounted as compose secrets: (mode 0600), not into .env. It should be structured so the later slices' keys can slot in next to them: the grant key ring, moca-egress's client credential, and per-sandbox tokens. The relay exec token that fix: MI1 S1 — multi-user isolation hardening (R1–R8) #350 adds (MOCA_RELAY_EXEC_TOKEN) is an environment variable for now and moves to a file with MI1's slice S2.
    • Tenancy. Compose ships as MOCA_TENANCY=single. Item 7 (users' own inference credentials in direct mode, plus the operator fallback) is safe there because the control plane pins the first subject that creates a session and refuses any other with 403 single_tenant_deployment. Multi-user compose arrives with MI1's slices S2 and S5.
    • Order. This issue adds SH_EXCHANGE_TOKEN to the worker environment, so it should land with or after fix: MI1 S1 — multi-user isolation hardening (R1–R8) #350, never before: fix: MI1 S1 — multi-user isolation hardening (R1–R8) #350 makes sandbox commands receive an explicit environment allowlist instead of the worker's environment.

    Two more points:

    • The development identity provider (item 6b) must refuse to start under MOCA_TENANCY=multi.
    • Item 2, the Kubernetes-free CredentialStore, is what MI1's slice S2 (grants and the token endpoint) builds on, so it is on MI1's critical path.
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions