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
+32
View File
@@ -55,6 +55,38 @@ of a qualifying administrator — e.g. after demoting the last one — never
re-opens promotion through signup. Recovery is operator-driven
(`ADMIN_EMAILS` + `make seed`, or promotion by an existing admin).
### API keys (MCP / machine clients)
Personal long-lived Bearer credentials (`sb_` + 43 base64url characters) for
non-browser clients: the `superbrain-mcp` server (see `mcp/`), the federated
`mcpserver` gateway, or plain REST scripts. A key authenticates **every data
endpoint** below as its owner — same ownership rules, same 401/403/404
semantics — with `Authorization: Bearer sb_...` instead of a cookie. Only
the SHA-256 hash is stored; the plaintext is returned exactly once, by POST.
| Method | Path | Returns |
|---|---|---|
| GET | `/api/keys` | `{keys:[{id,name,prefix,createdAt,lastUsedAt}],allowed}` — never the hash or a plaintext; `allowed` reports whether the caller's plan includes the `mcp-core` connector |
| POST | `/api/keys` | 201 `{id,name,prefix,createdAt,lastUsedAt,key}` — the one and only plaintext reveal; body `{name}` (1–100 chars); **403** when the plan lacks `mcp-core`; **400** past the cap of 10 live keys |
| DELETE | `/api/keys/{id}` | `{ok:true}`; revocation is deletion and takes effect immediately. 404 for another user's key |
Rules and deliberate semantics:
- Keys require the `mcp-core` connector (entitlements catalog: core plan) at
**creation AND at every use** — a plan downgrade answers 403 on an
otherwise valid key (the notify creation+delivery discipline).
- Keys are independent of `tokenVersion`: "sign out everywhere" revokes
browser sessions and assertions but NOT API keys, so a gateway link
survives a password change. Machine credentials are revoked explicitly,
by deleting the key.
- API-key requests never impersonate: view-as is cookie-driven and stays
browser-only.
- The Next.js web proxy signs browser assertions and does not forward
client-supplied `Authorization` headers, so keys only work against the Go
API directly (dev: `http://localhost:8080`; federated core:
`http://superbrain-app:8080` on the `core` network).
- `lastUsedAt` is updated at most once a minute per key.
## Bookmarks
Bookmark responses are permission-specific. Owners receive camelCase scalar