Previously we successfully spun up our Spring Boot application With Prometheus. An endpoint in our Spring application is exposing our metric data so that prometheus is able to retrieve them.
The main question that comes to mind is how to secure this information.
Spring already provides us with its great security framework
so it will be fairly easy to use it for our application. The goal would be to use basic authentication for the actuator/prometheus endpoints and also configure prometheus in order to access that information using basic authentication.
So the first step is to enable the security on our app. The first step is to add the security jar.
The Spring boot application will get secured on its own by generating a password for the default user.
However we do want to have control over the username and password so we are going to use some environment variables.
By running the application with the credentials for the default user we have the prometheus endpoints secured with a minimal configuration.
So now that we have the security setup on our app, it’s time to update our prometheus config.
So let’s run again prometheus as described previously.
To sum app after this change prometheus will gather metrics data for our application in a secure way.
Published on Java Code Geeks with permission by Emmanouil Gkatziouras, partner at our JCG program. See the original article here: Spring Boot and Micrometer with Prometheus Part 6: Securing metrics
Opinions expressed by Java Code Geeks contributors are their own.