Skip to content

Commit eb65624

Browse files
committed
Add Kibana application privileges for monitoring and ml reserved roles (#40651)
* Add Kibana application privileges for monitoring and ml reserved roles * Adding test for kibana-.kibana application explicitly * Whoa there, fat fingered kibana and application... * And I copied something from monitoring I shouldn't have... * And actually doing what Yogesh recommended...
1 parent 665f0d8 commit eb65624

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
5757
new RoleDescriptor.IndicesPrivileges[] {
5858
RoleDescriptor.IndicesPrivileges.builder()
5959
.indices(".monitoring-*").privileges("read", "read_cross_cluster").build()
60-
},
61-
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
60+
},
61+
new RoleDescriptor.ApplicationResourcePrivileges[] {
62+
RoleDescriptor.ApplicationResourcePrivileges.builder()
63+
.application("kibana-*").resources("*").privileges("reserved_monitoring").build()
64+
},
65+
null, null, MetadataUtils.DEFAULT_RESERVED_METADATA, null))
6266
.put("remote_monitoring_agent", new RoleDescriptor("remote_monitoring_agent",
6367
new String[] {
6468
"manage_index_templates", "manage_ingest_pipelines", "monitor",
@@ -146,7 +150,11 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
146150
RoleDescriptor.IndicesPrivileges.builder().indices(".ml-annotations*")
147151
.privileges("view_index_metadata", "read", "write").build()
148152
},
149-
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
153+
new RoleDescriptor.ApplicationResourcePrivileges[] {
154+
RoleDescriptor.ApplicationResourcePrivileges.builder()
155+
.application("kibana-*").resources("*").privileges("reserved_ml").build()
156+
},
157+
null, null, MetadataUtils.DEFAULT_RESERVED_METADATA, null))
150158
.put("machine_learning_admin", new RoleDescriptor("machine_learning_admin", new String[] { "manage_ml" },
151159
new RoleDescriptor.IndicesPrivileges[] {
152160
RoleDescriptor.IndicesPrivileges.builder()
@@ -155,7 +163,11 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
155163
RoleDescriptor.IndicesPrivileges.builder().indices(".ml-annotations*")
156164
.privileges("view_index_metadata", "read", "write").build()
157165
},
158-
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
166+
new RoleDescriptor.ApplicationResourcePrivileges[] {
167+
RoleDescriptor.ApplicationResourcePrivileges.builder()
168+
.application("kibana-*").resources("*").privileges("reserved_ml").build()
169+
},
170+
null, null, MetadataUtils.DEFAULT_RESERVED_METADATA, null))
159171
.put("data_frame_transforms_admin", new RoleDescriptor("data_frame_transforms_admin",
160172
new String[] { "manage_data_frame_transforms" },
161173
new RoleDescriptor.IndicesPrivileges[]{

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

+37
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ public void testMonitoringUserRole() {
452452
assertThat(monitoringUserRole.indices().allowedIndicesMatcher(READ_CROSS_CLUSTER_NAME).test(index), is(true));
453453

454454
assertNoAccessAllowed(monitoringUserRole, RestrictedIndicesNames.RESTRICTED_NAMES);
455+
456+
final String kibanaApplicationWithRandomIndex = "kibana-" + randomFrom(randomAlphaOfLengthBetween(8, 24), ".kibana");
457+
assertThat(monitoringUserRole.application().grants(
458+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-foo", "foo"), "*"), is(false));
459+
assertThat(monitoringUserRole.application().grants(
460+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-reserved_monitoring", "reserved_monitoring"), "*"), is(true));
461+
462+
final String otherApplication = "logstash-" + randomAlphaOfLengthBetween(8, 24);
463+
assertThat(monitoringUserRole.application().grants(
464+
new ApplicationPrivilege(otherApplication, "app-foo", "foo"), "*"), is(false));
465+
assertThat(monitoringUserRole.application().grants(
466+
new ApplicationPrivilege(otherApplication, "app-reserved_monitoring", "reserved_monitoring"), "*"), is(false));
455467
}
456468

457469
public void testRemoteMonitoringAgentRole() {
@@ -957,6 +969,18 @@ public void testMachineLearningAdminRole() {
957969
assertReadWriteDocsButNotDeleteIndexAllowed(role, AnnotationIndex.INDEX_NAME);
958970

959971
assertNoAccessAllowed(role, RestrictedIndicesNames.RESTRICTED_NAMES);
972+
973+
final String kibanaApplicationWithRandomIndex = "kibana-" + randomFrom(randomAlphaOfLengthBetween(8, 24), ".kibana");
974+
assertThat(role.application().grants(
975+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-foo", "foo"), "*"), is(false));
976+
assertThat(role.application().grants(
977+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-reserved_ml", "reserved_ml"), "*"), is(true));
978+
979+
final String otherApplication = "logstash-" + randomAlphaOfLengthBetween(8, 24);
980+
assertThat(role.application().grants(
981+
new ApplicationPrivilege(otherApplication, "app-foo", "foo"), "*"), is(false));
982+
assertThat(role.application().grants(
983+
new ApplicationPrivilege(otherApplication, "app-reserved_ml", "reserved_ml"), "*"), is(false));
960984
}
961985

962986
public void testMachineLearningUserRole() {
@@ -1028,6 +1052,19 @@ public void testMachineLearningUserRole() {
10281052
assertReadWriteDocsButNotDeleteIndexAllowed(role, AnnotationIndex.INDEX_NAME);
10291053

10301054
assertNoAccessAllowed(role, RestrictedIndicesNames.RESTRICTED_NAMES);
1055+
1056+
1057+
final String kibanaApplicationWithRandomIndex = "kibana-" + randomFrom(randomAlphaOfLengthBetween(8, 24), ".kibana");
1058+
assertThat(role.application().grants(
1059+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-foo", "foo"), "*"), is(false));
1060+
assertThat(role.application().grants(
1061+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-reserved_ml", "reserved_ml"), "*"), is(true));
1062+
1063+
final String otherApplication = "logstash-" + randomAlphaOfLengthBetween(8, 24);
1064+
assertThat(role.application().grants(
1065+
new ApplicationPrivilege(otherApplication, "app-foo", "foo"), "*"), is(false));
1066+
assertThat(role.application().grants(
1067+
new ApplicationPrivilege(otherApplication, "app-reserved_ml", "reserved_ml"), "*"), is(false));
10311068
}
10321069

10331070
public void testDataFrameTransformsAdminRole() {

0 commit comments

Comments
 (0)