【发布时间】:2020-01-10 23:31:42
【问题描述】:
是否可以将 Spring Boot 应用程序配置为具有不安全(非 https)的一些 url,例如:/actuator/info、/actuator/prometheous 而所有其他 enpoint 都强制安全?
像这样启用 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”需要监控,但现在不行了。
【问题讨论】:
-
在此配置中
http.requiresChannel().antMatchers("/actuator").requiresInsecure();蚂蚁匹配器"/actuator"不匹配" /actuator/info"。尝试将其更改为"/actuator/**"。 -
您解决了这个问题吗?我遇到了同样的问题。
-
您可以使用 2 个端口:1 个用于管理,1 个用于服务器 (https)。它工作正常。
-
不使用两个不同的端口是否可以达到同样的效果?
-
对于单端口我们只能使用http或https(其中之一)
标签: spring-boot spring-security https spring-boot-actuator