Skip to content

Commit 587f96d

Browse files
committed
Merge pull request #24715 from hatefpalizgar
* pr/24715: Polish " Change info endpoint to be secure and unexposed by default" Change info endpoint to be secure and unexposed by default Closes gh-24715
2 parents 0fc33b0 + d07e351 commit 587f96d

File tree

16 files changed

+24
-59
lines changed

16 files changed

+24
-59
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/IncludeExcludeEndpointFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public enum DefaultIncludes {
178178
/**
179179
* The default set of include patterns used for web.
180180
*/
181-
WEB("info", "health");
181+
WEB("health");
182182

183183
private final EndpointPatterns patterns;
184184

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/ReactiveManagementWebSecurityAutoConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration;
2121
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
2222
import org.springframework.boot.actuate.health.HealthEndpoint;
23-
import org.springframework.boot.actuate.info.InfoEndpoint;
2423
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2524
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
2625
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -40,8 +39,8 @@
4039

4140
/**
4241
* {@link EnableAutoConfiguration Auto-configuration} for Reactive Spring Security when
43-
* actuator is on the classpath. Specifically, it permits access to the health and info
44-
* endpoints while securing everything else.
42+
* actuator is on the classpath. Specifically, it permits access to the health endpoint
43+
* while securing everything else.
4544
*
4645
* @author Madhura Bhave
4746
* @since 2.1.0
@@ -59,7 +58,7 @@ public class ReactiveManagementWebSecurityAutoConfiguration {
5958
@Bean
6059
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
6160
http.authorizeExchange((exchanges) -> {
62-
exchanges.matchers(EndpointRequest.to(HealthEndpoint.class, InfoEndpoint.class)).permitAll();
61+
exchanges.matchers(EndpointRequest.to(HealthEndpoint.class)).permitAll();
6362
exchanges.anyExchange().authenticated();
6463
});
6564
http.httpBasic(Customizer.withDefaults());

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfiguration.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration;
2121
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
2222
import org.springframework.boot.actuate.health.HealthEndpoint;
23-
import org.springframework.boot.actuate.info.InfoEndpoint;
2423
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2524
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
2625
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -38,10 +37,8 @@
3837

3938
/**
4039
* {@link EnableAutoConfiguration Auto-configuration} for Spring Security when actuator is
41-
* on the classpath. It allows unauthenticated access to the {@link HealthEndpoint} and
42-
* {@link InfoEndpoint}. If the user specifies their own
43-
* {@link org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
44-
* WebSecurityConfigurerAdapter} or {@link SecurityFilterChain} bean, this will back-off
40+
* on the classpath. It allows unauthenticated access to the {@link HealthEndpoint}. If
41+
* the user specifies their own{@link SecurityFilterChain} bean, this will back-off
4542
* completely and the user should specify all the bits that they want to configure as part
4643
* of the custom security configuration.
4744
*
@@ -60,7 +57,7 @@ public class ManagementWebSecurityAutoConfiguration {
6057
@Bean
6158
SecurityFilterChain managementSecurityFilterChain(HttpSecurity http) throws Exception {
6259
http.authorizeRequests((requests) -> {
63-
requests.requestMatchers(EndpointRequest.to(HealthEndpoint.class, InfoEndpoint.class)).permitAll();
60+
requests.requestMatchers(EndpointRequest.to(HealthEndpoint.class)).permitAll();
6461
requests.anyRequest().authenticated();
6562
});
6663
http.formLogin(Customizer.withDefaults());

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@
9191
{
9292
"name": "management.endpoints.web.exposure.include",
9393
"defaultValue": [
94-
"health",
95-
"info"
94+
"health"
9695
]
9796
},
9897
{

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnAvailableEndpointTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class ConditionalOnAvailableEndpointTests {
4040

4141
@Test
4242
void outcomeShouldMatchDefaults() {
43-
this.contextRunner.run((context) -> assertThat(context).hasBean("info").hasBean("health")
44-
.doesNotHaveBean("spring").doesNotHaveBean("test").doesNotHaveBean("shutdown"));
43+
this.contextRunner.run((context) -> assertThat(context).hasBean("health").doesNotHaveBean("spring")
44+
.doesNotHaveBean("test").doesNotHaveBean("shutdown"));
4545
}
4646

4747
@Test
@@ -79,7 +79,7 @@ void outcomeWhenIncludeAllWebAndEnablingEndpointDisabledByDefaultShouldMatchAll(
7979
@Test
8080
void outcomeWhenIncludeAllJmxButJmxDisabledShouldMatchDefaults() {
8181
this.contextRunner.withPropertyValues("management.endpoints.jmx.exposure.include=*")
82-
.run((context) -> assertThat(context).hasBean("info").hasBean("health").doesNotHaveBean("spring")
82+
.run((context) -> assertThat(context).hasBean("health").doesNotHaveBean("spring")
8383
.doesNotHaveBean("test").doesNotHaveBean("shutdown"));
8484
}
8585

@@ -95,8 +95,8 @@ void outcomeWhenIncludeAllJmxAndJmxEnabledAndEnablingEndpointDisabledByDefaultSh
9595
this.contextRunner
9696
.withPropertyValues("management.endpoints.jmx.exposure.include=*", "spring.jmx.enabled=true",
9797
"management.endpoint.shutdown.enabled=true")
98-
.run((context) -> assertThat(context).hasBean("info").hasBean("health").hasBean("test")
99-
.hasBean("spring").hasBean("shutdown"));
98+
.run((context) -> assertThat(context).hasBean("health").hasBean("test").hasBean("spring")
99+
.hasBean("shutdown"));
100100
}
101101

102102
@Test

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfigurationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ class InfoEndpointAutoConfigurationTests {
3636

3737
@Test
3838
void runShouldHaveEndpointBean() {
39-
this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true")
39+
this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=info")
4040
.run((context) -> assertThat(context).hasSingleBean(InfoEndpoint.class));
4141
}
4242

4343
@Test
44-
void runShouldHaveEndpointBeanEvenIfDefaultIsDisabled() {
45-
this.contextRunner.withPropertyValues("management.endpoint.default.enabled:false")
46-
.run((context) -> assertThat(context).hasSingleBean(InfoEndpoint.class));
44+
void runWhenNotExposedShouldNotHaveEndpointBean() {
45+
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(InfoEndpoint.class));
4746
}
4847

4948
@Test

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void webEndpointsAreDisabledByDefault() {
9191
assertThat(isExposed(client, HttpMethod.GET, "customservlet")).isFalse();
9292
assertThat(isExposed(client, HttpMethod.GET, "env")).isFalse();
9393
assertThat(isExposed(client, HttpMethod.GET, "health")).isTrue();
94-
assertThat(isExposed(client, HttpMethod.GET, "info")).isTrue();
94+
assertThat(isExposed(client, HttpMethod.GET, "info")).isFalse();
9595
assertThat(isExposed(client, HttpMethod.GET, "mappings")).isFalse();
9696
assertThat(isExposed(client, HttpMethod.POST, "shutdown")).isFalse();
9797
assertThat(isExposed(client, HttpMethod.GET, "threaddump")).isFalse();

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/ReactiveManagementWebSecurityAutoConfigurationTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ void permitAllForHealth() {
7878
this.contextRunner.run((context) -> assertThat(getAuthenticateHeader(context, "/actuator/health")).isNull());
7979
}
8080

81-
@Test
82-
void permitAllForInfo() {
83-
this.contextRunner.run((context) -> assertThat(getAuthenticateHeader(context, "/actuator/info")).isNull());
84-
}
85-
8681
@Test
8782
void securesEverythingElse() {
8883
this.contextRunner.run((context) -> {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ void permitAllForHealth() {
7373
});
7474
}
7575

76-
@Test
77-
void permitAllForInfo() {
78-
this.contextRunner.run((context) -> {
79-
HttpStatus status = getResponseStatus(context, "/actuator/info");
80-
assertThat(status).isEqualTo(HttpStatus.OK);
81-
});
82-
}
83-
8476
@Test
8577
void securesEverythingElse() {
8678
this.contextRunner.run((context) -> {

spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3960,10 +3960,10 @@ You can register multiple relying parties under the `spring.security.saml2.relyi
39603960

39613961
[[boot-features-security-actuator]]
39623962
=== Actuator Security
3963-
For security purposes, all actuators other than `/health` and `/info` are disabled by default.
3963+
For security purposes, all actuators other than `/health` are disabled by default.
39643964
The configprop:management.endpoints.web.exposure.include[] property can be used to enable the actuators.
39653965

3966-
If Spring Security is on the classpath and no other `WebSecurityConfigurerAdapter` or `SecurityFilterChain` bean is present, all actuators other than `/health` and `/info` are secured by Spring Boot auto-configuration.
3966+
If Spring Security is on the classpath and no other `WebSecurityConfigurerAdapter` or `SecurityFilterChain` bean is present, all actuators other than `/health` are secured by Spring Boot auto-configuration.
39673967
If you define a custom `WebSecurityConfigurerAdapter` or `SecurityFilterChain` bean, Spring Boot auto-configuration will back off and you will be in full control of actuator access rules.
39683968

39693969
NOTE: Before setting the `management.endpoints.web.exposure.include`, ensure that the exposed actuators do not contain sensitive information and/or are secured by placing them behind a firewall or by something like Spring Security.

0 commit comments

Comments
 (0)