Skip to content

Commit

Permalink
APM system_user (elastic#47668)
Browse files Browse the repository at this point in the history
* Add test for APM beats index perms

* Grant monitoring index privs to apm_system user

* Review feedback

* Fix compilation problem
  • Loading branch information
cachedout authored and SivagurunathanV committed Jan 21, 2020
1 parent b7ffb2b commit a16ebaf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
},
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))
new String[] { "monitor", MonitoringBulkAction.NAME},
new RoleDescriptor.IndicesPrivileges[]{
RoleDescriptor.IndicesPrivileges.builder()
.indices(".monitoring-beats-*").privileges("create_index", "create_doc").build()
},
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
.put("apm_user", new RoleDescriptor("apm_user",
null, new RoleDescriptor.IndicesPrivileges[] {
RoleDescriptor.IndicesPrivileges.builder().indices("apm-*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public void testBeatsSystemRole() {


final String index = ".monitoring-beats-" + randomIntBetween(0, 5);;
logger.info("index name [{}]", index);
logger.info("beats monitoring index name [{}]", index);
assertThat(beatsSystemRole.indices().allowedIndicesMatcher(IndexAction.NAME).test("foo"), is(false));
assertThat(beatsSystemRole.indices().allowedIndicesMatcher(IndexAction.NAME).test(".reporting"), is(false));
assertThat(beatsSystemRole.indices().allowedIndicesMatcher("indices:foo").test(randomAlphaOfLengthBetween(8, 24)),
Expand Down Expand Up @@ -930,7 +930,20 @@ public void testAPMSystemRole() {
assertThat(APMSystemRole.indices().allowedIndicesMatcher("indices:foo").test(randomAlphaOfLengthBetween(8, 24)),
is(false));

final String index = ".monitoring-beats-" + randomIntBetween(10, 15);
logger.info("APM beats monitoring index name [{}]", index);

assertThat(APMSystemRole.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(index), is(true));
assertThat(APMSystemRole.indices().allowedIndicesMatcher("indices:data/write/index:op_type/create").test(index), is(true));
assertThat(APMSystemRole.indices().allowedIndicesMatcher(DeleteAction.NAME).test(index), is(false));
assertThat(APMSystemRole.indices().allowedIndicesMatcher(BulkAction.NAME).test(index), is(true));

assertThat(APMSystemRole.indices().allowedIndicesMatcher("indices:data/write/index:op_type/index").test(index), is(false));
assertThat(APMSystemRole.indices().allowedIndicesMatcher(
"indices:data/write/index:op_type/" + randomAlphaOfLengthBetween(3,5)).test(index), is(false));

assertNoAccessAllowed(APMSystemRole, RestrictedIndicesNames.RESTRICTED_NAMES);

}

public void testAPMUserRole() {
Expand Down

0 comments on commit a16ebaf

Please sign in to comment.