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
+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"
}