Skip to content

Commit 00b9791

Browse files
committed
APM system_user (elastic#47668)
* Add test for APM beats index perms * Grant monitoring index privs to apm_system user * Review feedback * Fix compilation problem
1 parent f6b4d26 commit 00b9791

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStore.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
148148
},
149149
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
150150
.put(UsernamesField.APM_ROLE, new RoleDescriptor(UsernamesField.APM_ROLE,
151-
new String[] { "monitor", MonitoringBulkAction.NAME}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA))
151+
new String[] { "monitor", MonitoringBulkAction.NAME},
152+
new RoleDescriptor.IndicesPrivileges[]{
153+
RoleDescriptor.IndicesPrivileges.builder()
154+
.indices(".monitoring-beats-*").privileges("create_index", "create_doc").build()
155+
},
156+
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
152157
.put("apm_user", new RoleDescriptor("apm_user",
153158
null, new RoleDescriptor.IndicesPrivileges[] {
154159
RoleDescriptor.IndicesPrivileges.builder().indices("apm-*")

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ public void testBeatsSystemRole() {
892892

893893

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

933+
final String index = ".monitoring-beats-" + randomIntBetween(10, 15);
934+
logger.info("APM beats monitoring index name [{}]", index);
935+
936+
assertThat(APMSystemRole.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(index), is(true));
937+
assertThat(APMSystemRole.indices().allowedIndicesMatcher("indices:data/write/index:op_type/create").test(index), is(true));
938+
assertThat(APMSystemRole.indices().allowedIndicesMatcher(DeleteAction.NAME).test(index), is(false));
939+
assertThat(APMSystemRole.indices().allowedIndicesMatcher(BulkAction.NAME).test(index), is(true));
940+
941+
assertThat(APMSystemRole.indices().allowedIndicesMatcher("indices:data/write/index:op_type/index").test(index), is(false));
942+
assertThat(APMSystemRole.indices().allowedIndicesMatcher(
943+
"indices:data/write/index:op_type/" + randomAlphaOfLengthBetween(3,5)).test(index), is(false));
944+
933945
assertNoAccessAllowed(APMSystemRole, RestrictedIndicesNames.RESTRICTED_NAMES);
946+
934947
}
935948

936949
public void testAPMUserRole() {

0 commit comments

Comments
 (0)