Skip to content

Commit 1be5812

Browse files
committed
Require ACTUATOR role rather than ADMIN
Update management security to require an `ACTUATOR` role rather than `ADMIN` by default. This should reduce the risk of users accidentally exposing actuator endpoints because they happen to use a role named `ADMIN`. Fixes spring-projectsgh-7569
1 parent 95be208 commit 1be5812

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private static class AuthenticationManagerAdapter extends
295295
CRaSHPlugin<AuthenticationPlugin> implements AuthenticationPlugin<String> {
296296

297297
private static final PropertyDescriptor<String> ROLES = PropertyDescriptor.create(
298-
"auth.spring.roles", "ADMIN",
298+
"auth.spring.roles", "ACTUATOR",
299299
"Comma separated list of roles required to access the shell");
300300

301301
@Autowired
@@ -305,7 +305,7 @@ private static class AuthenticationManagerAdapter extends
305305
@Qualifier("shellAccessDecisionManager")
306306
private AccessDecisionManager accessDecisionManager;
307307

308-
private String[] roles = new String[] { "ADMIN" };
308+
private String[] roles = new String[] { "ACTUATOR" };
309309

310310
@Override
311311
public boolean authenticate(String username, String password) throws Exception {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public static class Security {
168168
/**
169169
* Comma-separated list of roles that can access the management endpoint.
170170
*/
171-
private List<String> roles = Arrays.asList("ADMIN");
171+
private List<String> roles = Arrays.asList("ACTUATOR");
172172

173173
/**
174174
* Session creating policy for security use (always, never, if_required,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public static class SpringAuthenticationProperties
524524
/**
525525
* Comma-separated list of required roles to login to the CRaSH console.
526526
*/
527-
private String[] roles = new String[] { "ADMIN" };
527+
private String[] roles = new String[] { "ACTUATOR" };
528528

529529
@Override
530530
protected void applyToCrshShellConfig(Properties config) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private boolean isSecure(Principal principal) {
194194
Authentication authentication = (Authentication) principal;
195195
List<String> roles = Arrays.asList(StringUtils
196196
.trimArrayElements(StringUtils.commaDelimitedListToStringArray(
197-
this.roleResolver.getProperty("roles", "ROLE_ADMIN"))));
197+
this.roleResolver.getProperty("roles", "ROLE_ACTUATOR"))));
198198
for (GrantedAuthority authority : authentication.getAuthorities()) {
199199
String name = authority.getAuthority();
200200
for (String role : roles) {

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public Authentication authenticate(Authentication authentication)
347347
authentication = new UsernamePasswordAuthenticationToken(
348348
authentication.getPrincipal(),
349349
authentication.getCredentials(), Collections
350-
.singleton(new SimpleGrantedAuthority("ADMIN")));
350+
.singleton(new SimpleGrantedAuthority("ACTUATOR")));
351351
}
352352
else {
353353
throw new BadCredentialsException(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void testWebConfigurationWithExtraRole() throws Exception {
120120
ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(
121121
user.getAuthorities());
122122
assertThat(authorities).containsAll(AuthorityUtils
123-
.commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ADMIN"));
123+
.commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ACTUATOR"));
124124
}
125125

126126
private UserDetails getUser() {

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void close() {
6868
@Test
6969
public void defaultJsonResponseIsNotIndented() throws Exception {
7070
TestSecurityContextHolder.getContext().setAuthentication(
71-
new TestingAuthenticationToken("user", "N/A", "ROLE_ADMIN"));
71+
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
7272
this.context = new AnnotationConfigWebApplicationContext();
7373
this.context.register(SecureConfiguration.class);
7474
MockMvc mockMvc = createSecureMockMvc();
@@ -103,7 +103,7 @@ public void fileExtensionNotFound() throws Exception {
103103
@Test
104104
public void jsonExtensionProvided() throws Exception {
105105
TestSecurityContextHolder.getContext().setAuthentication(
106-
new TestingAuthenticationToken("user", "N/A", "ROLE_ADMIN"));
106+
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
107107
this.context = new AnnotationConfigWebApplicationContext();
108108
this.context.register(SecureConfiguration.class);
109109
MockMvc mockMvc = createSecureMockMvc();
@@ -151,7 +151,7 @@ public void sensitiveEndpointsAreSecureByDefaultWithCustomContextPath()
151151
}
152152

153153
@Test
154-
public void sensitiveEndpointsAreSecureWithNonAdminRoleWithCustomContextPath()
154+
public void sensitiveEndpointsAreSecureWithNonActuatorRoleWithCustomContextPath()
155155
throws Exception {
156156
TestSecurityContextHolder.getContext().setAuthentication(
157157
new TestingAuthenticationToken("user", "N/A", "ROLE_USER"));
@@ -164,10 +164,10 @@ public void sensitiveEndpointsAreSecureWithNonAdminRoleWithCustomContextPath()
164164
}
165165

166166
@Test
167-
public void sensitiveEndpointsAreSecureWithAdminRoleWithCustomContextPath()
167+
public void sensitiveEndpointsAreSecureWithActuatorRoleWithCustomContextPath()
168168
throws Exception {
169169
TestSecurityContextHolder.getContext().setAuthentication(
170-
new TestingAuthenticationToken("user", "N/A", "ROLE_ADMIN"));
170+
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
171171
this.context = new AnnotationConfigWebApplicationContext();
172172
this.context.register(SecureConfiguration.class);
173173
EnvironmentTestUtils.addEnvironment(this.context,
@@ -199,7 +199,7 @@ public void endpointSecurityCanBeDisabled() throws Exception {
199199

200200
private void assertIndentedJsonResponse(Class<?> configuration) throws Exception {
201201
TestSecurityContextHolder.getContext().setAuthentication(
202-
new TestingAuthenticationToken("user", "N/A", "ROLE_ADMIN"));
202+
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
203203
this.context = new AnnotationConfigWebApplicationContext();
204204
this.context.register(configuration);
205205
EnvironmentTestUtils.addEnvironment(this.context,

spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected static class AuthenticationSecurity
7373
@Override
7474
public void init(AuthenticationManagerBuilder auth) throws Exception {
7575
auth.inMemoryAuthentication().withUser("admin").password("admin")
76-
.roles("ADMIN", "USER").and().withUser("user").password("user")
76+
.roles("ADMIN", "USER", "ACTUATOR").and().withUser("user").password("user")
7777
.roles("USER");
7878
}
7979

0 commit comments

Comments
 (0)