Feature/role based apikeys - #34
Conversation
- api_keys.role: enum(dashboard, production, test), default dashboard - events.mode: enum(test, production), default production - users.mode: enum(test, production), default production - sessions.mode: enum(test, production), default production
- keyFormat.ts: parseRoleFromApiKey, isValidApiKeyFormat, getModeForRole - generateAPIKey(role): scrn_dash_, scrn_live_, scrn_test_ prefixes (42 chars total) - generateInitialApiKey: dashboard key with scrn_dash_ prefix and role in SQL
…, handlers - apiKeysTable: add role column (dashboard/production/test) - eventsTable, usersTable, sessionsTable: add mode column (test/production) - keyFormat.ts: prefix-based role parsing (scrn_dash_, scrn_live_, scrn_test_) - auth interceptor: parse role from prefix, set AuthContext with apiKeyId+role+mode - requireRole() guard for endpoint-level permission enforcement - authenticateHttpApiKey: returns AuthContext with role/mode - apiKeyCache: stores role and mode - AuthError: add permissionDenied, invalidRole, roleMismatch - createAPIKey: dashboard-only, accepts role, generates role-prefixed keys - registerEvent, streamEvents: reject dashboard keys, pass mode to storage - createCheckoutLink: production-only, pass mode to storage - generateAPIKey(role): scrn_dash_/scrn_live_/scrn_test_ prefixes - generateInitialAPIKey: dashboard key with scrn_dash_ prefix - createApiKey helper: accepts role param - findApiKeyByHash: returns role - eventHelpers: storeEvent accepts AuthContext, passes mode to storage - Zod: createAPIKeySchema includes role field BREAKING: Key format changes from scrn_ (37 chars) to scrn_dash_/scrn_live_/scrn_test_ (42 chars). Existing keys invalid.
CreateAPIKey now requires a valid dashboard key. Previously it was whitelisted with no auth, causing the handler to fail with 'API key context not found' since the interceptor never set the context.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (19)
📝 WalkthroughWalkthroughThis PR implements a role-based authorization system for API keys across authentication, gRPC interception, and route handlers. It introduces role types (dashboard, production, test), updates database schemas with role and mode columns, refactors API key generation to derive keys from roles, and enforces authorization checks at key creation, event ingestion, and checkout endpoints. ChangesRole-Based Authorization Implementation
Proto Submodule Update
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
Signed-off-by: Devyash Saini <dysaini2004@gmail.com>
Summary by CodeRabbit
New Features
Chores