官术网_书友最值得收藏!

Securing the Actuator endpoints

The Actuator's endpoints provide many insights into your Spring application to callers, but some of that information might be unsafe if you expose it to the caller. For example, the /shutdown endpoint can kill your application in production. So the /shutdown endpoint can be very dangerous for your application if you expose it publicly. Similarly, many endpoints in Spring Boot's Actuator expose information that might be very sensitive. So, you have to secure those Actuator endpoints and make them only available to authorized callers. You can use Spring Security to make secure the Actuator endpoints.

Although Spring Boot will not apply any security on your behalf, it does provide some convenient RequestMatchers that can be used in combination with Spring Security. In a Spring Boot application, this means adding the Security Starter as a build dependency and letting security auto-configuration take care of locking down the application, including the Actuator endpoints.

Let's add the following Starter dependency for Spring Security:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency> 

It will secure all Actuator endpoints, but you can disable basic security as follows:

In the application.properties file:

security.basic.enabled=false

In the application.yml file, it looks like this:

   basic:
         enabled: false

The preceding configuration change leaves only the sensitive Actuator endpoints secured and leaves the rest open for access.

Now you can secure sensitive endpoints by defining the default security properties, such username, password, and role, in the application.properties file:

security.user.name=admin
security.user.password=secret
management.security.role=SUPERUSER 

The preceding configuration will secure the Actuator endpoints. If any call reaches these endpoints, then it asks for username and password. That means no one can access these Actuator endpoints without authentication.

This Spring Security configuration is provided by the auto-configuration of the Spring Boot. You can also customize the Spring Security configuration to lock some of the more dangerous Actuator endpoints such as /shutdown or provide this Actuator endpoint for a very specific role.

Let's see what changes are introduced with Spring Boot 2.0.

主站蜘蛛池模板: 南宫市| 任丘市| 永靖县| 银川市| 襄垣县| 赣榆县| 榕江县| 大洼县| 福海县| 和硕县| 陵水| 唐山市| 吉林省| 左权县| 梨树县| 三原县| 鹿泉市| 文山县| 新巴尔虎左旗| 商城县| 宿迁市| 南皮县| 乐昌市| 彰武县| 唐海县| 高清| 海兴县| 林芝县| 叶城县| 峨边| 新丰县| 宝应县| 荃湾区| 泰安市| 阜南县| 永仁县| 信阳市| 临江市| 兰溪市| 遵义市| 疏勒县|