Api key management — production auth for admin#359
Open
clintjeff2 wants to merge 2 commits into
Hidden character warning
The head ref may contain hidden characters: "API-key-management-\u2014-production-auth-for-admin"
Open
Conversation
…entication Add API key auth management (scoped service keys, admin UI, middleware)
|
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.



Motivation
Description
lib/auth/api-keys.tsimplementing key generation, hashed storage, prefix display, rotation, revocation, expiry, last-used timestamp, request counting, and extraction fromAuthorization: Beareror?apiKey=.lib/auth/middleware.tswhich maps routes to required scopes, validates keys (including anADMIN_API_KEYfallback), and enforces tiered rate limits (anonymous 10/min, free 60/min, pro 600/min, admin unlimited) using the existinglib/rate-limithelper.middleware.tsto apply the new auth middleware for/api/*and/admin/*routes viaapplyApiAuth.app/api/admin/keysplusPOSTsubroutes torotateandrevokekeys, and an admin UI page atapp/admin/keys/page.tsxto list/manage keys.lib/auth.tsintolib/auth/index.tsand add unit tests inlib/auth/api-keys.test.tscovering key creation and scoped validation.Testing
npm test -- --run lib/auth/api-keys.test.ts, and the new auth tests passed (2 tests).npx eslint middleware.ts lib/auth app/api/admin/keys app/admin/keysfor the introduced files and no new lint errors were reported for those files.npx tsc --noEmitwhich surfaced pre-existing unrelated TypeScript errors (inapp/api/agents/[id]/tasks/drain/route.ts,lib/wallet-config.ts, andtests/lib/agents/task-drain.test.ts) that are outside this change.npm run lintalso reported unrelated existing lint issues (not introduced by this PR) inapp/offline/page.tsxandlib/passport/validator-client.ts.Closes #39