Skip to content

Commit ce74f7f

Browse files
committed
[ML] Add Kibana application privilege to data frame admin/user roles (#42757)
Data frame transforms are restricted by different roles to ML, but share the ML UI. To prevent the ML UI being hidden for users who only have the data frame admin or user role, it is necessary to add the ML Kibana application privilege to the backend data frame roles.
1 parent 0861153 commit ce74f7f

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,22 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
180180
RoleDescriptor.IndicesPrivileges.builder()
181181
.indices(".data-frame-notifications*")
182182
.privileges("view_index_metadata", "read").build()
183-
}, null, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA, null))
183+
},
184+
new RoleDescriptor.ApplicationResourcePrivileges[] {
185+
RoleDescriptor.ApplicationResourcePrivileges.builder()
186+
.application("kibana-*").resources("*").privileges("reserved_ml").build()
187+
}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA, null))
184188
.put("data_frame_transforms_user", new RoleDescriptor("data_frame_transforms_user",
185189
new String[] { "monitor_data_frame_transforms" },
186190
new RoleDescriptor.IndicesPrivileges[]{
187191
RoleDescriptor.IndicesPrivileges.builder()
188192
.indices(".data-frame-notifications*")
189193
.privileges("view_index_metadata", "read").build()
190-
}, null, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA, null))
194+
},
195+
new RoleDescriptor.ApplicationResourcePrivileges[] {
196+
RoleDescriptor.ApplicationResourcePrivileges.builder()
197+
.application("kibana-*").resources("*").privileges("reserved_ml").build()
198+
}, null, null, MetadataUtils.DEFAULT_RESERVED_METADATA, null))
191199
.put("watcher_admin", new RoleDescriptor("watcher_admin", new String[] { "manage_watcher" },
192200
new RoleDescriptor.IndicesPrivileges[] {
193201
RoleDescriptor.IndicesPrivileges.builder().indices(Watch.INDEX, TriggeredWatchStoreField.INDEX_NAME,

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

+24
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,18 @@ public void testDataFrameTransformsAdminRole() {
10961096
assertNoAccessAllowed(role, ".data-frame-internal-1"); // internal use only
10971097

10981098
assertNoAccessAllowed(role, RestrictedIndicesNames.RESTRICTED_NAMES);
1099+
1100+
final String kibanaApplicationWithRandomIndex = "kibana-" + randomFrom(randomAlphaOfLengthBetween(8, 24), ".kibana");
1101+
assertThat(role.application().grants(
1102+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-foo", "foo"), "*"), is(false));
1103+
assertThat(role.application().grants(
1104+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-reserved_ml", "reserved_ml"), "*"), is(true));
1105+
1106+
final String otherApplication = "logstash-" + randomAlphaOfLengthBetween(8, 24);
1107+
assertThat(role.application().grants(
1108+
new ApplicationPrivilege(otherApplication, "app-foo", "foo"), "*"), is(false));
1109+
assertThat(role.application().grants(
1110+
new ApplicationPrivilege(otherApplication, "app-reserved_ml", "reserved_ml"), "*"), is(false));
10991111
}
11001112

11011113
public void testDataFrameTransformsUserRole() {
@@ -1120,6 +1132,18 @@ public void testDataFrameTransformsUserRole() {
11201132
assertNoAccessAllowed(role, ".data-frame-internal-1");
11211133

11221134
assertNoAccessAllowed(role, RestrictedIndicesNames.RESTRICTED_NAMES);
1135+
1136+
final String kibanaApplicationWithRandomIndex = "kibana-" + randomFrom(randomAlphaOfLengthBetween(8, 24), ".kibana");
1137+
assertThat(role.application().grants(
1138+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-foo", "foo"), "*"), is(false));
1139+
assertThat(role.application().grants(
1140+
new ApplicationPrivilege(kibanaApplicationWithRandomIndex, "app-reserved_ml", "reserved_ml"), "*"), is(true));
1141+
1142+
final String otherApplication = "logstash-" + randomAlphaOfLengthBetween(8, 24);
1143+
assertThat(role.application().grants(
1144+
new ApplicationPrivilege(otherApplication, "app-foo", "foo"), "*"), is(false));
1145+
assertThat(role.application().grants(
1146+
new ApplicationPrivilege(otherApplication, "app-reserved_ml", "reserved_ml"), "*"), is(false));
11231147
}
11241148

11251149
public void testWatcherAdminRole() {

0 commit comments

Comments
 (0)