Add personal API keys, superbrain-mcp, and fix Markdown prose styling

API keys & MCP (the mcpserver-link prerequisite from STRATEGY.md):
- ApiKey table (migration 017 + schema.sql): hash-only storage of personal
  "sb_..." Bearer credentials, unique keyHash, owner cascade.
- internal/auth/apikeys.go + AuthMiddleware fork: keys resolve before the
  assertion/cookie channels; gated on the mcp-core connector at issuance
  AND at every use (downgrade 403s); independent of tokenVersion so "sign
  out everywhere" never breaks a gateway link; view-as stays browser-only.
- /api/keys GET/POST/DELETE: plaintext shown exactly once, 10-key cap under
  the user lock, owner-scoped revocation; Settings -> API Keys tab.
- mcp/: superbrain-mcp, a pip-installable stdio MCP server (listmonk-mcp
  pattern) with bookmarks/tags/pages tools, version-safe updates; the
  federated gateway spawns it via config_mcpserver_superbrain() in
  deploy/federated/lib-superbrain.sh (mints the gateway key in-db, points
  it at http://superbrain-app:8080). STRATEGY.md records the remaining
  suite-side registry work.
- Tests: TestAPIKeys (plan gate, cap, revocation, tokenVersion semantics,
  downgrade-at-use); full DB-backed suite, db-converge, live MCP-client
  smoke all pass.

Markdown (Gitea issue #3): add @tailwindcss/typography and enable it in
tailwind.config.ts. The prose wrapper was a no-op without it, so Tailwind
Preflight flattened headings/blockquotes to body text while bold/italic
survived - exactly the reported symptom. Verified in the built CSS.

Gitea: #2 and #3 closed with reference notes; #1 stays open pending the
Superpanel core-AI walkthrough.
This commit is contained in:
Andrew S Erwin
2026-11-02 14:27:58 -06:00
parent febc7b2195
commit e6ab778bd5
20 changed files with 1283 additions and 14 deletions
+34 -7
View File
@@ -261,14 +261,41 @@ password-less (ADMIN via `ADMIN_EMAILS`), first SSO login links by verified
email; everyone else is provisioned by Superpanel → LDAP → Authelia and
auto-provisions on first login.
### mcpserver link: drop for now
### mcpserver link: implemented (supersedes "drop for now")
The n8n-template `config_mcpserver_superbrain` (minting an HS256 public-API
JWT from `deployment_key`, inserting into `user_api_keys`, n8n scope list)
describes n8n's schema and does not apply to this codebase — Superbrain has no
equivalent long-lived API-key surface yet (browser sessions + 60s Bearer
assertions only). Remove it from `lib/superbrain.sh` until/unless Superbrain
grows a real API-key mechanism; revisit then.
The old decision — drop the n8n-shaped template until Superbrain grows a
real API-key mechanism — is resolved. Superbrain now has:
1. **Personal API keys** (`ApiKey` table, migration 017; `sb_...` Bearer
tokens accepted by the Go API's auth middleware, hash-only storage,
Settings → API Keys UI). Issuance AND use are gated on the tenant's
`mcp-core` connector — the core plan, which `TIER=core` derives, includes
it. Keys are deliberately independent of `tokenVersion` ("sign out
everywhere" must not break the gateway); revocation is deleting the key.
2. **`superbrain-mcp`** (`mcp/` in the repo): a pip-installable stdio MCP
server in the listmonk-mcp mold — env-configured (`SUPERBRAIN_API_URL`,
`SUPERBRAIN_API_KEY`), bookmarks/tags/pages tools, version-safe updates.
3. **`config_mcpserver_superbrain()`** in `lib-superbrain.sh`: mints a
dedicated `mcpserver` key for the admin account directly in the database
(immich/plane pattern — the keys API is session-gated and the core-tier
operator account is password-less), idempotent rotation, and points the
gateway at `http://superbrain-app:8080` (container-name DNS on `core`;
the web proxy signs browser assertions and never forwards a Bearer key,
so the gateway must talk to the app container directly — no traefik
hairpin needed since the app speaks plain HTTP internally).
Suite-side work items to finish the link (NOT in this repo):
- `/federated/lib/mcpserver.sh`: add `superbrain` to `MCPSERVER_APPS` and
`mcpserver_app_env_var() { superbrain) echo "SUPERBRAIN_API_URL" ;; }` —
the restart/uninstall machinery keys off both.
- mcpserver image repo: add the `apps_registry.py` entry
(`"superbrain": {"required_env": "SUPERBRAIN_API_URL",
"command": "superbrain-mcp", "args": []}`) and install the package into
the image (pipx like the other Python servers; publish `superbrain-mcp`
to PyPI or vendor it from the repo's `mcp/` directory).
- Then on a core: `/federated/bin/installapp-mcpserver superbrain` links it
and `mcphub`/Hermes pick the tools up like every other app.
### Not applicable
+61 -1
View File
@@ -48,7 +48,7 @@ SUPERBRAIN_APP_IP="192.168.0.94"
SUPERBRAIN_MIGRATE_IP="192.168.0.95"
# Release to install; the generic `upgrade` flow keeps .env in step with the
# service file's VERSION afterwards.
SUPERBRAIN_IMAGE_VERSION="1.0.1"
SUPERBRAIN_IMAGE_VERSION="1.2.0"
# render_superbrain_compose writes the app-dir compose file. Called by
# config_superbrain (install) and by deploy/federated/update.sh after a lib
@@ -388,3 +388,63 @@ EOF
# POST /api/admin/oidc-link — email match alone is intentionally not proof.
echo -ne "done.\n"
}
# --- mcpserver link ---------------------------------------------------------
# Supersedes the old "drop for now" decision (STRATEGY.md): Superbrain grew
# a real API-key mechanism (personal "sb_..." keys, internal/auth/apikeys.go)
# and ships its own MCP server package (mcp/ in the repo, spawned by the
# gateway as `superbrain-mcp`). Credential minting follows the immich/plane
# house pattern — direct into the app's database — because the keys API is
# session-gated and the operator account on this tier is password-less.
config_mcpserver_superbrain() {
echo -ne "* Linking superbrain into mcpserver.."
local admin_id key hash prefix key_id
admin_id=$(docker exec postgresql psql -U superbrain -d superbrain -t -A \
-c "select id from \"User\" where email='admin@$DOMAIN' limit 1;")
if [ -z "$admin_id" ]; then
echo -ne "failed -- admin@$DOMAIN not found in Superbrain.\n"
return 1
fi
# Key shape (must match internal/auth/apikeys.go): "sb_" + 43 base64url
# chars over 32 random bytes; the database stores only the SHA-256 hash.
key="sb_$(openssl rand 32 | openssl base64 -A | tr '+/' '-_' | tr -d '=')"
hash=$(printf '%s' "$key" | sha256sum | awk '{print $1}')
prefix=${key:0:11}
key_id=$(openssl rand -hex 16)
# Idempotent: relinking rotates cleanly — exactly one dedicated key, the
# old one is deleted first so it never keeps working.
docker exec postgresql psql -U superbrain -d superbrain -c \
"DELETE FROM \"ApiKey\" WHERE \"ownerId\"='$admin_id' AND name='mcpserver';" &>/dev/null
docker exec postgresql psql -U superbrain -d superbrain -c \
"INSERT INTO \"ApiKey\" (id, \"ownerId\", name, prefix, \"keyHash\") VALUES ('$key_id','$admin_id','mcpserver','$prefix','$hash');" &>/dev/null
# The Go API directly, via container-name DNS on the core network. The web
# proxy signs browser assertions and never forwards a Bearer key, and no
# extra_hosts hairpin is needed either: the app container speaks plain HTTP
# internally (only web is traefik-routed). Keys are plan-gated on the
# mcp-core connector — this tier runs TIER=core, whose plan includes it.
set_mcpserver_env SUPERBRAIN_API_URL "http://superbrain-app:8080"
set_mcpserver_env SUPERBRAIN_API_KEY "$key"
echo -ne "done.\n"
}
# Reverses config_mcpserver_superbrain(): deletes the dedicated key and
# mcpserver's env vars. Called by /federated/bin/uninstallapp-mcpserver
# superbrain, and from lib/mcpserver.sh's uninstall_mcpserver() when the
# whole gateway is removed (the &>/dev/null tolerates a dropped database
# during a full superbrain uninstall).
uninstall_mcpserver_superbrain() {
echo -ne "* Unlinking superbrain from mcpserver.."
docker exec postgresql psql -U superbrain -d superbrain -c \
"DELETE FROM \"ApiKey\" WHERE name='mcpserver';" &>/dev/null
unset_mcpserver_env SUPERBRAIN_API_URL
unset_mcpserver_env SUPERBRAIN_API_KEY
echo -ne "done.\n"
}