Skip to content

Commit 989a7d6

Browse files
authored
Add indices permissions to Enterprise Search service account (#85726)
1 parent 6598d90 commit 989a7d6

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

docs/changelog/85726.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 85726
2+
summary: Add indices permissions to Enterprise Search service account
3+
area: Authorization
4+
type: enhancement
5+
issues: []

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ public class ServiceAccountIT extends ESRestTestCase {
171171
"write"
172172
],
173173
"allow_restricted_indices": false
174+
},
175+
{
176+
"names": [
177+
"search-*"
178+
],
179+
"privileges": [
180+
"read",
181+
"view_index_metadata"
182+
],
183+
"allow_restricted_indices": false
174184
}
175185
],
176186
"applications": [],

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ final class ElasticServiceAccounts {
4343
"logs-workplace_search.content_events-default"
4444
)
4545
.privileges("manage", "read", "write")
46-
.build() },
46+
.build(),
47+
RoleDescriptor.IndicesPrivileges.builder().indices("search-*").privileges("read", "view_index_metadata").build() },
4748
null,
4849
null,
4950
null,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction;
2121
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction;
2222
import org.elasticsearch.action.bulk.BulkAction;
23+
import org.elasticsearch.action.datastreams.GetDataStreamAction;
2324
import org.elasticsearch.action.delete.DeleteAction;
2425
import org.elasticsearch.action.get.GetAction;
2526
import org.elasticsearch.action.get.MultiGetAction;
@@ -31,6 +32,7 @@
3132
import org.elasticsearch.common.Strings;
3233
import org.elasticsearch.test.ESTestCase;
3334
import org.elasticsearch.transport.TransportRequest;
35+
import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction;
3436
import org.elasticsearch.xpack.core.ilm.action.GetLifecycleAction;
3537
import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction;
3638
import org.elasticsearch.xpack.core.ml.action.CloseJobAction;
@@ -367,6 +369,19 @@ public void testElasticEnterpriseSearchServerAccount() {
367369
assertThat(role.indices().allowedIndicesMatcher(RefreshAction.NAME).test(enterpriseSearchIndex), is(true));
368370
assertThat(role.indices().allowedIndicesMatcher("indices:foo").test(enterpriseSearchIndex), is(false));
369371
});
372+
373+
final IndexAbstraction elasticsearchIndex = mockIndexAbstraction("search-" + randomAlphaOfLengthBetween(1, 20));
374+
// read
375+
assertThat(role.indices().allowedIndicesMatcher(GetAction.NAME).test(elasticsearchIndex), is(true));
376+
assertThat(role.indices().allowedIndicesMatcher(MultiGetAction.NAME).test(elasticsearchIndex), is(true));
377+
assertThat(role.indices().allowedIndicesMatcher(SearchAction.NAME).test(elasticsearchIndex), is(true));
378+
assertThat(role.indices().allowedIndicesMatcher(MultiSearchAction.NAME).test(elasticsearchIndex), is(true));
379+
// view_index_metadata
380+
assertThat(role.indices().allowedIndicesMatcher(GetDataStreamAction.NAME).test(elasticsearchIndex), is(true));
381+
assertThat(role.indices().allowedIndicesMatcher(ExplainLifecycleAction.NAME).test(elasticsearchIndex), is(true));
382+
// ingestion and delete are forbidden
383+
assertThat(role.indices().allowedIndicesMatcher(IndexAction.NAME).test(elasticsearchIndex), is(false));
384+
assertThat(role.indices().allowedIndicesMatcher(DeleteAction.NAME).test(elasticsearchIndex), is(false));
370385
}
371386

372387
private IndexAbstraction mockIndexAbstraction(String name) {

0 commit comments

Comments
 (0)