Sfoglia il codice sorgente

Add privileges for Fleet example package for transforms (#90037)

As a companion to elastic/kibana#140046 an example transform
package is being created in elastic/integrations#4138.

Initially the intention was that this example would use the
Kibana sample data. Then, after realising that wouldn't work
due to lack of permissions, it was changed to reinstall a
transform that is created by the security solution. However,
it has been pointed out that this is dangerous because even
if we tell people not to install the example in production
it could somehow happen by mistake and then we'd have created
objects that clash with production code.

Therefore, it is best that the example transform package be
switched back to the original idea of using the Kibana sample
data, so that there is no risk of it ever clashing with a
production package.
David Roberts 3 anni fa
parent
commit
0fde08853e

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

@@ -813,6 +813,11 @@ public class ReservedRolesStore implements BiConsumer<Set<String>, ActionListene
                     )
                     )
                     .privileges("create_index", "delete_index", "read", "index")
                     .privileges("create_index", "delete_index", "read", "index")
                     .build(),
                     .build(),
+                // For src/dest indices of the example transform package
+                RoleDescriptor.IndicesPrivileges.builder()
+                    .indices("kibana_sample_data_*")
+                    .privileges("create_index", "delete_index", "read", "index", "view_index_metadata")
+                    .build(),
                 // For src/dest indices of the Cloud Security Posture packages that ships a transform
                 // For src/dest indices of the Cloud Security Posture packages that ships a transform
                 RoleDescriptor.IndicesPrivileges.builder()
                 RoleDescriptor.IndicesPrivileges.builder()
                     .indices("logs-cloud_security_posture.findings-*")
                     .indices("logs-cloud_security_posture.findings-*")

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

@@ -1109,6 +1109,27 @@ public class ReservedRolesStoreTests extends ESTestCase {
             assertThat(kibanaRole.indices().allowedIndicesMatcher(RolloverAction.NAME).test(indexAbstraction), is(true));
             assertThat(kibanaRole.indices().allowedIndicesMatcher(RolloverAction.NAME).test(indexAbstraction), is(true));
             assertThat(kibanaRole.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(indexAbstraction), is(true));
             assertThat(kibanaRole.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(indexAbstraction), is(true));
         });
         });
+
+        // Example transform package
+        Arrays.asList("kibana_sample_data_ecommerce", "kibana_sample_data_ecommerce_transform" + randomInt()).forEach(indexName -> {
+            final IndexAbstraction indexAbstraction = mockIndexAbstraction(indexName);
+            // Allow search and indexing
+            assertThat(kibanaRole.indices().allowedIndicesMatcher(SearchAction.NAME).test(indexAbstraction), is(true));
+            assertThat(kibanaRole.indices().allowedIndicesMatcher(GetAction.NAME).test(indexAbstraction), is(true));
+            assertThat(kibanaRole.indices().allowedIndicesMatcher(IndexAction.NAME).test(indexAbstraction), is(true));
+            assertThat(kibanaRole.indices().allowedIndicesMatcher(UpdateAction.NAME).test(indexAbstraction), is(true));
+            assertThat(kibanaRole.indices().allowedIndicesMatcher(BulkAction.NAME).test(indexAbstraction), is(true));
+            // Allow create and delete index
+            assertThat(kibanaRole.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(indexAbstraction), is(true));
+            assertThat(kibanaRole.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(indexAbstraction), is(true));
+
+            // Implied by the overall view_index_metadata and monitor privilege
+            assertViewIndexMetadata(kibanaRole, indexName);
+            assertThat(
+                kibanaRole.indices().allowedIndicesMatcher("indices:monitor/" + randomAlphaOfLengthBetween(3, 8)).test(indexAbstraction),
+                is(true)
+            );
+        });
     }
     }
 
 
     public void testKibanaAdminRole() {
     public void testKibanaAdminRole() {