Require optional admin auth for /metrics endpoint - #1537
rodneyosodo wants to merge 3 commits into
Conversation
d950629 to
f814d3b
Compare
|
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 |
|
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. |
|
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. |
|
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. |
f814d3b to
f9b2f22
Compare
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>
f9b2f22 to
44b272d
Compare
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
|
@Xynnn007 Thanks for the review. Agreed on all three points and adjusted the change accordingly.
I also tightened the ACL change: instead of |
Xynnn007
left a comment
There was a problem hiding this comment.
Thanks for this. The option would make sense to me.
| # Only needed when http_server.require_admin_auth_metrics = true: | ||
| # present a valid admin JWT. | ||
| authorization: | ||
| type: Bearer | ||
| credentials_file: /path/to/admin.jwt |
Protect
/metricswith admin auth (opt-in)KBS serves Prometheus metrics on
/metricswithout authentication, and the metriclabels expose operational detail such as resource paths and TEE types. Those values
are not secrets in the KBS threat model (without TLS they are already observable on
the wire), but operators may still want to lock the endpoint down without adding an
external component. This adds an opt-in way to do that.
What changed
New config flag
http_server.require_admin_auth_metrics(defaultfalse). Setit to
trueto require an admin JWT to scrape/metrics:When enabled,
/metricsgoes through the same admin authentication/authorizationas the other admin endpoints, and failures map to
AdminAuthAccess. Scrapers senda bearer admin JWT whose role ACL covers
/metrics(e.g.^/metrics$). WithDenyAll,/metricsis fully locked.The ACL anchor check is narrowed, not removed:
allowed_endpointsmust stillstart with
^/kbsor^/metricsand end with$, so enabling this does not letadmin auth be silently extended to arbitrary paths. A rule spanning both namespaces
must be split into one ACL entry per namespace. Existing
^/kbs...$rules areunaffected.
Only
/metricsis guarded./healthzand other status/liveness handlers stayunauthenticated; this is not a general mechanism for putting operational endpoints
behind admin auth.
Docs updated (
config.md,admin.md,metrics.md).Deployment guidance
This is defense-in-depth for deployments that do not put an authenticating gateway in
front of KBS. Restricting network access to the metrics port (and running a gateway)
remains the recommended primary control; the flag exists so that operators who cannot
rely on one still have a built-in option.
Tests
Integration tests cover no token, valid token,
DenyAll, and a restricted ACL thatexcludes
/metrics, plus a test asserting the default stays unauthenticated. Unittests cover the narrowed ACL anchor validation.