Actuator endpoints reveal sensitive information about the application.
To password protect the actuator endpoints follow the below steps :
Step 1 : Add spring-boot-starter-security
dependency in pom.xml
.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
Thanks to SpringBoot Auto Configuration
. It automatically initialises all the security related components.
Step 2 : Define a username and password in your property/yaml file.
See the below configuration.
spring:
security:
user:
name: admin
password: ********
Step 3 : Restart the application and try to access Secured Endpoints.
You should get “401 Unauthorized” response.
Step 4 : Open actuator endpoint in a Browser and it will prompt for username/password.
If you want just to secure you actuator endpoints, Add below config :
server:
port: 8080
context-path: /MyApplication
security:
user:
name: admin
password: secret
basic:
enabled: false
management:
context-path: /actuator
security:
enabled: true
This will make sure that application security is disabled but is enabled for actuator endpoints.
Note : Don't configure username/password under management security otherwise it will not work.