You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@jkroepke having a way to restrict access to the metrics endpoint sounds reasonable. Usually this endpoint is scraped by Prometheus which won't have a valid keycloak session. Wondering what's the best way here, i'll try to give it some thought.
This exporter generates a static key. If you want to scrape the endpoint you must attach the key as get parameter. Otherwise you get an unauthorized messages.
2 possible ways to store the static key inside keycloak.
The User must be define the key via -D property on startup
One way to restrict metrics endpoint is mentioned under Keycloak admin docs https://www.keycloak.org/docs/11.0/server_admin/#admin-endpoints-and-console where you replace path-prefix('/auth/admin') by
either path-template('/auth/realms/{realm}/metrics')
or (path-prefix('/auth/admin') or path-template('/auth/realms/{realm}/metrics'))
One way to restrict metrics endpoint is mentioned under Keycloak admin docs https://www.keycloak.org/docs/11.0/server_admin/#admin-endpoints-and-console where you replace path-prefix('/auth/admin') by
either path-template('/auth/realms/{realm}/metrics')
or (path-prefix('/auth/admin') or path-template('/auth/realms/{realm}/metrics'))
Maybe just add the jboss cli command in the documentation, at least for now.
There is also a way to implement everything as and "admin rest api" but it requires some work, so I'm not sure if this is the approach you want to go with.
Activity
pb82 commentedon Jul 12, 2019
@jkroepke having a way to restrict access to the metrics endpoint sounds reasonable. Usually this endpoint is scraped by Prometheus which won't have a valid keycloak session. Wondering what's the best way here, i'll try to give it some thought.
jkroepke commentedon Jul 12, 2019
Some inspiration from here https://github.com/AndreyVMarkelov/jira-prometheus-exporter/
https://github.com/AndreyVMarkelov/jira-prometheus-exporter/blob/master/src/main/java/ru/andreymarkelov/atlas/plugins/promjiraexporter/servlet/PrometheusExporter.java#L35
This exporter generates a static key. If you want to scrape the endpoint you must attach the key as get parameter. Otherwise you get an unauthorized messages.
2 possible ways to store the static key inside keycloak.
-Dproperty on startupattributeswhich is designed for user properties. Maybe it's possible to safe the key there.danifr commentedon Jul 10, 2020
I am interested in this. Having those keycloak metrics open to everyone does not seem like good idea.
@jkroepke did you managed to configure it? Thanks
danifr commentedon Jul 14, 2020
As a workaround and since I have an HAproxy in front of my Keycloak servers, I added a
http-request denyto my HAproxy frontend configuration:This config seems to do the trick.
giner commentedon Sep 2, 2020
One way to restrict metrics endpoint is mentioned under Keycloak admin docs https://www.keycloak.org/docs/11.0/server_admin/#admin-endpoints-and-console where you replace
path-prefix('/auth/admin')byeither
path-template('/auth/realms/{realm}/metrics')or
(path-prefix('/auth/admin') or path-template('/auth/realms/{realm}/metrics'))jelly commentedon Sep 9, 2020
I've fixed this problem with an nginx location rule and basic auth (ofcourse servering on https)
Prometheus itself supports base64 authentication.
jkroepke commentedon Sep 9, 2020
I still would like to see an in-tree solution without the need to configure an reverse proxy.
Tim-Schwalbe commentedon Oct 2, 2020
Here is my NGINX Ingress Config to block requests to
/auth/realms/master/metricsCyben commentedon Aug 19, 2021
I think it is really important to restrict this endpoint from regular users as well.
Seems like the best and easiest way is configuring it in the keycloak configuration.
As @giner mentioned:
Maybe just add the jboss cli command in the documentation, at least for now.
There is also a way to implement everything as and "admin rest api" but it requires some work, so I'm not sure if this is the approach you want to go with.
TDog42 commentedon Oct 18, 2022
It seems that with KeyCloak 17 there is no way to rextrict endpoints anymore within the server configuration (keycloak/keycloak#12394)
Maybe just add an option for some basic authentication. This way not the whole internet will be able to sniff out the metrics