Spring Boot:对执行器端点禁用https

时间:2019-09-09 07:59:43

标签: spring-boot spring-security https spring-boot-actuator

是否可以将Spring Booot应用程序配置为具有一些非安全(非https)的URL,例如:/ actuator / info,/ actuator / prometheous,而所有其他要求都必须是安全的?

像这样启用SSL:

server.ssl.enabled=true
server.ssl.key-store=classpath:keystore.jks
server.ssl.key-store-password=xxxx

我尝试设置:

management.server.port=8762
management.server.ssl.enabled=false

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.requiresChannel().antMatchers("/actuator").requiresInsecure();
    http.requiresChannel().anyRequest().requiresSecure();
    // accept only IP in range to access metric
    http.csrf().disable().authorizeRequests().antMatchers("/actuator/**")
            .access("hasIpAddress('" + ipRangeMain + "') or hasIpAddress('" + ipRangeSecond + "')");

}

但是它仍然无法正常工作 当我尝试访问/ actuator / info时,它显示错误:

Bad Request
This combination of host and port requires TLS.

“ / actuator / info”端点需要由负载均衡器访问,而“ / actuator / prometheous”可以访问监视,但现在不起作用。

1 个答案:

答案 0 :(得分:0)

如果有人也为之迷迷糊糊。我使用2个建议的端口来解决它,例如@ user3611168建议:

applycation.yml:

  server:
    port: 10000
    ssl:
      key-store-type: ...
      key-store: ...
      key-store-password: ...
      key-alias: ...
  management:
    server:
      port: 8080
      ssl:
        enabled: false

具有SSL的端口10000。没有SSL的Prometheus 8080的端口