|
8 | 8 | package org.elasticsearch.xpack.security.authc.service;
|
9 | 9 |
|
10 | 10 | import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction;
|
| 11 | +import org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction; |
11 | 12 | import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction;
|
| 13 | +import org.elasticsearch.action.admin.cluster.snapshots.create.TransportCreateSnapshotAction; |
| 14 | +import org.elasticsearch.action.admin.cluster.snapshots.delete.TransportDeleteSnapshotAction; |
| 15 | +import org.elasticsearch.action.admin.cluster.snapshots.get.TransportGetSnapshotsAction; |
| 16 | +import org.elasticsearch.action.admin.cluster.snapshots.restore.TransportRestoreSnapshotAction; |
| 17 | +import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction; |
| 18 | +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction; |
12 | 19 | import org.elasticsearch.action.admin.indices.create.AutoCreateAction;
|
13 | 20 | import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
|
14 | 21 | import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
|
15 | 22 | import org.elasticsearch.action.admin.indices.mapping.put.TransportAutoPutMappingAction;
|
16 | 23 | import org.elasticsearch.action.admin.indices.refresh.RefreshAction;
|
| 24 | +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction; |
17 | 25 | import org.elasticsearch.action.admin.indices.settings.put.TransportUpdateSettingsAction;
|
18 | 26 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction;
|
19 | 27 | import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteIndexTemplateAction;
|
| 28 | +import org.elasticsearch.action.admin.indices.template.get.GetComponentTemplateAction; |
| 29 | +import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction; |
20 | 30 | import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction;
|
21 | 31 | import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction;
|
22 | 32 | import org.elasticsearch.action.bulk.TransportBulkAction;
|
| 33 | +import org.elasticsearch.action.datastreams.DataStreamsStatsAction; |
| 34 | +import org.elasticsearch.action.datastreams.lifecycle.GetDataStreamLifecycleAction; |
23 | 35 | import org.elasticsearch.action.delete.TransportDeleteAction;
|
24 | 36 | import org.elasticsearch.action.get.TransportGetAction;
|
25 | 37 | import org.elasticsearch.action.get.TransportMultiGetAction;
|
|
52 | 64 | import org.elasticsearch.xpack.core.security.authz.store.ReservedRolesStore;
|
53 | 65 | import org.elasticsearch.xpack.core.security.user.KibanaSystemUser;
|
54 | 66 | import org.elasticsearch.xpack.core.security.user.User;
|
| 67 | +import org.elasticsearch.xpack.core.slm.action.DeleteSnapshotLifecycleAction; |
| 68 | +import org.elasticsearch.xpack.core.slm.action.ExecuteSnapshotLifecycleAction; |
| 69 | +import org.elasticsearch.xpack.core.slm.action.GetSLMStatusAction; |
| 70 | +import org.elasticsearch.xpack.core.slm.action.GetSnapshotLifecycleAction; |
| 71 | +import org.elasticsearch.xpack.core.slm.action.PutSnapshotLifecycleAction; |
55 | 72 | import org.elasticsearch.xpack.security.authc.service.ElasticServiceAccounts.ElasticServiceAccount;
|
56 | 73 |
|
57 | 74 | import java.util.List;
|
|
67 | 84 |
|
68 | 85 | public class ElasticServiceAccountsTests extends ESTestCase {
|
69 | 86 |
|
| 87 | + public void testAutoOpsPrivileges() { |
| 88 | + final Role role = Role.buildFromRoleDescriptor( |
| 89 | + ElasticServiceAccounts.ACCOUNTS.get("elastic/auto-ops").roleDescriptor(), |
| 90 | + new FieldPermissionsCache(Settings.EMPTY), |
| 91 | + RESTRICTED_INDICES |
| 92 | + ); |
| 93 | + |
| 94 | + final Authentication authentication = AuthenticationTestHelper.builder().serviceAccount().build(); |
| 95 | + final TransportRequest request = mock(TransportRequest.class); |
| 96 | + |
| 97 | + // monitor |
| 98 | + assertThat(role.cluster().check(GetComponentTemplateAction.NAME, request, authentication), is(true)); |
| 99 | + assertThat(role.cluster().check(GetComposableIndexTemplateAction.NAME, request, authentication), is(true)); |
| 100 | + assertThat(role.cluster().check(GetIndexTemplatesAction.NAME, request, authentication), is(true)); |
| 101 | + assertThat(role.cluster().check(TransportClusterHealthAction.NAME, request, authentication), is(true)); |
| 102 | + assertThat(role.cluster().check(TransportNodesStatsAction.TYPE.name(), request, authentication), is(true)); |
| 103 | + |
| 104 | + assertThat(role.cluster().check(ClusterUpdateSettingsAction.NAME, request, authentication), is(false)); |
| 105 | + assertThat(role.cluster().check(TransportPutIndexTemplateAction.TYPE.name(), request, authentication), is(false)); |
| 106 | + assertThat(role.cluster().check(TransportDeleteIndexTemplateAction.TYPE.name(), request, authentication), is(false)); |
| 107 | + |
| 108 | + // read_ilm |
| 109 | + assertThat(role.cluster().check(GetLifecycleAction.NAME, request, authentication), is(true)); |
| 110 | + |
| 111 | + assertThat(role.cluster().check(ILMActions.STOP.name(), request, authentication), is(false)); |
| 112 | + assertThat(role.cluster().check(ILMActions.PUT.name(), request, authentication), is(false)); |
| 113 | + |
| 114 | + // read_slm |
| 115 | + assertThat(role.cluster().check(GetSLMStatusAction.NAME, request, authentication), is(true)); |
| 116 | + assertThat(role.cluster().check(GetSnapshotLifecycleAction.NAME, request, authentication), is(true)); |
| 117 | + |
| 118 | + assertThat(role.cluster().check(DeleteSnapshotLifecycleAction.NAME, request, authentication), is(false)); |
| 119 | + assertThat(role.cluster().check(ExecuteSnapshotLifecycleAction.NAME, request, authentication), is(false)); |
| 120 | + assertThat(role.cluster().check(PutSnapshotLifecycleAction.NAME, request, authentication), is(false)); |
| 121 | + assertThat(role.cluster().check(TransportGetSnapshotsAction.TYPE.name(), request, authentication), is(false)); |
| 122 | + assertThat(role.cluster().check(TransportCreateSnapshotAction.TYPE.name(), request, authentication), is(false)); |
| 123 | + assertThat(role.cluster().check(TransportDeleteSnapshotAction.TYPE.name(), request, authentication), is(false)); |
| 124 | + assertThat(role.cluster().check(TransportRestoreSnapshotAction.TYPE.name(), request, authentication), is(false)); |
| 125 | + |
| 126 | + // index monitor |
| 127 | + List.of( |
| 128 | + "search-" + randomAlphaOfLengthBetween(1, 20), |
| 129 | + ".kibana-" + randomAlphaOfLengthBetween(1, 20), |
| 130 | + ".elastic-analytics-collections", |
| 131 | + "logs-" + randomAlphaOfLengthBetween(1, 20), |
| 132 | + "my-index-" + randomAlphaOfLengthBetween(1, 20), |
| 133 | + ".internal.alerts-default.alerts-default-" + randomAlphaOfLengthBetween(1, 20) |
| 134 | + ).forEach(index -> { |
| 135 | + final IndexAbstraction anyIndex = mockIndexAbstraction(index); |
| 136 | + |
| 137 | + assertThat(role.indices().allowedIndicesMatcher(IndicesStatsAction.NAME).test(anyIndex), is(true)); |
| 138 | + assertThat(role.indices().allowedIndicesMatcher(DataStreamsStatsAction.NAME).test(anyIndex), is(true)); |
| 139 | + assertThat(role.indices().allowedIndicesMatcher(GetAliasesAction.NAME).test(anyIndex), is(true)); |
| 140 | + assertThat(role.indices().allowedIndicesMatcher(GetSettingsAction.NAME).test(anyIndex), is(true)); |
| 141 | + assertThat(role.indices().allowedIndicesMatcher(GetDataStreamLifecycleAction.INSTANCE.name()).test(anyIndex), is(true)); |
| 142 | + |
| 143 | + assertThat(role.indices().allowedIndicesMatcher(AutoCreateAction.NAME).test(anyIndex), is(false)); |
| 144 | + assertThat(role.indices().allowedIndicesMatcher(TransportCreateIndexAction.TYPE.name()).test(anyIndex), is(false)); |
| 145 | + assertThat(role.indices().allowedIndicesMatcher(TransportDeleteAction.NAME).test(anyIndex), is(false)); |
| 146 | + assertThat(role.indices().allowedIndicesMatcher(TransportDeleteIndexAction.TYPE.name()).test(anyIndex), is(false)); |
| 147 | + assertThat(role.indices().allowedIndicesMatcher(TransportIndexAction.NAME).test(anyIndex), is(false)); |
| 148 | + assertThat(role.indices().allowedIndicesMatcher(TransportIndicesAliasesAction.NAME).test(anyIndex), is(false)); |
| 149 | + assertThat(role.indices().allowedIndicesMatcher(TransportBulkAction.NAME).test(anyIndex), is(false)); |
| 150 | + assertThat(role.indices().allowedIndicesMatcher(TransportGetAction.TYPE.name()).test(anyIndex), is(false)); |
| 151 | + assertThat(role.indices().allowedIndicesMatcher(TransportMultiGetAction.NAME).test(anyIndex), is(false)); |
| 152 | + assertThat(role.indices().allowedIndicesMatcher(TransportSearchAction.TYPE.name()).test(anyIndex), is(false)); |
| 153 | + assertThat(role.indices().allowedIndicesMatcher(TransportMultiSearchAction.TYPE.name()).test(anyIndex), is(false)); |
| 154 | + assertThat(role.indices().allowedIndicesMatcher(TransportUpdateSettingsAction.TYPE.name()).test(anyIndex), is(false)); |
| 155 | + assertThat(role.indices().allowedIndicesMatcher(RefreshAction.NAME).test(anyIndex), is(false)); |
| 156 | + assertThat(role.indices().allowedIndicesMatcher("indices:foo").test(anyIndex), is(false)); |
| 157 | + }); |
| 158 | + } |
| 159 | + |
70 | 160 | public void testKibanaSystemPrivileges() {
|
71 | 161 | final RoleDescriptor serviceAccountRoleDescriptor = ElasticServiceAccounts.ACCOUNTS.get("elastic/kibana").roleDescriptor();
|
72 | 162 | final RoleDescriptor reservedRolesStoreRoleDescriptor = ReservedRolesStore.kibanaSystemRoleDescriptor(KibanaSystemUser.ROLE_NAME);
|
|
0 commit comments