Commit 1be5812c authored by Madhura Bhave's avatar Madhura Bhave

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 gh-7569
parent 95be208f
...@@ -295,7 +295,7 @@ public class CrshAutoConfiguration { ...@@ -295,7 +295,7 @@ public class CrshAutoConfiguration {
CRaSHPlugin<AuthenticationPlugin> implements AuthenticationPlugin<String> { CRaSHPlugin<AuthenticationPlugin> implements AuthenticationPlugin<String> {
private static final PropertyDescriptor<String> ROLES = PropertyDescriptor.create( private static final PropertyDescriptor<String> ROLES = PropertyDescriptor.create(
"auth.spring.roles", "ADMIN", "auth.spring.roles", "ACTUATOR",
"Comma separated list of roles required to access the shell"); "Comma separated list of roles required to access the shell");
@Autowired @Autowired
...@@ -305,7 +305,7 @@ public class CrshAutoConfiguration { ...@@ -305,7 +305,7 @@ public class CrshAutoConfiguration {
@Qualifier("shellAccessDecisionManager") @Qualifier("shellAccessDecisionManager")
private AccessDecisionManager accessDecisionManager; private AccessDecisionManager accessDecisionManager;
private String[] roles = new String[] { "ADMIN" }; private String[] roles = new String[] { "ACTUATOR" };
@Override @Override
public boolean authenticate(String username, String password) throws Exception { public boolean authenticate(String username, String password) throws Exception {
......
...@@ -168,7 +168,7 @@ public class ManagementServerProperties implements SecurityPrerequisite { ...@@ -168,7 +168,7 @@ public class ManagementServerProperties implements SecurityPrerequisite {
/** /**
* Comma-separated list of roles that can access the management endpoint. * Comma-separated list of roles that can access the management endpoint.
*/ */
private List<String> roles = Arrays.asList("ADMIN"); private List<String> roles = Arrays.asList("ACTUATOR");
/** /**
* Session creating policy for security use (always, never, if_required, * Session creating policy for security use (always, never, if_required,
......
...@@ -524,7 +524,7 @@ public class ShellProperties { ...@@ -524,7 +524,7 @@ public class ShellProperties {
/** /**
* Comma-separated list of required roles to login to the CRaSH console. * Comma-separated list of required roles to login to the CRaSH console.
*/ */
private String[] roles = new String[] { "ADMIN" }; private String[] roles = new String[] { "ACTUATOR" };
@Override @Override
protected void applyToCrshShellConfig(Properties config) { protected void applyToCrshShellConfig(Properties config) {
......
...@@ -194,7 +194,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint ...@@ -194,7 +194,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
Authentication authentication = (Authentication) principal; Authentication authentication = (Authentication) principal;
List<String> roles = Arrays.asList(StringUtils List<String> roles = Arrays.asList(StringUtils
.trimArrayElements(StringUtils.commaDelimitedListToStringArray( .trimArrayElements(StringUtils.commaDelimitedListToStringArray(
this.roleResolver.getProperty("roles", "ROLE_ADMIN")))); this.roleResolver.getProperty("roles", "ROLE_ACTUATOR"))));
for (GrantedAuthority authority : authentication.getAuthorities()) { for (GrantedAuthority authority : authentication.getAuthorities()) {
String name = authority.getAuthority(); String name = authority.getAuthority();
for (String role : roles) { for (String role : roles) {
......
...@@ -347,7 +347,7 @@ public class CrshAutoConfigurationTests { ...@@ -347,7 +347,7 @@ public class CrshAutoConfigurationTests {
authentication = new UsernamePasswordAuthenticationToken( authentication = new UsernamePasswordAuthenticationToken(
authentication.getPrincipal(), authentication.getPrincipal(),
authentication.getCredentials(), Collections authentication.getCredentials(), Collections
.singleton(new SimpleGrantedAuthority("ADMIN"))); .singleton(new SimpleGrantedAuthority("ACTUATOR")));
} }
else { else {
throw new BadCredentialsException( throw new BadCredentialsException(
......
...@@ -120,7 +120,7 @@ public class ManagementWebSecurityAutoConfigurationTests { ...@@ -120,7 +120,7 @@ public class ManagementWebSecurityAutoConfigurationTests {
ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>( ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(
user.getAuthorities()); user.getAuthorities());
assertThat(authorities).containsAll(AuthorityUtils assertThat(authorities).containsAll(AuthorityUtils
.commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ADMIN")); .commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ACTUATOR"));
} }
private UserDetails getUser() { private UserDetails getUser() {
......
...@@ -68,7 +68,7 @@ public class MvcEndpointIntegrationTests { ...@@ -68,7 +68,7 @@ public class MvcEndpointIntegrationTests {
@Test @Test
public void defaultJsonResponseIsNotIndented() throws Exception { public void defaultJsonResponseIsNotIndented() throws Exception {
TestSecurityContextHolder.getContext().setAuthentication( TestSecurityContextHolder.getContext().setAuthentication(
new TestingAuthenticationToken("user", "N/A", "ROLE_ADMIN")); new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class); this.context.register(SecureConfiguration.class);
MockMvc mockMvc = createSecureMockMvc(); MockMvc mockMvc = createSecureMockMvc();
...@@ -103,7 +103,7 @@ public class MvcEndpointIntegrationTests { ...@@ -103,7 +103,7 @@ public class MvcEndpointIntegrationTests {
@Test @Test
public void jsonExtensionProvided() throws Exception { public void jsonExtensionProvided() throws Exception {
TestSecurityContextHolder.getContext().setAuthentication( TestSecurityContextHolder.getContext().setAuthentication(
new TestingAuthenticationToken("user", "N/A", "ROLE_ADMIN")); new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class); this.context.register(SecureConfiguration.class);
MockMvc mockMvc = createSecureMockMvc(); MockMvc mockMvc = createSecureMockMvc();
...@@ -151,7 +151,7 @@ public class MvcEndpointIntegrationTests { ...@@ -151,7 +151,7 @@ public class MvcEndpointIntegrationTests {
} }
@Test @Test
public void sensitiveEndpointsAreSecureWithNonAdminRoleWithCustomContextPath() public void sensitiveEndpointsAreSecureWithNonActuatorRoleWithCustomContextPath()
throws Exception { throws Exception {
TestSecurityContextHolder.getContext().setAuthentication( TestSecurityContextHolder.getContext().setAuthentication(
new TestingAuthenticationToken("user", "N/A", "ROLE_USER")); new TestingAuthenticationToken("user", "N/A", "ROLE_USER"));
...@@ -164,10 +164,10 @@ public class MvcEndpointIntegrationTests { ...@@ -164,10 +164,10 @@ public class MvcEndpointIntegrationTests {
} }
@Test @Test
public void sensitiveEndpointsAreSecureWithAdminRoleWithCustomContextPath() public void sensitiveEndpointsAreSecureWithActuatorRoleWithCustomContextPath()
throws Exception { throws Exception {
TestSecurityContextHolder.getContext().setAuthentication( TestSecurityContextHolder.getContext().setAuthentication(
new TestingAuthenticationToken("user", "N/A", "ROLE_ADMIN")); new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class); this.context.register(SecureConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, EnvironmentTestUtils.addEnvironment(this.context,
...@@ -199,7 +199,7 @@ public class MvcEndpointIntegrationTests { ...@@ -199,7 +199,7 @@ public class MvcEndpointIntegrationTests {
private void assertIndentedJsonResponse(Class<?> configuration) throws Exception { private void assertIndentedJsonResponse(Class<?> configuration) throws Exception {
TestSecurityContextHolder.getContext().setAuthentication( TestSecurityContextHolder.getContext().setAuthentication(
new TestingAuthenticationToken("user", "N/A", "ROLE_ADMIN")); new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
this.context.register(configuration); this.context.register(configuration);
EnvironmentTestUtils.addEnvironment(this.context, EnvironmentTestUtils.addEnvironment(this.context,
......
...@@ -73,7 +73,7 @@ public class SampleMethodSecurityApplication extends WebMvcConfigurerAdapter { ...@@ -73,7 +73,7 @@ public class SampleMethodSecurityApplication extends WebMvcConfigurerAdapter {
@Override @Override
public void init(AuthenticationManagerBuilder auth) throws Exception { public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("admin").password("admin") auth.inMemoryAuthentication().withUser("admin").password("admin")
.roles("ADMIN", "USER").and().withUser("user").password("user") .roles("ADMIN", "USER", "ACTUATOR").and().withUser("user").password("user")
.roles("USER"); .roles("USER");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment