Skip to content

Commit 5f6e9c7

Browse files
authored
Add delete privilege to kibana_system for APM and Endpoint ILM policies (#81811) (#81872)
1 parent 91d5f27 commit 5f6e9c7

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.action.admin.cluster.remote.RemoteInfoAction;
1111
import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesAction;
1212
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction;
13+
import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
1314
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction;
1415
import org.elasticsearch.action.admin.indices.rollover.RolloverAction;
1516
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsAction;
@@ -697,6 +698,11 @@ public static RoleDescriptor kibanaSystemRoleDescriptor(String name) {
697698
)
698699
.privileges(UpdateSettingsAction.NAME, PutMappingAction.NAME, RolloverAction.NAME)
699700
.build(),
701+
// For ILM policy for APM & Endpoint packages that have delete action
702+
RoleDescriptor.IndicesPrivileges.builder()
703+
.indices(".logs-endpoint.diagnostic.collection-*", "traces-apm.sampled-*")
704+
.privileges(DeleteIndexAction.NAME)
705+
.build(),
700706
// For src/dest indices of the Endpoint package that ships a transform
701707
RoleDescriptor.IndicesPrivileges.builder()
702708
.indices("metrics-endpoint.metadata*")

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ public void testKibanaSystemRole() {
551551
Arrays.asList(".logs-endpoint.diagnostic.collection-" + randomAlphaOfLength(randomIntBetween(0, 13))).forEach((index) -> {
552552
assertThat(kibanaRole.indices().allowedIndicesMatcher("indices:foo").test(mockIndexAbstraction(index)), is(false));
553553
assertThat(kibanaRole.indices().allowedIndicesMatcher("indices:bar").test(mockIndexAbstraction(index)), is(false));
554-
assertThat(kibanaRole.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(mockIndexAbstraction(index)), is(false));
555554
assertThat(kibanaRole.indices().allowedIndicesMatcher(GetIndexAction.NAME).test(mockIndexAbstraction(index)), is(true));
556555
assertThat(kibanaRole.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(mockIndexAbstraction(index)), is(false));
557556
assertThat(kibanaRole.indices().allowedIndicesMatcher(IndexAction.NAME).test(mockIndexAbstraction(index)), is(false));
@@ -565,6 +564,8 @@ public void testKibanaSystemRole() {
565564
assertThat(kibanaRole.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(mockIndexAbstraction(index)), is(true));
566565
assertThat(kibanaRole.indices().allowedIndicesMatcher(PutMappingAction.NAME).test(mockIndexAbstraction(index)), is(true));
567566
assertThat(kibanaRole.indices().allowedIndicesMatcher(RolloverAction.NAME).test(mockIndexAbstraction(index)), is(true));
567+
// Privileges needed for installing current ILM policy with delete action
568+
assertThat(kibanaRole.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(mockIndexAbstraction(index)), is(true));
568569
});
569570

570571
Arrays.asList(
@@ -708,7 +709,6 @@ public void testKibanaSystemRole() {
708709
assertThat(kibanaRole.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(indexAbstraction), is(false));
709710
assertThat(kibanaRole.indices().allowedIndicesMatcher(AutoCreateAction.NAME).test(indexAbstraction), is(false));
710711
assertThat(kibanaRole.indices().allowedIndicesMatcher(CreateDataStreamAction.NAME).test(indexAbstraction), is(false));
711-
assertThat(kibanaRole.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(indexAbstraction), is(false));
712712
assertThat(kibanaRole.indices().allowedIndicesMatcher(IndexAction.NAME).test(indexAbstraction), is(false));
713713
assertThat(kibanaRole.indices().allowedIndicesMatcher(DeleteAction.NAME).test(indexAbstraction), is(false));
714714

@@ -717,6 +717,11 @@ public void testKibanaSystemRole() {
717717
assertThat(kibanaRole.indices().allowedIndicesMatcher(GetAction.NAME).test(indexAbstraction), is(isAlsoReadIndex));
718718
assertThat(kibanaRole.indices().allowedIndicesMatcher(SearchAction.NAME).test(indexAbstraction), is(isAlsoReadIndex));
719719
assertThat(kibanaRole.indices().allowedIndicesMatcher(MultiSearchAction.NAME).test(indexAbstraction), is(isAlsoReadIndex));
720+
721+
// Endpoint diagnostic and sampled traces data streams also have an ILM policy with a delete action, all others should not.
722+
final boolean isAlsoIlmDeleteIndex = indexName.startsWith(".logs-endpoint.diagnostic.collection-")
723+
|| indexName.startsWith("traces-apm.sampled-");
724+
assertThat(kibanaRole.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(indexAbstraction), is(isAlsoIlmDeleteIndex));
720725
});
721726

722727
// 4. Transform for endpoint package
@@ -782,6 +787,31 @@ public void testKibanaSystemRole() {
782787
assertThat(kibanaRole.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(indexAbstraction), is(false));
783788
assertThat(kibanaRole.indices().allowedIndicesMatcher(RolloverAction.NAME).test(indexAbstraction), is(false));
784789
});
790+
791+
// Ensure privileges necessary for ILM policies in APM & Endpoint packages
792+
Arrays.asList(
793+
"metrics-apm.app-" + randomAlphaOfLengthBetween(3, 8),
794+
"metrics-apm.internal-" + randomAlphaOfLengthBetween(3, 8),
795+
"metrics-apm.profiling-" + randomAlphaOfLengthBetween(3, 8),
796+
"logs-apm.error_logs-" + randomAlphaOfLengthBetween(3, 8),
797+
"traces-apm-" + randomAlphaOfLengthBetween(3, 8)
798+
).forEach(indexName -> {
799+
logger.info("index name [{}]", indexName);
800+
final IndexAbstraction indexAbstraction = mockIndexAbstraction(indexName);
801+
802+
assertThat(kibanaRole.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(indexAbstraction), is(true));
803+
assertThat(kibanaRole.indices().allowedIndicesMatcher(RolloverAction.NAME).test(indexAbstraction), is(true));
804+
});
805+
Arrays.asList(
806+
".logs-endpoint.diagnostic.collection-" + randomAlphaOfLengthBetween(3, 8),
807+
"traces-apm.sampled-" + randomAlphaOfLengthBetween(3, 8)
808+
).forEach(indexName -> {
809+
logger.info("index name [{}]", indexName);
810+
final IndexAbstraction indexAbstraction = mockIndexAbstraction(indexName);
811+
812+
assertThat(kibanaRole.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(indexAbstraction), is(true));
813+
assertThat(kibanaRole.indices().allowedIndicesMatcher(RolloverAction.NAME).test(indexAbstraction), is(true));
814+
});
785815
}
786816

787817
public void testKibanaAdminRole() {

0 commit comments

Comments
 (0)