mesa-doc /mesa-pro/docs/control-plane
docs

Control plane

Why

A local, open-source license check is a deterrent, not a hard limit. The authoritative project count/quota must live server-side when the customer requires enforcement.

Contract

Client: src/license/control-plane.mjs (test/control-plane.test.mjs, test/project-cp-client.test.mjs).

methodpathpurpose
GET/healthzliveness {ok,version,time} (no auth)
GET/v1/entitlementseffective projects limit/used, license status
POST/v1/projects/reservereserve a slot; idempotent by project id
POST/v1/projects/releaserelease a slot; idempotent
POST/v1/licenses/checkrevocation/expiry check
  • Auth: bearer token (customer/instance), not the issuer private key. Token → sha256 → tokens table → one license serial. Off-loopback requires HTTPS (client refuses plain HTTP).
  • Reserve is called before base modu new; release only on confirmed deletion/creation failure.
  • Idempotency: repeat reserve/release with the same project id must be safe.
  • Errors: {error, message, requestId} with codes from src/license/control-plane-contract.mjs: QUOTA_EXCEEDED 409, LICENSE_REVOKED / LICENSE_EXPIRED / LICENSE_NOT_FOUND / PROJECT_FORBIDDEN 403, UNAUTHORIZED 401, BAD_REQUEST 400, NOT_FOUND 404, METHOD_NOT_ALLOWED 405, INTERNAL 500, SYNC_UNAVAILABLE 503.

Server (implemented, 2026-11-28)

Single process node:http + node:sqlite (WAL), no runtime dependencies. One token maps to one license; one license holds one project quota. Single instance only — no distributed locks; the upgrade path is a Postgres-backed store behind openControlPlaneStore.

  • Store: src/control-plane/store.mjs (test/control-plane-store.test.mjs) — schema (licenses/projects/reservations/tokens/audit, see the contract module), BEGIN IMMEDIATE reserve with license status/expiry/revocation checks and COUNT(active) vs limits.projects, idempotent release (rows kept for audit), token issue/disable, license import (signature verified when a public key is provided) and revoke, VACUUM INTO backup. A corrupt database fails closed: the process refuses to start.
  • Server: src/control-plane/server.mjs (test/control-plane-server.test.mjs) — routes above, bearer auth, X-Request-Id echo, 1MB JSON body limit, audit rows per action, JSON access logs. Logs carry requestId/action/project id/serial/result and the dir basename only — never the token, the raw license envelope, or absolute paths.
  • Admin CLI: mesa-control-plane (src/control-plane/cli.mjs) — serve, license import, license revoke, token issue/disable, backup, health, sync.
  • Tests: test/control-plane-e2e.test.mjs runs the full chain in a subprocess: sign license → import → mesa-project create → MCP project_create → release → quota recovered, then SIGKILL/restart consistency (no double spend).

Configuration

# server
MESA_CONTROL_PLANE_LISTEN=127.0.0.1:7331          # default; non-loopback must sit behind TLS
MESA_CONTROL_PLANE_DB=~/.mesa-control-plane/control.db
MESA_CONTROL_PLANE_TOKENS_FILE=~/.mesa-control-plane/tokens.json
MESA_LICENSE_PUBLIC_KEY=<base64>                  # optional: verify signatures at import time

# client (existing)
MESA_CONTROL_PLANE_URL=https://control.example.com
MESA_CONTROL_PLANE_TOKEN=<token>
  • tokens.json stores tokenSha256 hashes only, mode 0600; the raw token is printed once at issue time. The file is a bootstrap/issuance surface: serve upserts it into the tokens table without touching DB-side disabled.
  • Deployment shape: single process + SQLite volume + TLS reverse proxy; loopback by default.
  • Backup: mesa-control-plane backup --out <file> (online VACUUM INTO); restore drill is in runbook.md.

Integrated client

  • No control plane configured → local advisory quota only (registry vs limits.projects).
  • Configured → the server-side reserve is authoritative; the local registry is a cache and must not reject creation when it is stale. Unreachable control plane fails creation closed with SYNC_UNAVAILABLE (reads/edits stay available); base modu new failure releases the slot.
  • mesa-project release --id/--dir returns a slot (and drops the registry entry); mesa-project reconcile is a read-only cache-vs-server drift report.
  • MCP project_create reuses createProject, so MESA_CONTROL_PLANE_* are read from the MCP process env.

Machine shape: src/license/control-plane-contract.mjs (test/control-plane-contract.test.mjs).

Not implemented (deliberate)

  • multi-instance / HA store;
  • admin UI (CP-UI) and billing integration.

CP-SYNC(吊销列表同步)

  • 源文件形态:单行 base64(payload).base64(sig),Ed25519 签名;payload {version:1,issuedAt,entries:[{serial,revokedAt,reason}]},revokedAt/reason 必填,serial 不可重复(见 src/license/revocation.mjs)。
  • 公钥来源:--public-key <base64>(32 字节 raw Ed25519 public key,base64)或环境变量 MODU_LICENSE_PUBLIC_KEY。
  • 一次性:mesa-control-plane sync --file <signed> [--public-key <base64>] [--json] [--db <file>];成功退出 0,签名/形状非法退出 1,缺 --file/--public-key 退出 2;--json 输出 {ok,issuedAt,total,changed,applied}。
  • 常驻:mesa-control-plane serve --sync-file <signed> [--sync-interval <ms>] [--public-key <base64>];server 起来后立即跑一次,再按间隔(默认 60000ms)轮询文件,定时器 unref(),SIGINT/SIGTERM 先停止同步再关服务。
  • 失败策略:签名或形状非法 → 整批不应用(fail-closed);读文件失败记日志不退出;单条已吊销幂等跳过(changed 不计入)。
  • 落库:store.applyRevocation 落成 revoked 行 + license.revoke 审计(ok:sync[:reason]);不改 revokeLicense 操作员语义(要求 license 存在)。
  • 已同步吊销的 serial 即使尚未导入任何 license,importLicense 也会拒绝(LICENSE_REVOKED,fail-closed);吊销先于导入到达不会丢失。

多实例升级路径(当前仍单实例 MVP)

  • 现状:node:sqlite 单文件 + WAL、单进程单写者;reserve 在 BEGIN IMMEDIATE 内原子检查 + 插入;reserve/release 幂等键;无分布式锁。
  • 本期不实现多实例/HA;勿把同一 db 文件挂给两个进程。
  • 升级到多实例的前置条件:共享存储后端(如 Postgres);跨进程租约或外部唯一约束替代 BEGIN IMMEDIATE;token/audit 表同步;reserve 并发语义在共享后端重新验证。
  • 迁移步骤草案:
    1. 冻结写入;
    2. mesa-control-plane backup --out 导出并恢复到共享库;
    3. schema 迁移(user_version);
    4. 全实例指向同一后端;
    5. 重跑并发配额测试后放开写入。
  • 明确不做:本期不实现多实例、不提供自动 failover、不承诺 HA。

源文件 · mesa-pro/docs/control-plane.md