Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor(self-host): generate Supabase keys with openssl, drop Node dep
Sidwebworks2ced73fdeda9
diff --git a/.claude/rules/contrib-deploying-swarm.md b/.claude/rules/contrib-deploying-swarm.mdindex a18436389f..35c0c950ae 100644--- a/.claude/rules/contrib-deploying-swarm.md+++ b/.claude/rules/contrib-deploying-swarm.md@@ -40,8 +40,8 @@ This **replaced** the old `docker-compose.prod.yml` + `deploy/prod/` compose stashared_buffers, work_mem, effective_cache_size…) from `CARBON_PG_*` env +`pg_stat_statements`. `shared_preload_libraries=pg_stat_statements` is a serverflag in the postgres `command:` (can't be set by ALTER SYSTEM at runtime).-- `scripts/gen-supabase-keys.mjs` — Supabase JWT trio (jwt_secret + anon/service_role- signed with it). Consumed by `deploy.sh init`.+- `scripts/gen-supabase-keys.sh` — Supabase JWT trio (jwt_secret + anon/service_role+ signed with it), HS256 via `openssl` only (no Node). Consumed by `deploy.sh init`.- `scripts/harden.sh` — UFW (SSH+80+443 only), fail2ban, swap, unattended-upgrades.- `scripts/backup.sh` — `pg_dump` (password from the in-container secret) + storagevolume tarball.diff --git a/contrib/deploying/simple-docker-caddy/README.md b/contrib/deploying/simple-docker-caddy/README.mdindex d2879657f3..641ad138e1 100644--- a/contrib/deploying/simple-docker-caddy/README.md+++ b/contrib/deploying/simple-docker-caddy/README.md@@ -28,7 +28,7 @@ $EDITOR .env # hosts, URLs, ACME email, SMTP| `bin/secrets-entrypoint.sh` | Injects Swarm secrets into env (`__SECRET__` placeholders) for each service. || `postgres/01-roles.sh` | Supabase role bootstrap. || `postgres/02-performance.sh` | Postgres tuning + `pg_stat_statements`. |-| `scripts/gen-supabase-keys.mjs` | Generates the Supabase JWT key trio. |+| `scripts/gen-supabase-keys.sh` | Generates the Supabase JWT key trio (openssl only). || `scripts/harden.sh` | Host hardening (UFW, fail2ban, swap, unattended-upgrades). || `scripts/backup.sh` | Postgres dump + storage volume archive. || `.env.example` | Non-secret configuration template. |diff --git a/contrib/deploying/simple-docker-caddy/deploy.sh b/contrib/deploying/simple-docker-caddy/deploy.shindex 5c0eaa7381..0fde369406 100755--- a/contrib/deploying/simple-docker-caddy/deploy.sh+++ b/contrib/deploying/simple-docker-caddy/deploy.sh@@ -53,7 +53,7 @@ create_secret() { printf '%s' "$2" | docker secret create "$1" - >/dev/null && l# ── init ──────────────────────────────────────────────────────────────────────cmd_init() {- require_cmds docker node openssl+ require_cmds docker openssllocal force=0; [ "${1:-}" = "--force" ] && force=1swarm_active || { log "Initializing Docker Swarm"; docker swarm init >/dev/null; }@@ -86,7 +86,7 @@ cmd_init() {elselog "Generating Supabase key trio"local trio jwt anon svc- trio=$(node "$HERE/scripts/gen-supabase-keys.mjs")+ trio=$(bash "$HERE/scripts/gen-supabase-keys.sh")jwt=$(printf '%s\n' "$trio" | sed -n 's/^SUPABASE_JWT_SECRET=//p')anon=$(printf '%s\n' "$trio" | sed -n 's/^SUPABASE_ANON_KEY=//p')svc=$(printf '%s\n' "$trio" | sed -n 's/^SUPABASE_SERVICE_ROLE_KEY=//p')diff --git a/contrib/deploying/simple-docker-caddy/scripts/gen-supabase-keys.mjs b/contrib/deploying/simple-docker-caddy/scripts/gen-supabase-keys.mjsdeleted file mode 100755index aff666599a..0000000000--- a/contrib/deploying/simple-docker-caddy/scripts/gen-supabase-keys.mjs+++ /dev/null@@ -1,51 +0,0 @@-#!/usr/bin/env node-// Generate the Supabase self-host key trio for the Carbon Swarm stack.-//-// SUPABASE_JWT_SECRET — HMAC secret every Supabase service signs/verifies with-// SUPABASE_ANON_KEY — JWT(role=anon) signed with that secret-// SUPABASE_SERVICE_ROLE_KEY — JWT(role=service_role) signed with that secret-//-// The anon/service_role keys MUST be signed with the printed JWT secret — the-// three are a matched set. `deploy.sh init` consumes this output to create the-// `jwt_secret`, `anon_key`, and `service_role_key` Docker secrets together.-// Re-running mints a fresh, incompatible set.-//-// Usage: node scripts/gen-supabase-keys.mjs-// Zero dependencies (Node built-in crypto only).--import { createHmac, randomBytes } from "node:crypto";--const b64url = (buf) =>- Buffer.from(buf)- .toString("base64")- .replace(/\+/g, "-")- .replace(/\//g, "_")- .replace(/=+$/, "");--function signJwt(payload, secret) {- const header = b64url(JSON.stringify({ alg: "HS256", typ: "JWT" }));- const body = b64url(JSON.stringify(payload));- const data = `${header}.${body}`;- const sig = b64url(createHmac("sha256", secret).update(data).digest());- return `${data}.${sig}`;-}--const jwtSecret = randomBytes(32).toString("hex"); // 64 hex chars-const iat = Math.floor(Date.now() / 1000);-const exp = iat + 60 * 60 * 24 * 365 * 10; // 10 years--const anon = signJwt({ role: "anon", iss: "supabase", iat, exp }, jwtSecret);-const service = signJwt(- { role: "service_role", iss: "supabase", iat, exp },- jwtSecret-);--process.stdout.write(- [- "# --- Supabase self-host keys (generated) ---",- `SUPABASE_JWT_SECRET=${jwtSecret}`,- `SUPABASE_ANON_KEY=${anon}`,- `SUPABASE_SERVICE_ROLE_KEY=${service}`,- "",- ].join("\n")-);diff --git a/contrib/deploying/simple-docker-caddy/scripts/gen-supabase-keys.sh b/contrib/deploying/simple-docker-caddy/scripts/gen-supabase-keys.shnew file mode 100755index 0000000000..8b1ae4aa74--- /dev/null+++ b/contrib/deploying/simple-docker-caddy/scripts/gen-supabase-keys.sh@@ -0,0 +1,41 @@+#!/usr/bin/env bash+# Generate the Supabase self-host key trio for the Carbon Swarm stack.+#+# SUPABASE_JWT_SECRET — HMAC secret every Supabase service signs/verifies with+# SUPABASE_ANON_KEY — JWT(role=anon) signed with that secret+# SUPABASE_SERVICE_ROLE_KEY — JWT(role=service_role) signed with that secret+#+# The anon/service_role keys MUST be signed with the printed JWT secret — the+# three are a matched set. `deploy.sh init` consumes this output to create the+# `jwt_secret`, `anon_key`, and `service_role_key` Docker secrets together.+# Re-running mints a fresh, incompatible set.+#+# Usage: ./scripts/gen-supabase-keys.sh+# Dependencies: openssl only (no Node).+set -euo pipefail++# base64url-encode stdin (binary-safe, no line wrap, no padding).+b64url() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }++# sign_jwt <payload-json> <secret> — print the signed HS256 JWT.+sign_jwt() {+ local payload="$1" secret="$2" header data sig+ header=$(printf '%s' '{"alg":"HS256","typ":"JWT"}' | b64url)+ data="$header.$(printf '%s' "$payload" | b64url)"+ sig=$(printf '%s' "$data" | openssl dgst -sha256 -hmac "$secret" -binary | b64url)+ printf '%s.%s' "$data" "$sig"+}++jwt_secret=$(openssl rand -hex 32) # 64 hex chars+iat=$(date +%s)+exp=$((iat + 60 * 60 * 24 * 365 * 10)) # 10 years++anon=$(sign_jwt "{\"role\":\"anon\",\"iss\":\"supabase\",\"iat\":$iat,\"exp\":$exp}" "$jwt_secret")+service=$(sign_jwt "{\"role\":\"service_role\",\"iss\":\"supabase\",\"iat\":$iat,\"exp\":$exp}" "$jwt_secret")++cat <<EOF+# --- Supabase self-host keys (generated) ---+SUPABASE_JWT_SECRET=$jwt_secret+SUPABASE_ANON_KEY=$anon+SUPABASE_SERVICE_ROLE_KEY=$service+EOFdiff --git a/docs/content/docs/platform/self-hosting/docker-caddy.mdx b/docs/content/docs/platform/self-hosting/docker-caddy.mdxindex faa33ae438..35539964fa 100644--- a/docs/content/docs/platform/self-hosting/docker-caddy.mdx+++ b/docs/content/docs/platform/self-hosting/docker-caddy.mdx@@ -30,6 +30,7 @@ Everything for this recipe lives in [`contrib/deploying/simple-docker-caddy`](ht| --- | --- || VPS | Ubuntu 22.04+, **≥ 4 GB RAM** to run the stack. Building images on the host needs **~8 GB** — add swap or build elsewhere. || Docker | Docker Engine with the Compose plugin. |+| OpenSSL | `deploy.sh` uses `openssl` to generate secrets and the Supabase JWT keys (usually already present). || DNS | `A`/`AAAA` records for your ERP, MES, and Supabase hosts pointing at the VPS (needed for Let's Encrypt). || Repo | The Carbon repo checked out on the VPS (default `/opt/carbon`). |