Skip to content

Commit ef1f7a5

Browse files
axwywangdelasticmachine
authored
Extend fleet-server service account privileges (#82600)
* Extend fleet-server service account privileges Allow elastic/fleet-server service account to additionally read, monitor, and refresh traces-apm.sampled-* data streams. These data streams do not contain any sensitive information. Fleet-server itself does not need to perform these actions, but it creates API Keys for APM Server, which does need to. * Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/service/ElasticServiceAccounts.java Co-authored-by: Yang Wang <[email protected]> * Apply suggestions from code review Co-authored-by: Yang Wang <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent b2f2e3a commit ef1f7a5

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

x-pack/docs/en/rest-api/security/get-service-accounts.asciidoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ GET /_security/service/elastic/fleet-server
8484
],
8585
"allow_restricted_indices": false
8686
},
87+
{
88+
"names" : [
89+
"traces-apm.sampled-*"
90+
],
91+
"privileges" : [
92+
"read",
93+
"monitor",
94+
"maintenance"
95+
],
96+
"allow_restricted_indices": false
97+
},
8798
{
8899
"names": [
89100
".fleet-*"

x-pack/plugin/security/qa/service-account/src/javaRestTest/java/org/elasticsearch/xpack/security/authc/service/ServiceAccountIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ public class ServiceAccountIT extends ESRestTestCase {
101101
],
102102
"allow_restricted_indices": false
103103
},
104+
{
105+
"names": [
106+
"traces-apm.sampled-*"
107+
],
108+
"privileges": [
109+
"read",
110+
"monitor",
111+
"maintenance"
112+
],
113+
"allow_restricted_indices": false
114+
},
104115
{
105116
"names": [
106117
".fleet-*"

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/service/ElasticServiceAccounts.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ final class ElasticServiceAccounts {
3939
)
4040
.privileges("write", "create_index", "auto_configure")
4141
.build(),
42+
RoleDescriptor.IndicesPrivileges.builder()
43+
// APM Server (and hence Fleet Server, which issues its API Keys) needs additional privileges
44+
// for the non-sensitive "sampled traces" data stream:
45+
// - "maintenance" privilege to refresh indices
46+
// - "monitor" privilege to be able to query index stats for the global checkpoint
47+
// - "read" privilege to search the documents
48+
.indices("traces-apm.sampled-*")
49+
.privileges("read", "monitor", "maintenance")
50+
.build(),
4251
RoleDescriptor.IndicesPrivileges.builder()
4352
.indices(".fleet-*")
4453
// Fleet Server needs "maintenance" privilege to be able to perform operations with "refresh"

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/ElasticServiceAccountsTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,19 @@ public void testElasticFleetServerPrivileges() {
206206
assertThat(role.indices().allowedIndicesMatcher("indices:foo").test(dotFleetIndex), is(false));
207207
});
208208

209+
final IndexAbstraction apmSampledTracesIndex = mockIndexAbstraction("traces-apm.sampled-" + randomAlphaOfLengthBetween(1, 20));
210+
assertThat(role.indices().allowedIndicesMatcher(DeleteAction.NAME).test(apmSampledTracesIndex), is(true));
211+
assertThat(role.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(apmSampledTracesIndex), is(true));
212+
assertThat(role.indices().allowedIndicesMatcher(IndexAction.NAME).test(apmSampledTracesIndex), is(true));
213+
assertThat(role.indices().allowedIndicesMatcher(BulkAction.NAME).test(apmSampledTracesIndex), is(true));
214+
assertThat(role.indices().allowedIndicesMatcher(GetAction.NAME).test(apmSampledTracesIndex), is(true));
215+
assertThat(role.indices().allowedIndicesMatcher(MultiGetAction.NAME).test(apmSampledTracesIndex), is(true));
216+
assertThat(role.indices().allowedIndicesMatcher(SearchAction.NAME).test(apmSampledTracesIndex), is(true));
217+
assertThat(role.indices().allowedIndicesMatcher(MultiSearchAction.NAME).test(apmSampledTracesIndex), is(true));
218+
assertThat(role.indices().allowedIndicesMatcher(IndicesStatsAction.NAME).test(apmSampledTracesIndex), is(true));
219+
assertThat(role.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(apmSampledTracesIndex), is(false));
220+
assertThat(role.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(apmSampledTracesIndex), is(false));
221+
209222
final String kibanaApplication = "kibana-" + randomFrom(randomAlphaOfLengthBetween(8, 24), ".kibana");
210223
final String privilegeName = randomAlphaOfLengthBetween(3, 16);
211224
assertThat(

0 commit comments

Comments
 (0)