Skip to content

Commit ef7961b

Browse files
authored
kibana_system can only manage kibana privileges (#32221)
The kibana_system role can only manage privileges for applications named "kibana-*". The default kibana instance will have an application name of "kibana-.kibana", and other instances will be named similarly but with the ".kibana" replaced by the name of their kibana index.
1 parent 69a42b3 commit ef7961b

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.elasticsearch.xpack.core.monitoring.action.MonitoringBulkAction;
1010
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
1111
import org.elasticsearch.xpack.core.security.authz.permission.Role;
12+
import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivilege;
13+
import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivileges.ManageApplicationPrivileges;
1214
import org.elasticsearch.xpack.core.security.support.MetadataUtils;
1315
import org.elasticsearch.xpack.core.security.user.KibanaUser;
1416
import org.elasticsearch.xpack.core.security.user.UsernamesField;
@@ -81,8 +83,6 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
8183
.put(KibanaUser.ROLE_NAME, new RoleDescriptor(KibanaUser.ROLE_NAME,
8284
new String[] {
8385
"monitor", "manage_index_templates", MonitoringBulkAction.NAME, "manage_saml",
84-
"cluster:admin/xpack/security/privilege/get",
85-
"cluster:admin/xpack/security/privilege/put",
8686
},
8787
new RoleDescriptor.IndicesPrivileges[] {
8888
RoleDescriptor.IndicesPrivileges.builder().indices(".kibana*", ".reporting-*").privileges("all").build(),
@@ -91,7 +91,9 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
9191
RoleDescriptor.IndicesPrivileges.builder()
9292
.indices(".management-beats").privileges("create_index", "read", "write").build()
9393
},
94-
null, MetadataUtils.DEFAULT_RESERVED_METADATA))
94+
null,
95+
new ConditionalClusterPrivilege[] { new ManageApplicationPrivileges(Collections.singleton("kibana-*")) },
96+
null, MetadataUtils.DEFAULT_RESERVED_METADATA, null))
9597
.put("logstash_system", new RoleDescriptor("logstash_system", new String[] { "monitor", MonitoringBulkAction.NAME},
9698
null, null, MetadataUtils.DEFAULT_RESERVED_METADATA))
9799
.put("beats_admin", new RoleDescriptor("beats_admin",

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@
7777
import org.elasticsearch.xpack.core.ml.notifications.AuditorField;
7878
import org.elasticsearch.xpack.core.monitoring.action.MonitoringBulkAction;
7979
import org.elasticsearch.xpack.core.security.action.privilege.DeletePrivilegesAction;
80+
import org.elasticsearch.xpack.core.security.action.privilege.DeletePrivilegesRequest;
8081
import org.elasticsearch.xpack.core.security.action.privilege.GetPrivilegesAction;
82+
import org.elasticsearch.xpack.core.security.action.privilege.GetPrivilegesRequest;
8183
import org.elasticsearch.xpack.core.security.action.privilege.PutPrivilegesAction;
84+
import org.elasticsearch.xpack.core.security.action.privilege.PutPrivilegesRequest;
8285
import org.elasticsearch.xpack.core.security.action.role.PutRoleAction;
8386
import org.elasticsearch.xpack.core.security.action.saml.SamlAuthenticateAction;
8487
import org.elasticsearch.xpack.core.security.action.saml.SamlPrepareAuthenticationAction;
@@ -89,6 +92,7 @@
8992
import org.elasticsearch.xpack.core.security.authz.accesscontrol.IndicesAccessControl.IndexAccessControl;
9093
import org.elasticsearch.xpack.core.security.authz.permission.FieldPermissionsCache;
9194
import org.elasticsearch.xpack.core.security.authz.permission.Role;
95+
import org.elasticsearch.xpack.core.security.authz.privilege.ApplicationPrivilegeDescriptor;
9296
import org.elasticsearch.xpack.core.security.user.BeatsSystemUser;
9397
import org.elasticsearch.xpack.core.security.user.LogstashSystemUser;
9498
import org.elasticsearch.xpack.core.security.user.SystemUser;
@@ -108,6 +112,7 @@
108112
import org.joda.time.DateTimeZone;
109113

110114
import java.util.Arrays;
115+
import java.util.Collections;
111116
import java.util.Map;
112117

113118
import static org.hamcrest.Matchers.hasEntry;
@@ -192,10 +197,27 @@ public void testKibanaSystemRole() {
192197
assertThat(kibanaRole.cluster().check(InvalidateTokenAction.NAME, request), is(true));
193198
assertThat(kibanaRole.cluster().check(CreateTokenAction.NAME, request), is(false));
194199

195-
// Security
196-
assertThat(kibanaRole.cluster().check(DeletePrivilegesAction.NAME, request), is(false));
197-
assertThat(kibanaRole.cluster().check(GetPrivilegesAction.NAME, request), is(true));
198-
assertThat(kibanaRole.cluster().check(PutPrivilegesAction.NAME, request), is(true));
200+
// Application Privileges
201+
DeletePrivilegesRequest deleteKibanaPrivileges = new DeletePrivilegesRequest("kibana-.kibana", new String[]{ "all", "read" });
202+
DeletePrivilegesRequest deleteLogstashPrivileges = new DeletePrivilegesRequest("logstash", new String[]{ "all", "read" });
203+
assertThat(kibanaRole.cluster().check(DeletePrivilegesAction.NAME, deleteKibanaPrivileges), is(true));
204+
assertThat(kibanaRole.cluster().check(DeletePrivilegesAction.NAME, deleteLogstashPrivileges), is(false));
205+
206+
GetPrivilegesRequest getKibanaPrivileges = new GetPrivilegesRequest();
207+
getKibanaPrivileges.application("kibana-.kibana-sales");
208+
GetPrivilegesRequest getApmPrivileges = new GetPrivilegesRequest();
209+
getApmPrivileges.application("apm");
210+
assertThat(kibanaRole.cluster().check(GetPrivilegesAction.NAME, getKibanaPrivileges), is(true));
211+
assertThat(kibanaRole.cluster().check(GetPrivilegesAction.NAME, getApmPrivileges), is(false));
212+
213+
PutPrivilegesRequest putKibanaPrivileges = new PutPrivilegesRequest();
214+
putKibanaPrivileges.setPrivileges(Collections.singletonList(new ApplicationPrivilegeDescriptor(
215+
"kibana-.kibana-" + randomAlphaOfLengthBetween(2,6), "all", Collections.emptySet(), Collections.emptyMap())));
216+
PutPrivilegesRequest putSwiftypePrivileges = new PutPrivilegesRequest();
217+
putSwiftypePrivileges.setPrivileges(Collections.singletonList(new ApplicationPrivilegeDescriptor(
218+
"swiftype-kibana" , "all", Collections.emptySet(), Collections.emptyMap())));
219+
assertThat(kibanaRole.cluster().check(PutPrivilegesAction.NAME, putKibanaPrivileges), is(true));
220+
assertThat(kibanaRole.cluster().check(PutPrivilegesAction.NAME, putSwiftypePrivileges), is(false));
199221

200222
// Everything else
201223
assertThat(kibanaRole.runAs().check(randomAlphaOfLengthBetween(1, 12)), is(false));

0 commit comments

Comments
 (0)