Polish " Change info endpoint to be secure and unexposed by default"
See gh-24715
This commit is contained in:
@@ -20,7 +20,6 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAu
|
|||||||
import org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration;
|
import org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration;
|
||||||
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
|
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
|
||||||
import org.springframework.boot.actuate.health.HealthEndpoint;
|
import org.springframework.boot.actuate.health.HealthEndpoint;
|
||||||
import org.springframework.boot.actuate.info.InfoEndpoint;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
@@ -40,8 +39,8 @@ import org.springframework.security.web.server.WebFilterChainProxy;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for Reactive Spring Security when
|
* {@link EnableAutoConfiguration Auto-configuration} for Reactive Spring Security when
|
||||||
* actuator is on the classpath. Specifically, it permits access to the health and info
|
* actuator is on the classpath. Specifically, it permits access to the health endpoint
|
||||||
* endpoints while securing everything else.
|
* while securing everything else.
|
||||||
*
|
*
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
@@ -59,7 +58,7 @@ public class ReactiveManagementWebSecurityAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
|
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
|
||||||
http.authorizeExchange((exchanges) -> {
|
http.authorizeExchange((exchanges) -> {
|
||||||
exchanges.matchers(EndpointRequest.to(HealthEndpoint.class, InfoEndpoint.class)).permitAll();
|
exchanges.matchers(EndpointRequest.to(HealthEndpoint.class)).permitAll();
|
||||||
exchanges.anyExchange().authenticated();
|
exchanges.anyExchange().authenticated();
|
||||||
});
|
});
|
||||||
http.httpBasic(Customizer.withDefaults());
|
http.httpBasic(Customizer.withDefaults());
|
||||||
|
|||||||
@@ -34,6 +34,17 @@ class InfoEndpointAutoConfigurationTests {
|
|||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(InfoEndpointAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(InfoEndpointAutoConfiguration.class));
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void runShouldHaveEndpointBean() {
|
||||||
|
this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=info")
|
||||||
|
.run((context) -> assertThat(context).hasSingleBean(InfoEndpoint.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void runWhenNotExposedShouldNotHaveEndpointBean() {
|
||||||
|
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(InfoEndpoint.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() {
|
void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() {
|
||||||
this.contextRunner.withPropertyValues("management.endpoint.info.enabled:false")
|
this.contextRunner.withPropertyValues("management.endpoint.info.enabled:false")
|
||||||
|
|||||||
@@ -50,11 +50,6 @@ class SampleSecureWebFluxApplicationTests {
|
|||||||
.isOk();
|
.isOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void infoInsecureByDefault() {
|
|
||||||
this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void otherActuatorsSecureByDefault() {
|
void otherActuatorsSecureByDefault() {
|
||||||
this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
|
this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
|
||||||
|
|||||||
Reference in New Issue
Block a user