Skip to content

Commit 53c1e79

Browse files
hatefpalizgarmbhave
authored andcommitted
Change info endpoint to be secure and unexposed by default
See gh-24715
1 parent 0fc33b0 commit 53c1e79

File tree

14 files changed

+18
-58
lines changed

14 files changed

+18
-58
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/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: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ class InfoEndpointAutoConfigurationTests {
3434
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
3535
.withConfiguration(AutoConfigurations.of(InfoEndpointAutoConfiguration.class));
3636

37-
@Test
38-
void runShouldHaveEndpointBean() {
39-
this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true")
40-
.run((context) -> assertThat(context).hasSingleBean(InfoEndpoint.class));
41-
}
42-
43-
@Test
44-
void runShouldHaveEndpointBeanEvenIfDefaultIsDisabled() {
45-
this.contextRunner.withPropertyValues("management.endpoint.default.enabled:false")
46-
.run((context) -> assertThat(context).hasSingleBean(InfoEndpoint.class));
47-
}
48-
4937
@Test
5038
void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() {
5139
this.contextRunner.withPropertyValues("management.endpoint.info.enabled:false")

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.

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SecurityConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private UserDetails createUserDetails(String username, String password, String..
5757
SecurityFilterChain configure(HttpSecurity http) throws Exception {
5858
http.authorizeRequests((requests) -> {
5959
requests.mvcMatchers("/actuator/beans").hasRole("BEANS");
60-
requests.requestMatchers(EndpointRequest.to("health", "info")).permitAll();
60+
requests.requestMatchers(EndpointRequest.to("health")).permitAll();
6161
requests.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
6262
.hasRole("ACTUATOR");
6363
requests.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();

0 commit comments

Comments
 (0)