Skip to content

Commit

Permalink
Add apm_user reserved role (#38206)
Browse files Browse the repository at this point in the history
* Adding apm_user

* Fixing SecurityDocumentationIT testGetRoles test

* Adding access to .ml-anomalies-*

* Fixing APM test, we don't have access to the ML state index
  • Loading branch information
kobelb authored Feb 5, 2019
1 parent fe36861 commit 64ff75f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ public void testGetRoles() throws Exception {

List<Role> roles = response.getRoles();
assertNotNull(response);
// 24 system roles plus the three we created
assertThat(roles.size(), equalTo(27));
// 25 system roles plus the three we created
assertThat(roles.size(), equalTo(28));
}

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
new String[] { "monitor", MonitoringBulkAction.NAME}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA))
.put(UsernamesField.APM_ROLE, new RoleDescriptor(UsernamesField.APM_ROLE,
new String[] { "monitor", MonitoringBulkAction.NAME}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA))
.put("apm_user", new RoleDescriptor("apm_user",
null, new RoleDescriptor.IndicesPrivileges[] {
RoleDescriptor.IndicesPrivileges.builder().indices("apm-*")
.privileges("read", "view_index_metadata").build(),
RoleDescriptor.IndicesPrivileges.builder().indices(".ml-anomalies*")
.privileges("view_index_metadata", "read").build(),
}, null, MetadataUtils.DEFAULT_RESERVED_METADATA))
.put("machine_learning_user", new RoleDescriptor("machine_learning_user", new String[] { "monitor_ml" },
new RoleDescriptor.IndicesPrivileges[] {
RoleDescriptor.IndicesPrivileges.builder().indices(".ml-anomalies*", ".ml-notifications*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,23 @@ public void testAPMSystemRole() {
assertNoAccessAllowed(APMSystemRole, RestrictedIndicesNames.NAMES_SET);
}

public void testAPMUserRole() {
final TransportRequest request = mock(TransportRequest.class);

final RoleDescriptor roleDescriptor = new ReservedRolesStore().roleDescriptor("apm_user");
assertNotNull(roleDescriptor);
assertThat(roleDescriptor.getMetadata(), hasEntry("_reserved", true));

Role role = Role.builder(roleDescriptor, null).build();

assertThat(role.runAs().check(randomAlphaOfLengthBetween(1, 12)), is(false));

assertNoAccessAllowed(role, "foo");

assertOnlyReadAllowed(role, "apm-" + randomIntBetween(0, 5));
assertOnlyReadAllowed(role, AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + AnomalyDetectorsIndexFields.RESULTS_INDEX_DEFAULT);
}

public void testMachineLearningAdminRole() {
final TransportRequest request = mock(TransportRequest.class);

Expand Down

0 comments on commit 64ff75f

Please sign in to comment.