Skip to content

Commit bb55f49

Browse files
committed
Remove concept of sensitivity from Actuator's endpoints
Closes spring-projectsgh-9924
1 parent 847f6d1 commit bb55f49

File tree

55 files changed

+173
-606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+173
-606
lines changed

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

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import javax.servlet.http.HttpServletRequest;
2727

2828
import org.springframework.beans.factory.ObjectProvider;
29-
import org.springframework.boot.actuate.endpoint.Endpoint;
3029
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
3130
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
3231
import org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint;
@@ -62,7 +61,6 @@
6261
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
6362
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
6463
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
65-
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
6664
import org.springframework.security.config.http.SessionCreationPolicy;
6765
import org.springframework.security.web.AuthenticationEntryPoint;
6866
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
@@ -77,11 +75,7 @@
7775
* {@link EnableAutoConfiguration Auto-configuration} for security of framework endpoints.
7876
* Many aspects of the behavior can be controller with {@link ManagementServerProperties}
7977
* via externalized application properties (or via an bean definition of that type to set
80-
* the defaults).
81-
* <p>
82-
* The framework {@link Endpoint}s (used to expose application information to operations)
83-
* include a {@link Endpoint#isSensitive() sensitive} configuration option which will be
84-
* used as a security hint by the filter created here.
78+
* the defaults)..
8579
*
8680
* @author Dave Syer
8781
* @author Andy Wilkinson
@@ -126,7 +120,6 @@ public void customize(IgnoredRequestConfigurer configurer) {
126120
.getRequestMatcher(this.contextResolver);
127121
configurer.requestMatchers(requestMatcher);
128122
}
129-
130123
}
131124

132125
}
@@ -223,8 +216,6 @@ protected void configure(HttpSecurity http) throws Exception {
223216
http.exceptionHandling().authenticationEntryPoint(entryPoint);
224217
// Match all the requests for actuator endpoints ...
225218
http.requestMatcher(matcher);
226-
// ... but permitAll() for the non-sensitive ones
227-
configurePermittedRequests(http.authorizeRequests());
228219
http.httpBasic().authenticationEntryPoint(entryPoint).and().cors();
229220
// No cookies for management endpoints by default
230221
http.csrf().disable();
@@ -258,38 +249,9 @@ private AuthenticationEntryPoint entryPoint() {
258249
return entryPoint;
259250
}
260251

261-
private void configurePermittedRequests(
262-
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry requests) {
263-
requests.requestMatchers(new LazyEndpointPathRequestMatcher(
264-
this.contextResolver, EndpointPaths.SENSITIVE)).authenticated();
265-
// Permit access to the non-sensitive endpoints
266-
requests.requestMatchers(new LazyEndpointPathRequestMatcher(
267-
this.contextResolver, EndpointPaths.NON_SENSITIVE)).permitAll();
268-
}
269-
270252
}
271253

272-
private enum EndpointPaths {
273-
274-
ALL,
275-
276-
NON_SENSITIVE {
277-
278-
@Override
279-
protected boolean isIncluded(MvcEndpoint endpoint) {
280-
return !endpoint.isSensitive();
281-
}
282-
283-
},
284-
285-
SENSITIVE {
286-
287-
@Override
288-
protected boolean isIncluded(MvcEndpoint endpoint) {
289-
return endpoint.isSensitive();
290-
}
291-
292-
};
254+
private static class EndpointPaths {
293255

294256
public String[] getPaths(EndpointHandlerMapping endpointHandlerMapping) {
295257
if (endpointHandlerMapping == null) {
@@ -298,24 +260,18 @@ public String[] getPaths(EndpointHandlerMapping endpointHandlerMapping) {
298260
Set<? extends MvcEndpoint> endpoints = endpointHandlerMapping.getEndpoints();
299261
Set<String> paths = new LinkedHashSet<>(endpoints.size());
300262
for (MvcEndpoint endpoint : endpoints) {
301-
if (isIncluded(endpoint)) {
302-
String path = endpointHandlerMapping.getPath(endpoint.getPath());
303-
paths.add(path);
304-
if (!path.equals("")) {
305-
paths.add(path + "/**");
306-
// Add Spring MVC-generated additional paths
307-
paths.add(path + ".*");
308-
}
309-
paths.add(path + "/");
263+
String path = endpointHandlerMapping.getPath(endpoint.getPath());
264+
paths.add(path);
265+
if (!path.equals("")) {
266+
paths.add(path + "/**");
267+
// Add Spring MVC-generated additional paths
268+
paths.add(path + ".*");
310269
}
270+
paths.add(path + "/");
311271
}
312272
return paths.toArray(new String[paths.size()]);
313273
}
314274

315-
protected boolean isIncluded(MvcEndpoint endpoint) {
316-
return true;
317-
}
318-
319275
}
320276

321277
private static class LazyEndpointPathRequestMatcher implements RequestMatcher {
@@ -342,7 +298,8 @@ public static RequestMatcher getRequestMatcher(
342298
return matcher;
343299
}
344300
// Match everything, including the sensitive and non-sensitive paths
345-
return new LazyEndpointPathRequestMatcher(contextResolver, EndpointPaths.ALL);
301+
return new LazyEndpointPathRequestMatcher(contextResolver,
302+
new EndpointPaths());
346303
}
347304

348305
LazyEndpointPathRequestMatcher(ManagementContextResolver contextResolver,

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryDiscoveryMvcEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CloudFoundryDiscoveryMvcEndpoint extends AbstractMvcEndpoint {
4141
private final Set<NamedMvcEndpoint> endpoints;
4242

4343
CloudFoundryDiscoveryMvcEndpoint(Set<NamedMvcEndpoint> endpoints) {
44-
super("", false);
44+
super("");
4545
this.endpoints = endpoints;
4646
}
4747

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/AbstractEndpoint.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,27 @@ public abstract class AbstractEndpoint<T> implements Endpoint<T>, EnvironmentAwa
4141
*/
4242
private String id;
4343

44-
private final boolean sensitiveDefault;
45-
46-
/**
47-
* Mark if the endpoint exposes sensitive information.
48-
*/
49-
private Boolean sensitive;
50-
5144
/**
5245
* Enable the endpoint.
5346
*/
5447
private Boolean enabled;
5548

56-
/**
57-
* Create a new sensitive endpoint instance. The endpoint will enabled flag will be
58-
* based on the spring {@link Environment} unless explicitly set.
59-
* @param id the endpoint ID
60-
*/
61-
public AbstractEndpoint(String id) {
62-
this(id, true);
63-
}
64-
6549
/**
6650
* Create a new endpoint instance. The endpoint will enabled flag will be based on the
6751
* spring {@link Environment} unless explicitly set.
6852
* @param id the endpoint ID
69-
* @param sensitive if the endpoint is sensitive by default
7053
*/
71-
public AbstractEndpoint(String id, boolean sensitive) {
54+
public AbstractEndpoint(String id) {
7255
setId(id);
73-
this.sensitiveDefault = sensitive;
7456
}
7557

7658
/**
7759
* Create a new endpoint instance.
7860
* @param id the endpoint ID
79-
* @param sensitive if the endpoint is sensitive
8061
* @param enabled if the endpoint is enabled or not.
8162
*/
82-
public AbstractEndpoint(String id, boolean sensitive, boolean enabled) {
63+
public AbstractEndpoint(String id, boolean enabled) {
8364
setId(id);
84-
this.sensitiveDefault = sensitive;
8565
this.enabled = enabled;
8666
}
8767

@@ -115,14 +95,4 @@ public void setEnabled(Boolean enabled) {
11595
this.enabled = enabled;
11696
}
11797

118-
@Override
119-
public boolean isSensitive() {
120-
return EndpointProperties.isSensitive(this.environment, this.sensitive,
121-
this.sensitiveDefault);
122-
}
123-
124-
public void setSensitive(Boolean sensitive) {
125-
this.sensitive = sensitive;
126-
}
127-
12898
}

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/Endpoint.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ public interface Endpoint<T> {
4242
*/
4343
boolean isEnabled();
4444

45-
/**
46-
* Return if the endpoint is sensitive, i.e. may return data that the average user
47-
* should not see. Mappings can use this as a security hint.
48-
* @return if the endpoint is sensitive
49-
*/
50-
boolean isSensitive();
51-
5245
/**
5346
* Called to invoke the endpoint.
5447
* @return the results of the invocation
Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,18 +30,11 @@ public class EndpointProperties {
3030

3131
private static final String ENDPOINTS_ENABLED_PROPERTY = "endpoints.enabled";
3232

33-
private static final String ENDPOINTS_SENSITIVE_PROPERTY = "endpoints.sensitive";
34-
3533
/**
3634
* Enable endpoints.
3735
*/
3836
private Boolean enabled = true;
3937

40-
/**
41-
* Default endpoint sensitive setting.
42-
*/
43-
private Boolean sensitive;
44-
4538
public Boolean getEnabled() {
4639
return this.enabled;
4740
}
@@ -50,14 +43,6 @@ public void setEnabled(Boolean enabled) {
5043
this.enabled = enabled;
5144
}
5245

53-
public Boolean getSensitive() {
54-
return this.sensitive;
55-
}
56-
57-
public void setSensitive(Boolean sensitive) {
58-
this.sensitive = sensitive;
59-
}
60-
6146
/**
6247
* Determine if an endpoint is enabled based on its specific property and taking into
6348
* account the global default.
@@ -76,25 +61,4 @@ public static boolean isEnabled(Environment environment, Boolean enabled) {
7661
return true;
7762
}
7863

79-
/**
80-
* Determine if an endpoint is sensitive based on its specific property and taking
81-
* into account the global default.
82-
* @param environment the Spring environment or {@code null}.
83-
* @param sensitive the endpoint property or {@code null}
84-
* @param sensitiveDefault the default setting to use if no environment property is
85-
* defined
86-
* @return if the endpoint is sensitive
87-
*/
88-
public static boolean isSensitive(Environment environment, Boolean sensitive,
89-
boolean sensitiveDefault) {
90-
if (sensitive != null) {
91-
return sensitive;
92-
}
93-
if (environment != null
94-
&& environment.containsProperty(ENDPOINTS_SENSITIVE_PROPERTY)) {
95-
return environment.getProperty(ENDPOINTS_SENSITIVE_PROPERTY, Boolean.class);
96-
}
97-
return sensitiveDefault;
98-
}
99-
10064
}

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class HealthEndpoint extends AbstractEndpoint<Health> {
4949
*/
5050
public HealthEndpoint(HealthAggregator healthAggregator,
5151
Map<String, HealthIndicator> healthIndicators) {
52-
super("health", false);
52+
super("health");
5353
Assert.notNull(healthAggregator, "HealthAggregator must not be null");
5454
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
5555
CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator(

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class InfoEndpoint extends AbstractEndpoint<Map<String, Object>> {
4141
* @param infoContributors the info contributors to use
4242
*/
4343
public InfoEndpoint(List<InfoContributor> infoContributors) {
44-
super("info", false);
44+
super("info");
4545
Assert.notNull(infoContributors, "Info contributors must not be null");
4646
this.infoContributors = infoContributors;
4747
}

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ShutdownEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>>
5050
* Create a new {@link ShutdownEndpoint} instance.
5151
*/
5252
public ShutdownEndpoint() {
53-
super("shutdown", true, false);
53+
super("shutdown", false);
5454
}
5555

5656
@Override

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ public boolean isEnabled() {
6464
return this.endpoint.isEnabled();
6565
}
6666

67-
@ManagedAttribute(description = "Indicates whether the underlying endpoint exposes sensitive information")
68-
public boolean isSensitive() {
69-
return this.endpoint.isSensitive();
70-
}
71-
7267
@Override
7368
public String getIdentity() {
7469
return ObjectUtils.getIdentityHexString(getEndpoint());

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractEndpointMvcAdapter.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ public void setPath(String path) {
8080
this.path = path;
8181
}
8282

83-
@Override
84-
public boolean isSensitive() {
85-
return this.delegate.isSensitive();
86-
}
87-
8883
@Override
8984
@SuppressWarnings("rawtypes")
9085
public Class<? extends Endpoint> getEndpointType() {

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,8 @@ public abstract class AbstractMvcEndpoint
4646
*/
4747
private Boolean enabled;
4848

49-
/**
50-
* Mark if the endpoint exposes sensitive information.
51-
*/
52-
private Boolean sensitive;
53-
54-
private final boolean sensitiveDefault;
55-
56-
public AbstractMvcEndpoint(String path, boolean sensitive) {
49+
public AbstractMvcEndpoint(String path) {
5750
setPath(path);
58-
this.sensitiveDefault = sensitive;
59-
}
60-
61-
public AbstractMvcEndpoint(String path, boolean sensitive, boolean enabled) {
62-
setPath(path);
63-
this.sensitiveDefault = sensitive;
64-
this.enabled = enabled;
6551
}
6652

6753
@Override
@@ -93,16 +79,6 @@ public void setEnabled(Boolean enabled) {
9379
this.enabled = enabled;
9480
}
9581

96-
@Override
97-
public boolean isSensitive() {
98-
return EndpointProperties.isSensitive(this.environment, this.sensitive,
99-
this.sensitiveDefault);
100-
}
101-
102-
public void setSensitive(Boolean sensitive) {
103-
this.sensitive = sensitive;
104-
}
105-
10682
@Override
10783
@SuppressWarnings("rawtypes")
10884
public Class<? extends Endpoint> getEndpointType() {

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractNamedMvcEndpoint.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,8 @@ public abstract class AbstractNamedMvcEndpoint extends AbstractMvcEndpoint
3131

3232
private final String name;
3333

34-
public AbstractNamedMvcEndpoint(String name, String path, boolean sensitive) {
35-
super(path, sensitive);
36-
Assert.hasLength(name, "Name must not be empty");
37-
this.name = name;
38-
}
39-
40-
public AbstractNamedMvcEndpoint(String name, String path, boolean sensitive,
41-
boolean enabled) {
42-
super(path, sensitive, enabled);
34+
public AbstractNamedMvcEndpoint(String name, String path) {
35+
super(path);
4336
Assert.hasLength(name, "Name must not be empty");
4437
this.name = name;
4538
}

0 commit comments

Comments
 (0)