Conversation
|
@oycodes Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch has not been deployed
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.
Overview
This PR replaces the single global
API_KEYenv-var check with per-tenant API keys stored in the database, scoped to tenant and permission scopes, with expiry and last-used tracking. Cross-tenant key replay is now rejected, keys can be rotated per tenant without downtime, and the legacy single-key path still works via a deprecated fallback.Related Issue
Changes
🔐 Per-Tenant API Key Storage
[MODIFY]
backend/prisma/schema.prismaapiKeymodel keyed bytenantIdwithhashedKey,scopes[],expiresAt, andlastUsedAt, plus the relation back to the tenant.[ADD]
backend/src/services/apiKeyService.tsexpiresAt, enforces requiredscopes, and updateslastUsedAton successful use.🛡️ Tenant-Scoped Authentication Middleware
[MODIFY]
backend/src/middleware/apiKeyAuth.tstenantIdfrom the request path/query, validates the presented key against that tenant's storedhashedKey, and verifies the route's required scope is present inscopes[].401withAPI_KEY_EXPIREDorSCOPE_INSUFFICIENTand aWWW-Authenticateheader on failure.API_KEYenv var when no per-tenant key exists, emitting a deprecation log.[MODIFY]
backend/src/middleware/tenantBoundary.ts🗄️ Migration & Config
[MODIFY]
backend/scripts/canary-migration-check.tsapiKeytable.[MODIFY]
backend/scripts/check-migrations.jsapiKeytable.[MODIFY]
backend/.env.exampleAPI_KEYfallback as deprecated.Verification Results
apiKeypertenantIdwithhashedKey,scopes[],expiresAt,lastUsedAtschema.prismaand handled inapiKeyService.tstenantIdfrom path/query and validates required scopeapiKeyAuth.tsresolves tenant and enforces scopesAPI_KEY_EXPIRED/SCOPE_INSUFFICIENTwithWWW-AuthenticateCloses #1446