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).
| method | path | purpose |
|---|---|---|
| GET | /healthz | liveness {ok,version,time} (no auth) |
| GET | /v1/entitlements | effective projects limit/used, license status |
| POST | /v1/projects/reserve | reserve a slot; idempotent by project id |
| POST | /v1/projects/release | release a slot; idempotent |
| POST | /v1/licenses/check | revocation/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 fromsrc/license/control-plane-contract.mjs:QUOTA_EXCEEDED409,LICENSE_REVOKED/LICENSE_EXPIRED/LICENSE_NOT_FOUND/PROJECT_FORBIDDEN403,UNAUTHORIZED401,BAD_REQUEST400,NOT_FOUND404,METHOD_NOT_ALLOWED405,INTERNAL500,SYNC_UNAVAILABLE503.
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 IMMEDIATEreserve with license status/expiry/revocation checks andCOUNT(active)vslimits.projects, idempotent release (rows kept for audit), token issue/disable, license import (signature verified when a public key is provided) and revoke,VACUUM INTObackup. 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-Idecho, 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.mjsruns the full chain in a subprocess: sign license → import →mesa-project create→ MCPproject_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.jsonstorestokenSha256hashes only, mode 0600; the raw token is printed once at issue time. The file is a bootstrap/issuance surface:serveupserts it into the tokens table without touching DB-sidedisabled.- Deployment shape: single process + SQLite volume + TLS reverse proxy; loopback by default.
- Backup:
mesa-control-plane backup --out <file>(onlineVACUUM 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); basemodu newfailure releases the slot. mesa-project release --id/--dirreturns a slot (and drops the registry entry);mesa-project reconcileis a read-only cache-vs-server drift report.- MCP
project_createreusescreateProject, soMESA_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 并发语义在共享后端重新验证。 - 迁移步骤草案:
- 冻结写入;
mesa-control-plane backup --out导出并恢复到共享库;- schema 迁移(
user_version); - 全实例指向同一后端;
- 重跑并发配额测试后放开写入。
- 明确不做:本期不实现多实例、不提供自动 failover、不承诺 HA。
源文件 · mesa-pro/docs/control-plane.md