feat: support METRICS_JWT_JWKS for metrics endpoint auth - #2172
Open
Larslllllll wants to merge 1 commit into
Open
Larslllllll wants to merge 1 commit into
Larslllllll wants to merge 1 commit into
Conversation
Allow the metrics endpoint to authenticate using JWKS (ES256/RS256/EdDSA) as an alternative to METRICS_JWT_SECRET. This enables self-hosted setups to use asymmetric JWT verification for metrics without maintaining a separate HS256 symmetric key. The metrics pipeline now falls back to API_JWT_JWKS when METRICS_JWT_SECRET is not set, and supports both symmetric and asymmetric key verification. Closes supabase#1951
Contributor
|
Looking at it from the architecture side, I don’t think adding JWKS auth to Prometheus usually uses a static secret or network-level protection. Using If the goal is just to avoid extra env vars in self-hosted setups, I think making |
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
Allow the metrics endpoint (
/metrics) to authenticate using JWKS (ES256/RS256/EdDSA asymmetric keys) as an alternative toMETRICS_JWT_SECRET(HS256 symmetric key).Problem
Currently the metrics endpoint in realtime hard-requires
METRICS_JWT_SECRET(HS256 symmetric) and crashes at boot if it is missing:Meanwhile, the WebSocket/API endpoint already supports
API_JWT_JWKSfor both ES256 and HS256 verification. This creates an inconsistency:In self-hosted setups migrating to asymmetric signing (ES256 via
GOTRUE_JWT_KEYS), operators still have to maintain a separate HS256 symmetric key just for realtime metrics — even thoughJWT_JWKSalready contains the same HS256 key material plus the ES256 public keys.Solution
config/runtime.exs: TheMETRICS_JWT_SECRETnow falls back toAPI_JWT_JWKSwhen not set, enabling asymmetric key support for metrics.lib/realtime_web/router.ex: Newcheck_auth_metricsplug that reads bothmetrics_jwt_secretandmetrics_jwt_jwks, passing the JWKS to the JWT verification layer.ENVS.md: Document the newMETRICS_JWT_JWKSenvironment variable.Tests: Added JWKS authentication tests for the metrics endpoint.
Benefit
Testing
Three new tests added to
metrics_controller_test.exs:GET /metricsaccepts ES256 JWT from JWKSGET /metrics/:regionaccepts ES256 JWT from JWKSGET /metricsrejects JWT with wrong signatureCloses #1951