Skip to content

Require optional admin auth for /metrics endpoint - #1537

Open
rodneyosodo wants to merge 2 commits into
confidential-containers:mainfrom
rodneyosodo:fix/6-protect-metrics
Open

Require optional admin auth for /metrics endpoint#1537
rodneyosodo wants to merge 2 commits into
confidential-containers:mainfrom
rodneyosodo:fix/6-protect-metrics

Conversation

@rodneyosodo

Copy link
Copy Markdown

Protect /metrics with admin auth (opt-in)

The /metrics endpoint was open to anyone who could reach KBS, which leaks internal stuff like resource paths and TEE types in the metric labels. Not great.

This adds the option to require a valid admin token for /metrics so you can lock it down if you want to.

What changed

  • New config flag http_server.require_admin_auth_metrics (default false). Set it to true to require an admin JWT to scrape /metrics:

    [http_server]
    require_admin_auth_metrics = true
  • When enabled, /metrics goes through the same admin auth/authorization as the other admin endpoints. Scrapers need to send a bearer admin JWT, and their role's allowed_endpoints has to cover /metrics (e.g. ^/(kbs/v0/.*|metrics)$). If the admin backend is DenyAll, /metrics is fully locked.

  • Relaxed the ACL regex check so roles can be granted /metrics (was only ^/kbs... rules before). Existing rules still work.

  • Docs updated (config.md, admin.md, metrics.md).

@rodneyosodo
rodneyosodo requested a review from a team as a code owner August 3, 2026 13:06
The /metrics endpoint was unauthenticated, leaking internal label values
such as resource paths and TEE types. Require a valid admin JWT (via the
configured admin authentication/authorization backend) before serving
Prometheus metrics, and map failures to AdminAuthAccess like the other
admin-protected endpoints.

Relax the regex_acl anchor validation from '^/kbs' to '^/' so that
/metrics can be granted to admin roles via allowed_endpoints; existing
'^/kbs...$' rules remain valid.

Add an integration test covering no token, valid token, DenyAll admin
backend, and a restricted ACL that excludes /metrics.

Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
Add http_server.require_admin_auth_metrics (default false) so operators
can opt in to protecting /metrics with admin JWT auth instead of it being
mandatory. The default preserves unauthenticated metric scraping for
existing deployments; enabling it applies the check_admin_access guard
added previously.

Update the metrics integration test to opt in to the protection, add a
test asserting /metrics stays accessible without a token by default, and
document the new flag in config.md and metrics.md.

Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
@rodneyosodo
rodneyosodo force-pushed the fix/6-protect-metrics branch from d950629 to f814d3b Compare August 3, 2026 13:06
@fitzthum

fitzthum commented Aug 3, 2026

Copy link
Copy Markdown
Member

This was discussed when the metrics feature was first added. Note that neither of thing things in your example are considered secret. They are both conveyed revealed by the KBS protocol itself (unless TLS Is enabled).

On the other hand, maybe it's reasonable to add this option. wdyt @Xynnn007 @pmores

@Xynnn007

Xynnn007 commented Aug 4, 2026

Copy link
Copy Markdown
Member

Oh. This is a following question for admin module integration. imo, we do not need this in KBS logic, as it would make the core KBS logic complexer. Usually, the API only exposes in intranet (with proper deployment with k8s) thus would not be called by outer clients.

If the API needs to be exposed to outer callers in some cases, it's rercommended to use a network gateway in front of KBS. That gate way can control the inbound/outbound network flow and the allowlists. This is about the deployment model, than core logic.

Furthurmore, in future some more APIs about HTTP service status/liveness/... should not be covered by admin auth imo.

@pmores

pmores commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

I don't really have a strong opinion of this as it's really much more about auth than Prometheus. That said, the option doesn't seem likely to break anything, and it seems to bring the metric endpoint to the same level of auth as the admin endpoints, for whatever that's worth. The change isn't overly complex either. On the other hand, extending the set of auth'd endpoints this way does seem excessive.

@fitzthum

fitzthum commented Aug 4, 2026

Copy link
Copy Markdown
Member

I am open to it. In theory metrics don't reveal any information, but perhaps better safe than sorry. If something is potentially sensitive, I think we we should provide a way to lock it down without needing any extra tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants