feat: protect /metrics endpoint with auth and IP allowlist#620
Merged
hman38705 merged 2 commits intosolutions-plug:mainfrom Apr 27, 2026
Merged
feat: protect /metrics endpoint with auth and IP allowlist#620hman38705 merged 2 commits intosolutions-plug:mainfrom
hman38705 merged 2 commits intosolutions-plug:mainfrom
Conversation
- Move /metrics from public_routes into a dedicated metrics_routes router guarded by metrics_auth_middleware - Import MetricsAuthConfig in main.rs and wire it from config fields (metrics_public, metrics_allowlist_ips, api_key_auth) - Add unit tests in security.rs for all middleware branches - Add integration-level tests in tests/security_tests.rs covering: public mode bypass, missing key → 401, valid key → 200, wrong key → 401, IP not in allowlist → 403 Config env vars (already present in Config): METRICS_PUBLIC=true opt-in public mode (default: false) METRICS_ALLOWLIST_IPS=... comma-separated IP allowlist API_KEYS=... shared API key(s) for x-api-key header Closes solutions-plug#456
|
@obanai9 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 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
Gates the
/metricsPrometheus endpoint behind API key authentication and an optional IP allowlist, preventing public exposure of internal operational data.Changes
services/api/src/main.rs/metricsfrompublic_routesmetrics_routesrouter withmetrics_auth_middlewarewired fromMetricsAuthConfig(built from existing config fields:metrics_public,metrics_allowlist_ips,api_key_auth)services/api/src/security.rsMetricsAuthConfigandmetrics_auth_middlewarewere already implemented; no changes neededservices/api/tests/security_tests.rsSecurity Behaviour
METRICS_PUBLIC=truex-api-keyheader, no allowlistx-api-keyMETRICS_ALLOWLIST_IPSConfiguration
METRICS_PUBLICfalseMETRICS_ALLOWLIST_IPSAPI_KEYSx-api-keyheaderTesting
All new tests are in
security.rs(unit) andtests/security_tests.rs(integration).Closes #456