Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

control-plane

The SaaS control plane of VibeChat editions: one Go binary with PocketBase inside. It implements ADR 0003 "Editions" and is measured against the pilot SLOs.

One client, many hosts: every workspace gets its own cell, an unchanged single-user vibechat-server (Studio, /runtime/v1 seam, Pi agent, preview). The control plane only decides who may reach which cell, holds the money and the provider keys, and meters usage. Editions are described by an edition.json made in the configurator. The JSON Schemas of edition.json and license.json are published here in schemas/ (the one source; the configurator vendors a pinned copy), and the rules a schema cannot express are one compatibility table, internal/edition/compat.go (ADR 0004).

flowchart LR
  B[Browser] -->|https| CP[control-plane]
  CP -->|/_cp: accounts, credits, payments, projects| PB[(PocketBase)]
  CP -->|proxy, ticket sign-in| C1[cell: vibechat-server]
  CP -->|proxy| C2[cell: vibechat-server]
  C1 -->|/gw/provider/v1, per-cell token| GW[gateway in control-plane]
  C2 --> GW
  GW -->|operator key, metering| P[(GigaChat, Yandex, OpenRouter, xAI)]
  PAY[YooKassa / Robokassa] -->|webhook| CP
Loading

What is in it

Part Package Notes
Edition loader internal/edition, schemas/ JSON Schema plus the compatibility table (profile x license tier, license host, RU contour, Cursor in SaaS; every rule has an id, an error and a hint), `security: basic
Sign-in internal/auth, internal/web pocketbase adapter (email and password, invite code, consent) and oidc adapter (any issuer in auth.issuers[], client registered by RFC 7591 dynamic registration, PKCE, nonce).
Moderation internal/web Invite-only sign-up, questionnaire, manual approval (control-plane approve), pre-approved invites.
Workspaces, members, projects internal/web, internal/store Projects are created from the edition's templates inside the cell; plan limits (projects, members, sleep) from plans[].limits.
Credits ledger internal/ledger Append-only, unique ref per entry: a replayed webhook or usage record never counts twice.
Billing port internal/billing YooKassa (RUB, 54-FZ receipt) and Robokassa (currency, signatures). mode: fake sends the gateway's own webhook format from a local test checkout; live needs the keys in the environment.
Provider gateway internal/gateway Cells reach providers only through /gw/<provider>/v1 (loopback, per-cell HMAC token). Balance precheck (402), usage metering from the provider's usage (stream too), credits from models[].price or measurement mode (no price: recorded, charged 0), loop guard (the same tool call 8 times in a row stops the run).
Cells internal/cells Driver port: process (one box, tests) and incus (one container per cell; command construction only, not run yet). Wake on demand, sleep after the plan's idle time, wake time recorded (SLO).
Publishing internal/web Vite projects build into a static site at /p/<slug>/ (approved workspaces only).
Installer internal/install, scripts/install.sh Checks an edition.json, writes the env file (names only, no secrets) and the systemd unit; install.sh verifies the release binary against SHA256SUMS.
Edge (tests) internal/edge Several stands behind one public test domain: a cookie picks the stand, /p/<stand>-<id>/ routes by slug.
Test issuer cmd/testissuer TEST ONLY OpenID Connect issuer with dynamic registration.
License internal/license, schemas/license.schema.json Ed25519-signed license.json (tier regular or extended, host, updates period, purchase id only), verified offline with embedded keys; missing, invalid or foreign: base mode (works, one user, no paid content). maxUsers is enforced at sign-up.
Deploy internal/deploy, templates/saas-template control-plane deploy: Git and CI are the control plane of an extended install (ADR 0004).
Secrets at rest internal/secretbox Login provider client secrets encrypted (AES-256-GCM) with CP_MASTER_KEY.
Legal internal/web/legal.go TEMPLATE texts, clearly marked, until a lawyer reviews them.

Run

go build -o control-plane ./cmd/control-plane
export CP_EDITION=./edition.json CP_DATA=./cp-data CP_HTTP=127.0.0.1:8090 CP_PUBLIC_URL=https://app.example.ru
export CP_DRIVER=process CP_SERVER_BIN=/usr/local/bin/vibechat-server CP_PI_DIR=/opt/pi
export VIBECHAT_CLOUDRU_KEY=...   # the provider keys named by the edition's keyEnv
./control-plane serve
./control-plane invite new            # one invite code (only its hash is stored)
./control-plane approve user@example.ru

A production install: sh install.sh --edition ./edition.json (downloads the release binary, checks its sha256, writes /opt/vibebuildy/{edition.json,control-plane.env,control-plane.service}).

Private editions (private-server, private-browser) run vibechat-server alone, with no control plane. For them install.sh also installs the vibechat-server package (Debian 13, amd64; the .deb carries the cursor-sdk-bridge and the sandbox helper next to the binary) and runs control-plane install --apply: it applies the edition (vibechat-server edition apply: every runtime of the edition plus the default) and moves the Cursor key out of the server env file: a CURSOR_API_KEY= value in PREFIX/vibechat-server.env (or in the job's environment) is stored into the server's secrets file with vibechat-server set-key (over stdin; never in argv, logs or output) and removed from the env file. The running server does not read CURSOR_API_KEY from its environment. The owner picks the agents in Studio Settings > Agents.

Routes on the public host: /_cp/ account UI, /_cp/hooks/<gateway> payment webhooks, /_cp/healthz, /p/<slug>/ published sites, everything else proxied to the signed-in user's own cell. /gw/, the PocketBase admin /_/ and /api/ answer only on the machine itself.

Licenses (ADR 0004)

Tier Profiles Users Cursor SDK
regular private-server, private-browser 1 (the owner) the owner's own key
extended saas-ru, saas-eu (and private) unlimited each tenant's own key (byok; planned in the cells)
control-plane license keygen --id KEY-ID --out key.json         # private key 0600, never in a repository
control-plane license issue --tier extended --host app.example.ru --days 365 --licensee PURCHASE-ID --key key.json --out license.json
control-plane license verify --edition edition.json license.json
control-plane edition check --license license.json edition.json  # the compatibility table, with hints
control-plane edition migrate --write edition.json               # upgrade schemaVersion (and old names)

The server reads CP_LICENSE. The binary embeds only the key TEST-2026-1 (test stands, never sold): the production public key is added before the first sale. A version released after the license's updatesUntil runs in base mode; the version you have keeps running.

Emergency access when a login provider is broken: control-plane admin login-link owner@example.ru on the server prints a one-time link (10 minutes, audited).

Deploy from Git

templates/saas-template is the template repository (buildytech/saas-template): edition.json, VERSION, deploy.env, allowed_signers and two thin workflows (deploy, check-update). control-plane deploy does the work:

  1. checks the edition (schema, compatibility table) and the license;
  2. with security hardware or max: the last commit of edition.json must be signed by a key in allowed_signers;
  3. downloads the release (or --from DIR), verifies SHA256SUMS, refuses a release newer than the license's updates;
  4. over SSH (stdin only, no secrets in argv): binary, edition, license, env file (0600; --secrets-age decrypts an age file on the server);
  5. stops the service, snapshots data/ and the replaced files to backups/, swaps, starts, checks health;
  6. on failure restores the snapshot and the previous files, starts again and fails the job. --dry-run prints the plan.

control-plane update check --current vX.Y.Z --channel stable|edge reports a newer release.

Deploy a private edition

The same command deploys a private edition (private-server, private-browser): there is no control plane, so what goes to the server is the vibechat-server package (the .deb of buildytech/vibechat-desktop, checked against its SHA256SUMS; it carries the cursor-sdk-bridge), the control-plane binary (it runs install --apply there), edition.json, license.json and an env file. Tenants, billing and CP_MASTER_KEY do not exist for it. The server must be Debian 13 (trixie), amd64; the SSH user is root or has passwordless sudo (the package is installed with apt-get and the unit is restarted).

On the server, as root: stop the service, snapshot the settings and secrets (contour.json, agents.json, secrets/, auth/; never the projects) and the replaced files, apt-get install the package, run control-plane install --apply (the edition into the contour; CURSOR_API_KEY into the secrets file and out of the env file), write a systemd drop-in (EnvironmentFile, and for private-browser the allowed host and the sign-in form), start, check /runtime/v1/host/hello, and roll back (previous package, files and settings) on failure. On the first install a sign-in token is written to <dir>/first-login-token (root only, never printed): read it once, sign in, delete the file. For private-browser Caddy is installed and serves your domain with automatic TLS to 127.0.0.1:18120 (--tls none or DEPLOY_TLS=none: your own proxy; an existing Caddyfile that this deploy did not write is never overwritten). The A record must point at the server, ports 80 and 443 must be open.

Secret (environment of the job) Needed when
VPS_HOST, VPS_USER, SSH_KEY (file), VPS_KNOWN_HOSTS (file, recommended) always (without a host: dry run)
LICENSE_FILE (license.json) recommended: without it the edition runs in base mode; the license's host must match branding.appDomain
CURSOR_API_KEY cursor-sdk in runtimes; optional (the owner can set it in Settings > Models and keys; when the secret is set, every deploy stores it again)
each providers[].keyEnv pi in runtimes (a provider without its key stays off)

Options: --server-version vX.Y.Z|latest (DEPLOY_SERVER_VERSION; the package release), --version (the control-plane release), --tls caddy|none, --dir, --keep; DEPLOY_STOP, DEPLOY_START and DEPLOY_HEALTH_URL are SaaS settings (a private edition refuses them when they name the control plane). --dry-run checks the edition, the license, downloads and verifies both releases and prints the plan without touching the server.

Test stands

scripts/box-stands.sh starts saas-ru, saas-eu, a private-browser server, the test issuer, the edge and an ngrok tunnel on one box; scripts/e2e_stands.py signs up (pocketbase and OIDC), pays through the fake checkouts, creates Svelte, React and Go templ projects, lets Pi build a site through the gateway, publishes it and checks export, sleep and wake.

Not done yet

  • Login providers are still set in edition.json (auth.issuers); adding them in the cabinet (owner only, audited) is ADR 0004 work not started. Security levels: the field, validation and the signed-commit check exist; TOTP, FIDO2 and TPM ceremonies do not.

  • Per-tenant own Cursor keys (extended, byok) are not wired into the cells: SaaS editions run Pi only.

  • Incus driver not run against a real Incus host; the box tests use the process driver.

  • Live payments: needs the shop keys (YooKassa shop id and secret, Robokassa passwords).

  • In-Studio live preview needs a wildcard preview domain per edition; on a single test domain projects are published instead.

  • Prices: models run in measurement mode until per-model costs are measured (price about 1.5-2x cost).

License

Apache-2.0, see LICENSE and NOTICE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages