Skip to content

Commit aacfaa2

Browse files
authored
Fix privileges for predefined roles (#72061) (#72178)
In #71904 we added two new predefined roles, editor and viewer in elasticsearch. This change adds a missing application privilege to these roles. This is only needed in 7.x as the behavior has changed in Kibana, starting 8.0 and this extra privilege is not necessary.
1 parent da1c5ff commit aacfaa2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,11 @@ private static RoleDescriptor buildViewerRoleDescriptor() {
356356
RoleDescriptor.ApplicationResourcePrivileges.builder()
357357
.application("kibana-.kibana")
358358
.resources("*")
359-
.privileges("read").build() },
359+
.privileges("read").build(),
360+
RoleDescriptor.ApplicationResourcePrivileges.builder()
361+
.application("kibana-*")
362+
.resources("*")
363+
.privileges("reserved_ml_user").build() },
360364
null,
361365
null,
362366
MetadataUtils.DEFAULT_RESERVED_METADATA,
@@ -383,7 +387,11 @@ private static RoleDescriptor buildEditorRoleDescriptor() {
383387
RoleDescriptor.ApplicationResourcePrivileges.builder()
384388
.application("kibana-.kibana")
385389
.resources("*")
386-
.privileges("all").build() },
390+
.privileges("all").build(),
391+
RoleDescriptor.ApplicationResourcePrivileges.builder()
392+
.application("kibana-*")
393+
.resources("*")
394+
.privileges("reserved_ml_admin").build() },
387395
null,
388396
null,
389397
MetadataUtils.DEFAULT_RESERVED_METADATA,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,11 @@ public void testPredefinedViewerRole() {
17131713
// Check application privileges
17141714
assertThat(role.application().grants(new ApplicationPrivilege("kibana-.kibana", "kibana-read", "read"), "*"), is(true));
17151715
assertThat(role.application().grants(new ApplicationPrivilege("kibana-.kibana", "kibana-all", "all"), "*"), is(false));
1716+
final String kibIndex = "kibana-" + randomAlphaOfLengthBetween(5, 10);
1717+
assertThat(
1718+
role.application().grants(new ApplicationPrivilege(kibIndex, "app-reserved_ml_user", "reserved_ml_user"), "*"), is(true));
1719+
assertThat(
1720+
role.application().grants(new ApplicationPrivilege(kibIndex, "app-reserved_ml_admin", "reserved_ml_admin"), "*"), is(false));
17161721

17171722
assertThat(role.runAs().check(randomAlphaOfLengthBetween(1, 20)), is(false));
17181723
}
@@ -1767,6 +1772,9 @@ public void testPredefinedEditorRole() {
17671772

17681773
// Check application privileges
17691774
assertThat(role.application().grants(new ApplicationPrivilege("kibana-.kibana", "kibana-all", "all"), "*"), is(true));
1775+
assertThat(role.application().grants(
1776+
new ApplicationPrivilege("kibana-" + randomAlphaOfLengthBetween(6, 10),
1777+
"app-reserved_ml", "reserved_ml_admin"), "*"), is(true));
17701778

17711779
assertThat(role.runAs().check(randomAlphaOfLengthBetween(1, 20)), is(false));
17721780
}

0 commit comments

Comments
 (0)