Automation clients and coding agents authenticate to /api/v1/* and /mcp using Personal Access Tokens (PATs) prefixed with od_pat_. Every token is bound to its owning CMS user role, constrained by explicit scopes, blocked from high-risk operational routes by a hard Bearer deny-list, and logged for audit.
Token Format, Hashing & Storage Caps
OpenDash generates random 64-character hex secrets formatted as od_pat_<64-hex>, accompanied by a lookup identifier tok_<24-hex>. Only the 15-character prefix and a SHA-256 hash are stored in SQLite; the plaintext secret is displayed once at creation and cannot be recovered later.
| Constraint | Value in V1 | Enforcement Source |
|---|---|---|
| Token prefix & ID | od_pat_ / tok_<24-hex> | routes/auth_tokens.rs |
| Token name | 1..=80 characters | Validated on CLI and HTTP |
| Optional expiration | 1..=365 days | expires_days query/flag |
| Active tokens per user | Max 32 active tokens | MAX_ACTIVE_TOKENS_PER_USER |
Creating & Revoking Tokens (Admin UI, HTTP & CLI)
Tokens can be minted from the Connect AI modal in OpenDash Admin (#/users), via the cookie-authenticated Admin HTTP API (GET|POST /api/admin/tokens and DELETE /api/admin/tokens/{id}), or directly on the host with opendash token create.
OPENDASH_SITE_ROOT=/var/lib/opendash opendash token create \
--name "docs-assistant" \
--preset safe_draft_assistant \
--expires-days 30 \
--json
OPENDASH_SITE_ROOT=/var/lib/opendash opendash token create \
--user admin \
--name "seo-proposal-bot" \
--preset custom \
--scopes site:read,content:read,content:write,mcp:access \
--expires-days 90 \
--json
POST /api/admin/tokens HTTP/1.1
Cookie: opendash_session=...
Origin: https://cms.example.com
X-CSRF-Token: <csrf>
Content-Type: application/json
{
"name": "ci-blueprint-runner",
"preset": "full_site_builder",
"expires_days": 60
}
9 Granular Scopes & Built-in Presets
opendash-core::api_auth defines 9 fine-grained scopes alongside a legacy admin scope (which defaults only when neither preset nor scopes is specified, and is explicitly rejected inside custom scope lists).
| Scope / Preset | Granted Capabilities |
|---|---|
site:read | Read site overview, themes, blocks, patterns, locales, and diagnostics |
content:read | List and inspect entries, revisions, terms, redirects, 404 logs, and SEO context |
content:write | Create/update draft entries, terms, redirects, SEO proposals, and sparse SEO metadata |
content:publish | Transition draft_publish entries between draft and published status |
builder:write | Patch Studio block trees (patch_page_blocks, compose_page_from_patterns, builder endpoints) |
design:write | Modify theme options, design tokens, template overrides, menus, reading settings, and Home SEO |
media:write | Upload media assets and edit media title/alt metadata |
schema:write | Apply schema mutations and content structure updates |
mcp:access | Connect to POST|GET|DELETE /mcp sessions (still gated per-tool by mutation scopes) |
Available Presets: read_only (site:read, content:read), safe_draft_assistant (adds content:write, builder:write, media:write, mcp:access while omitting publish, design, and schema writes), full_site_builder (all 9 granular scopes), and custom (explicit non-empty list without duplicates or admin).
Bearer CSRF Exemption vs /mcp Origin & Rate Limits
REST requests authenticated with Authorization: Bearer od_pat_... bypass browser cookie CSRF tokens and Origin checks on /api/v1/*. In contrast, the Streamable HTTP endpoint at /mcp validates any supplied Origin header against the listener origin or trusted_public_origin, limits active sessions to 256 (3600s idle TTL), and caps requests at 120 requests/minute per token.
Hard Bearer Deny-List (forbid_bearer_token)
Inspecting Agent & Bearer Audit Logs
Every mutating API v1 or MCP request invokes record_bearer_audit, recording the token identity, HTTP/tool action, resource kind, and response status. Administrators inspect recent automation trails in the Admin UI or query GET /api/admin/tokens/audit-logs?limit=50 using a browser Admin session.