1. 介绍
spring boot actuator 是一个用于监控和管理 spring boot 应用程序的功能模块。它提供了一系列生产就绪的功能,帮助你了解应用程序的运行状况,以及在运行时对应用程序进行调整。actuator 使用了 spring mvc 来暴露各种 http 或 jmx 端点,通过这些端点你可以获取到应用程序的运行信息,如健康状态、指标、线程 dump、环境变量等。
spring boot actuator 的主要特性包括:
- 健康检查:可以检查应用程序的运行状况,包括数据库连接、磁盘空间、服务状态等。
- 指标收集:收集应用程序的性能指标,如内存使用情况、处理器使用情况、http 请求计数等。
- http 端点:暴露了一系列的 http 端点,通过这些端点可以访问应用程序的运行信息。
- 日志管理:可以动态地修改应用程序的日志级别。
- 跟踪和应用信息:提供了对应用程序的跟踪信息和应用信息的访问。
- 线程转储:可以获取应用程序的线程转储信息,帮助诊断性能问题。
- 环境信息:可以查看应用程序的配置属性和环境变量。
- 映射信息:可以查看 spring mvc 的映射信息。
- 审计事件:可以访问应用程序的审计事件信息。
要启用 spring boot actuator,你需要在项目中包含相应的依赖,然后在配置文件中配置相关的属性。spring boot 2.x 版本中,actuator 的默认端点是通过 http 公开的,但是出于安全考虑,除了/health
和/info
端点之外,其他端点默认是不对外暴露的。你可以通过配置文件来开启这些端点,并设置是否需要认证访问。
spring boot actuator 是开发
2. 问题描述
<!-- springboot actuator --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-actuator</artifactid> </dependency>
当我们的项目只是引入了 actuator 模块时,默认只公开了几个接口,如:
访问http://localhost:9200/actuator
有些情况下,我们需要将服务的健康信息上报给安全监控服务,则需要将接口打开
# 暴露监控端点 management: endpoints: web: exposure: include: '*'
此时,再次访问http://localhost:9200/actuator
也可以访问具体的属性http://localhost:9200/actuator/env
我们发现这个时候就会暴露很多服务信息,安全性得不到保证。
3. 解决方案
3.1 springboot1.x
3.1.1 禁用所有端口
#关闭全部接口 endpoints.enabled = false ###只开启某些接口 #endpoints.beans.enabled = true #endpoints.env.enabled = true #endpoints.trace.enabled = true #endpoints.metrics.enabled = true
3.1.2 安全框架控制
引入依赖
<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-security</artifactid> </dependency>
配置输入账号密码验证后才允许访问
management.security.enabled=true security.user.name=admin security.user.password=admin
3.2 springboot2.x
3.2.1 禁用所有端口
management.endpoints.enabled-by-default: false
3.2.2 安全框架控制
引入依赖
<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-security</artifactid> </dependency>
配置输入账号密码验证后才允许访问
spring.security.user.name=actuator spring.security.user.password=actuator
添加配置类
import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import org.springframework.security.config.annotation.web.builders.httpsecurity; import org.springframework.security.config.annotation.web.configuration.websecurityconfigureradapter; /** * actuator 监控端点权限 * */ @configuration public class actuatorsecurityconfig extends websecurityconfigureradapter { @override protected void configure(httpsecurity http) throws exception { http.httpbasic().and() .authorizerequests() .antmatchers("/actuator/**") .authenticated() .anyrequest() .permitall(); http // 关闭csrf token认证不需要csrf防护 .csrf().disable() // 关闭session会话管理器 jwt 不需要 .sessionmanagement().disable() // 关闭记住我功能 jwt 不需要 .rememberme().disable(); } }
4.总结
以上就是springboot actuator未授权访问漏洞的排查和解决方法的详细内容,更多关于springboot actuator访问漏洞的资料请关注代码网其它相关文章!
发表评论