【问题标题】:SpringBoot disable Actuator rootSpring Boot 禁用执行器根目录
【发布时间】:2018-11-07 13:46:20
【问题描述】:

我正在使用 springboot,并且我正在使用执行器和 prometheus 公开指标。我想公开“信息”、“健康”、“指标”、“普罗米修斯”、“关机”等等。但即使我在应用程序属性中指定,我看到的是即使根“/执行器”也被暴露了。

我想禁用根执行器,并且只有我之前所说的 5 个成员。

有没有办法不只暴露 /actuator 端点?我也尝试过这样的应用程序属性:

management.endpoints.web.exposure.exclude=actuator

那是暴露的执行器列表:

{
"_links": {
"self": {
"href": "http://localhost:9002/actuator",
"templated": false
},
"health-component-instance": {
"href": "http://localhost:9002/actuator/health/{component}/{instance}",
"templated": true
},
"health-component": {
"href": "http://localhost:9002/actuator/health/{component}",
"templated": true
},
"health": {
"href": "http://localhost:9002/actuator/health",
"templated": false
},
"shutdown": {
"href": "http://localhost:9002/actuator/shutdown",
"templated": false
},
"info": {
"href": "http://localhost:9002/actuator/info",
"templated": false
},
"prometheus": {
"href": "http://localhost:9002/actuator/prometheus",
"templated": false
},
"metrics-requiredMetricName": {
"href": "http://localhost:9002/actuator/metrics/{requiredMetricName}",
"templated": true
},
"metrics": {
"href": "http://localhost:9002/actuator/metrics",
"templated": false
}
}
}

【问题讨论】:

  • 不,因为/actuator 是所有其他执行器的主要入口点。

标签: java spring spring-boot openshift prometheus


【解决方案1】:

对此没有配置值。您现在可以做的最好的事情是将管理基础端点移动到/,在这种情况下,发现页面被禁用以防止与您应用中的其他端点发生冲突:

https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-endpoints-hypermedia

当管理上下文路径设置为/时,发现页面被禁用以防止与其他映射发生冲突的可能性。

如果您使用 Spring Security,您可以在自己的 WebSecurityConfigurerAdapter 中使用类似这样的内容有效地隐藏发现页面:

@Override
protected void configure(HttpSecurity http) throws Exception
{
   http
      .authorizeRequests()
         .mvcMatchers("/actuator").denyAll()
         .mvcMatchers("/actuator/").denyAll()
}

这将拒绝对发现页面的所有请求,但允许请求通过各个公开的端点。

在这个 GitHub 问题中也有一些关于发现页面的讨论:

https://github.com/spring-projects/spring-boot/issues/10331

【讨论】:

  • 嗨,迈克,感谢您的回复。我不明白如何覆盖执行器路径。我尝试在同一路径上暴露一个 api rest,但我的不被考虑
  • 很好,就像这个执行器没有暴露。但是现在没有办法将执行器暴露在 /actuator 下而不是主根目录下吗?
  • 正确,这就是我要指出的缺点:所有暴露的端点现在都在/而不是/actuator下。
  • 我添加了一个 spring 安全代码示例,说明如何隐藏发现页面,同时让暴露的端点工作。
猜你喜欢
  • 2020-01-10
  • 2015-09-28
  • 2017-01-21
  • 2017-10-30
  • 2014-04-07
  • 2017-02-07
  • 2021-06-01
  • 1970-01-01
  • 2016-02-13
相关资源
最近更新 更多