feat: add API key management with fine-grained RBAC scopes#208
Open
feat: add API key management with fine-grained RBAC scopes#208
Conversation
Implements a multi-key API key management system for the GoClaw gateway, replacing the single-token auth model with support for multiple API keys each with configurable permission scopes. Backend: - Migration 000019: api_keys table with SHA-256 hashed keys, scopes, expiry, and revocation support - Store layer: APIKeyStore interface + PG implementation with indexed hash lookups and expiry checks - Key generation: goclaw_ prefixed keys with SHA-256 hashing (show once) - Auth integration: HTTP Bearer + WebSocket connect both resolve API keys and derive roles from scopes (admin/read/write/approvals/pairing) - HTTP API: GET/POST/DELETE /v1/api-keys (admin-only) - WebSocket RPC: api_keys.list, api_keys.create, api_keys.revoke - Permissions: all API key methods require admin role Web UI: - API Keys management page with list, create dialog, revoke confirmation - Show-once key display with copy-to-clipboard - Scope checkboxes and configurable expiry (never/7d/30d/90d) - Full i18n support (en/vi/zh) - Sidebar navigation under System group https://claude.ai/code/session_017sg1fT9pN25DsArUxyGxHK
Serve OpenAPI 3.0 spec at /v1/openapi.json and Swagger UI at /docs with embedded spec covering all HTTP endpoints. Add API Docs link to sidebar with i18n support (en/vi/zh). https://claude.ai/code/session_017sg1fT9pN25DsArUxyGxHK
- 18-http-api.md: Complete HTTP REST API reference covering 130+ endpoints across 23 sections (chat, agents, skills, providers, MCP, memory, KG, etc.) - 19-websocket-rpc.md: Full WebSocket RPC method catalog with 64+ methods, permission matrix, event types, and Mermaid flow diagrams - 20-api-keys-auth.md: API key authentication model, RBAC scopes, security design (SHA-256 hashing, show-once), database schema, usage examples - Updated changelog with API keys and docs entries https://claude.ai/code/session_017sg1fT9pN25DsArUxyGxHK
- Features: add API key management to Security section, update Web Dashboard - API section: replace old links with table linking to new docs (HTTP API, WebSocket RPC, API Keys & Auth, Gateway Protocol) + mention Swagger UI - Security section: add API key management entry with doc link - Project Status: add API keys and Swagger UI entries https://claude.ai/code/session_017sg1fT9pN25DsArUxyGxHK
- Move expiry check from Go to SQL WHERE clause (prevent race condition)
- Extract permissions.ValidScope() to deduplicate scope validation
- Change DELETE to POST /v1/api-keys/{id}/revoke (semantic correctness)
- Handle unmarshal error in WS revoke handler
- Remove redundant allKeys field from APIKeysHandler
- Sanitize error messages (no internal err.Error() to client)
- Fix display prefix to use hex part instead of goclaw_ prefix
- Replace raw div overlay with accessible Radix Dialog
OAuth token format (sk-ant-oat01-*) should be passed as anthropic_api_key, not claude_code_oauth_token which expects a different auth flow (OIDC).
Another maintainer is working on migration 19, so bump api_keys migration to 000020 and update RequiredSchemaVersion + doc references accordingly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #207
operator.admin,operator.read,operator.write,operator.approvals,operator.pairing) mapped to 3 roles (Admin/Operator/Viewer)goclaw_prefix format, optional expiration, and soft-revocation/v1/api-keys) and WebSocket RPC (api_keys.list/create/revoke), both admin-only/docs+ comprehensive HTTP/WebSocket/auth docs000019to000020to avoid conflict with concurrent workSecurity
WHEREclause (not application layer)crypto/subtle)permissions.ValidScope()for scope validationerr.Error()leaks)Test plan
connecttoken — verify scopes enforcedexpires_atset correctly/docs