Recently, we have been particularly disturbed by various security vulnerabilities, and we have received dozens of vulnerability emails scanned by the security team in a week, which have a class of vulnerabilities that are easy to ignore, but have an extremely wide impact and are extremely harmful, and you should not be unfamiliar with my name, which is Spring Boot Actuator.
Before writing this article, I did a little survey with my friends asking them about their knowledge of the Spring Boot Actuator and the results were surprisingly consistent, everyone knows that Spring Boot provides automatic configuration of the spring-boot-starter-actuator, but very few people but few people actually use its related features. As you continue to read the article below, you can also think about the following questions.
- Check if you have introduced the
spring-boot-starter-actuatordependency in your development project? - Do you actually use the
spring-boot-starter-actuatorrelated functionality in your projects? - Do you know the security risks of
spring-boot-starter-actuatorand the correct way to configure it?
What is the Spring Boot Actuator
Official Definition
Definition of Actuator An actuator is a manufacturing term that refers to a mechanical device for moving or controlling something. Actuators can generate a large amount of motion from a small change.
Quick Start
Step 1 Introduce dependencies
tips: spring-boot-starter-actuator has some configuration differences in different versions of Spring Boot, this article uses the 2.4.4 version of the project
Step 2 Understanding endpoint
The endpoint is the most important object we need to care about when using the Spring Boot Actuator, to list some of the endpoints you might be interested in
| ID | Description |
|---|---|
| beans | View all objects in the Spring container |
| configprops | View the list of objects annotated by @ConfigurationProperties |
| env | View the environment configuration information for the application.yaml configuration |
| health | Health Check Endpoints |
| info | Application Information |
| metrics | Statistical Information |
| mappings | Service contract @RequestMapping related endpoints |
| shutdown | Elegant shutdown |
For example, for health, you only need to access the following endpoint to get the status of the application
|
|
Step 3 Understanding the enable and exposure states of endpoint
The spring Boot Actuator provides two states of configuration for all endpoint
-
enabledEnabled status. By default allendpoints are enabled exceptshutdown. This is understandable, as the otherendpoints are basically viewing behavior, whileshutdownaffects the running state of the application. -
exposureexposes the state. Afterendpoint’senabledis set totrue, it needs to be exposed once more before it can be accessed; by default onlyhealthandinfoare exposed.
When enabled is not enabled, the associated endpoint code is not loaded by the Spring context at all, so it doesn’t matter if exposure is configured when enabled is false.
A few typical configuration examples are as follows
Enable and expose all endpoints
Only enable and expose the specified endpoint
Disable all endpoint
Or, remove the spring-boot-starter-actuator dependency!
Understanding the Security Risks of the Spring Boot Actuator
As you can see from the introduction above, there are endpoints provided by the Spring Boot Actuator that expose important information about the application, so take env as an example to get a feel for a typical application.yaml example.
The above configuration couldn’t be more classic. Let’s look at the return value after accessing localhost:8080/actuator/env
|
|
You can see that the Spring Boot Actuator is desensitized for the built-in sensitive configuration information spring.datasource.password, but some custom sensitive configurations like kirito.ak and kirito.sk are exposed.
Some readers may immediately question: our machines are deployed intranet, and are generally exposed to the public through a reverse proxy service, this kind of endpoint is not accessible to external users. Then I can only say that it is too naive, for example, the following situations are real examples that lead to security vulnerabilities
- The reverse proxy misconfigured the root node, exposing the
endpointof theactuatoralong with thewebservice - The online configuration is fine, but the public network
SLBwas opened when the test environment was deployed, resulting in theendpointofactuatorbeing exposed - A machine in the same environment is hacked, resulting in the leakage of application configuration information
Security Advice
For the endpoint provided by the Spring Boot Actuator, there are several measures that can be taken to minimize the risk of security attacks
- Expose
endpointwith minimal granularity. Only enable and expose theendpointthat is actually used, instead of configuring:management.endpoints.web.exposure.include=*. - Configure a separate access port for
endpointso that it is separate from the port of thewebservice to avoid exposing theendpointof theactuatorby mistake when exposing thewebservice. Example:management.port=8099. - Introduce the
spring-boot-starter-securitydependency to configure access control for theendpointof theactuator. - Evaluate carefully whether you need to bring in the
spring-boot-stater-actuator. In my personal experience, I have not encountered any requirement that necessarily requires the introduction ofspring-boot-stater-actuatorto solve, so if you are not aware of the security risks described above, I suggest you remove the dependency first.
Reference https://www.cnkirito.moe/spring-boot-actuator-notes/