Skip to content

Commit 83b7947

Browse files
ycombinatorGurkan Kaymak
authored and
Gurkan Kaymak
committed
Expand beats_system role privileges (elastic#40876)
Traditionally we have [recommended](https://www.elastic.co/guide/en/beats/filebeat/current/monitoring.html) that Beats send their monitoring data to the **production** Elasticsearch cluster. Beats do this by calling the `POST _monitoring/bulk` API. When Security is enabled this API call requires the `cluster:admin/xpack/monitoring/bulk` privilege. The built-in `beats_system` role has this privilege. [Going forward](elastic/beats#9260), Beats will be able to send their monitoring data directly to the **monitoring** Elasticsearch cluster. Beats will do this by calling the regular `POST _bulk` API. When Security is enabled this API call requires the `indices:data/write/bulk` privilege. Further, the call has to be able to create any indices that don't exist. This PR expands the built-in `beats_system` role's privileges. Specifically, it adds index-level `write` and `create_index` privileges for `.monitoring-beats-*` indices. This will allow Beats users to continue using the `beats_system` role for the new direct monitoring route when Security is enabled.
1 parent 89cef32 commit 83b7947

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
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
@@ -133,7 +133,12 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
133133
},
134134
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
135135
.put(UsernamesField.BEATS_ROLE, new RoleDescriptor(UsernamesField.BEATS_ROLE,
136-
new String[] { "monitor", MonitoringBulkAction.NAME}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA))
136+
new String[] { "monitor", MonitoringBulkAction.NAME},
137+
new RoleDescriptor.IndicesPrivileges[]{
138+
RoleDescriptor.IndicesPrivileges.builder()
139+
.indices(".monitoring-beats-*").privileges("create_index", "create").build()
140+
},
141+
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
137142
.put(UsernamesField.APM_ROLE, new RoleDescriptor(UsernamesField.APM_ROLE,
138143
new String[] { "monitor", MonitoringBulkAction.NAME}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA))
139144
.put("apm_user", new RoleDescriptor("apm_user",

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

+20-13
Original file line numberDiff line numberDiff line change
@@ -838,23 +838,30 @@ public void testBeatsSystemRole() {
838838
assertNotNull(roleDescriptor);
839839
assertThat(roleDescriptor.getMetadata(), hasEntry("_reserved", true));
840840

841-
Role logstashSystemRole = Role.builder(roleDescriptor, null).build();
842-
assertThat(logstashSystemRole.cluster().check(ClusterHealthAction.NAME, request), is(true));
843-
assertThat(logstashSystemRole.cluster().check(ClusterStateAction.NAME, request), is(true));
844-
assertThat(logstashSystemRole.cluster().check(ClusterStatsAction.NAME, request), is(true));
845-
assertThat(logstashSystemRole.cluster().check(PutIndexTemplateAction.NAME, request), is(false));
846-
assertThat(logstashSystemRole.cluster().check(ClusterRerouteAction.NAME, request), is(false));
847-
assertThat(logstashSystemRole.cluster().check(ClusterUpdateSettingsAction.NAME, request), is(false));
848-
assertThat(logstashSystemRole.cluster().check(MonitoringBulkAction.NAME, request), is(true));
841+
Role beatsSystemRole = Role.builder(roleDescriptor, null).build();
842+
assertThat(beatsSystemRole.cluster().check(ClusterHealthAction.NAME, request), is(true));
843+
assertThat(beatsSystemRole.cluster().check(ClusterStateAction.NAME, request), is(true));
844+
assertThat(beatsSystemRole.cluster().check(ClusterStatsAction.NAME, request), is(true));
845+
assertThat(beatsSystemRole.cluster().check(PutIndexTemplateAction.NAME, request), is(false));
846+
assertThat(beatsSystemRole.cluster().check(ClusterRerouteAction.NAME, request), is(false));
847+
assertThat(beatsSystemRole.cluster().check(ClusterUpdateSettingsAction.NAME, request), is(false));
848+
assertThat(beatsSystemRole.cluster().check(MonitoringBulkAction.NAME, request), is(true));
849849

850-
assertThat(logstashSystemRole.runAs().check(randomAlphaOfLengthBetween(1, 30)), is(false));
850+
assertThat(beatsSystemRole.runAs().check(randomAlphaOfLengthBetween(1, 30)), is(false));
851851

852-
assertThat(logstashSystemRole.indices().allowedIndicesMatcher(IndexAction.NAME).test("foo"), is(false));
853-
assertThat(logstashSystemRole.indices().allowedIndicesMatcher(IndexAction.NAME).test(".reporting"), is(false));
854-
assertThat(logstashSystemRole.indices().allowedIndicesMatcher("indices:foo").test(randomAlphaOfLengthBetween(8, 24)),
852+
853+
final String index = ".monitoring-beats-" + randomIntBetween(0, 5);;
854+
logger.info("index name [{}]", index);
855+
assertThat(beatsSystemRole.indices().allowedIndicesMatcher(IndexAction.NAME).test("foo"), is(false));
856+
assertThat(beatsSystemRole.indices().allowedIndicesMatcher(IndexAction.NAME).test(".reporting"), is(false));
857+
assertThat(beatsSystemRole.indices().allowedIndicesMatcher("indices:foo").test(randomAlphaOfLengthBetween(8, 24)),
855858
is(false));
859+
assertThat(beatsSystemRole.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(index), is(true));
860+
assertThat(beatsSystemRole.indices().allowedIndicesMatcher(IndexAction.NAME).test(index), is(true));
861+
assertThat(beatsSystemRole.indices().allowedIndicesMatcher(DeleteAction.NAME).test(index), is(false));
862+
assertThat(beatsSystemRole.indices().allowedIndicesMatcher(BulkAction.NAME).test(index), is(true));
856863

857-
assertNoAccessAllowed(logstashSystemRole, RestrictedIndicesNames.RESTRICTED_NAMES);
864+
assertNoAccessAllowed(beatsSystemRole, RestrictedIndicesNames.RESTRICTED_NAMES);
858865
}
859866

860867
public void testAPMSystemRole() {

0 commit comments

Comments
 (0)