Repository navigation
feat(admin): zero-downtime key rotation with bounded overlap window (#501) - #571
Open
sparkysolutions10-pixel wants to merge 1 commit into
Conversation
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.
Description
Fixes #501.
Summary of Changes
Callers rotating keys previously had to suffer an outage or keep suspected compromised keys active indefinitely.
This PR implements zero-downtime key rotation via
POST /admin/keys/:id/rotate:expiresAttimestamp tonow + overlapHours(configurable via body orKEY_ROTATION_OVERLAP_HOURS, default 24h).lookupApiKeyResultautomatically rejects the old key withexpired(401), while the new key continues seamlessly.label,ratePerMin,ratePerDay,monthlyQuotaCents,dailyQuotaCents, andoveragePolicy.copyUsageHistorytransfers existing daily and monthly usage/cents counters across to the replacement key so rotation does not reset metering or look like a new customer.overlapEndsAtandoverlapHours.KEY_ROTATION_OVERLAP_HOURSin.env.example.INTERNAL_ROUTESinsrc/openapi/coverage.ts.src/__tests__/keyRotation.test.tscovering unauthorized rotation, 404/400 validation, quota/usage inheritance, simultaneous operation during the overlap window, and old key failure post-overlap.Testing
npx vitest run src/__tests__/keyRotation.test.ts(4/4 passed)npx vitest run src/__tests__/auth.test.ts(22/22 passed)npx vitest run tests/openapi.test.ts(8/8 passed)