|
39 | 39 | import org.elasticsearch.common.settings.Settings;
|
40 | 40 | import org.elasticsearch.index.IndexVersion;
|
41 | 41 | import org.elasticsearch.index.reindex.ReindexAction;
|
| 42 | +import org.elasticsearch.tasks.TaskCancellationService; |
42 | 43 | import org.elasticsearch.test.ESTestCase;
|
| 44 | +import org.elasticsearch.transport.RemoteClusterService; |
43 | 45 | import org.elasticsearch.transport.TransportRequest;
|
| 46 | +import org.elasticsearch.transport.TransportService; |
44 | 47 | import org.elasticsearch.xpack.core.XPackPlugin;
|
| 48 | +import org.elasticsearch.xpack.core.action.XPackInfoAction; |
45 | 49 | import org.elasticsearch.xpack.core.ml.action.UpdateJobAction;
|
46 | 50 | import org.elasticsearch.xpack.core.security.authc.Authentication;
|
47 | 51 | import org.elasticsearch.xpack.core.security.authc.AuthenticationTestHelper;
|
| 52 | +import org.elasticsearch.xpack.core.security.authz.RoleDescriptor; |
48 | 53 | import org.elasticsearch.xpack.core.security.authz.permission.ApplicationPermission;
|
49 | 54 | import org.elasticsearch.xpack.core.security.authz.permission.ClusterPermission;
|
50 | 55 | import org.elasticsearch.xpack.core.security.authz.permission.FieldPermissionsCache;
|
| 56 | +import org.elasticsearch.xpack.core.security.authz.permission.IndicesPermission; |
| 57 | +import org.elasticsearch.xpack.core.security.authz.permission.RemoteClusterPermissions; |
51 | 58 | import org.elasticsearch.xpack.core.security.authz.permission.RemoteIndicesPermission;
|
52 | 59 | import org.elasticsearch.xpack.core.security.authz.permission.Role;
|
53 | 60 | import org.elasticsearch.xpack.core.security.authz.permission.RunAsPermission;
|
|
57 | 64 |
|
58 | 65 | import java.util.Arrays;
|
59 | 66 | import java.util.List;
|
| 67 | +import java.util.Optional; |
60 | 68 |
|
61 | 69 | import static org.elasticsearch.xpack.core.security.test.TestRestrictedIndices.INTERNAL_SECURITY_MAIN_INDEX_7;
|
62 | 70 | import static org.elasticsearch.xpack.core.security.test.TestRestrictedIndices.INTERNAL_SECURITY_TOKENS_INDEX_7;
|
63 | 71 | import static org.elasticsearch.xpack.core.security.test.TestRestrictedIndices.SECURITY_MAIN_ALIAS;
|
64 | 72 | import static org.elasticsearch.xpack.core.security.test.TestRestrictedIndices.SECURITY_TOKENS_ALIAS;
|
| 73 | +import static org.elasticsearch.xpack.core.security.user.UsernamesField.CROSS_PROJECT_SEARCH_USER_NAME; |
65 | 74 | import static org.elasticsearch.xpack.core.security.user.UsernamesField.REINDEX_DATA_STREAM_NAME;
|
66 | 75 | import static org.hamcrest.Matchers.arrayContaining;
|
67 | 76 | import static org.hamcrest.Matchers.equalTo;
|
@@ -358,6 +367,47 @@ public void testRegularUser() {
|
358 | 367 | expectThrows(IllegalStateException.class, () -> InternalUsers.getUser(username));
|
359 | 368 | }
|
360 | 369 |
|
| 370 | + public void testCrossProjectSearchUser() { |
| 371 | + final InternalUser crossProjectSearchUser = InternalUsers.CROSS_PROJECT_SEARCH_USER; |
| 372 | + assertThat(InternalUsers.getUser(CROSS_PROJECT_SEARCH_USER_NAME), is(crossProjectSearchUser)); |
| 373 | + |
| 374 | + assertThat(crossProjectSearchUser.getRemoteAccessRoleDescriptor().isPresent(), equalTo(false)); |
| 375 | + |
| 376 | + Optional<RoleDescriptor> localClusterRoleDescriptor = crossProjectSearchUser.getLocalClusterRoleDescriptor(); |
| 377 | + assertThat(localClusterRoleDescriptor.isPresent(), equalTo(true)); |
| 378 | + assertThat(localClusterRoleDescriptor.get().getMetadata(), equalTo(MetadataUtils.DEFAULT_RESERVED_METADATA)); |
| 379 | + |
| 380 | + final SimpleRole role = getLocalClusterRole(crossProjectSearchUser); |
| 381 | + |
| 382 | + assertThat(role.indices(), is(IndicesPermission.NONE)); |
| 383 | + assertThat(role.runAs(), is(RunAsPermission.NONE)); |
| 384 | + assertThat(role.application(), is(ApplicationPermission.NONE)); |
| 385 | + assertThat(role.remoteIndices(), is(RemoteIndicesPermission.NONE)); |
| 386 | + assertThat(role.remoteCluster(), is(RemoteClusterPermissions.NONE)); |
| 387 | + assertThat(role.hasFieldOrDocumentLevelSecurity(), is(false)); |
| 388 | + assertThat(role.hasWorkflowsRestriction(), is(false)); |
| 389 | + |
| 390 | + final List<String> allowedClusterActions = List.of( |
| 391 | + RemoteClusterService.REMOTE_CLUSTER_HANDSHAKE_ACTION_NAME, |
| 392 | + TaskCancellationService.REMOTE_CLUSTER_BAN_PARENT_ACTION_NAME, |
| 393 | + TaskCancellationService.REMOTE_CLUSTER_CANCEL_CHILD_ACTION_NAME, |
| 394 | + "cluster:internal:data/read/esql/open_exchange", |
| 395 | + "cluster:internal:data/read/esql/exchange" |
| 396 | + ); |
| 397 | + |
| 398 | + for (String clusterAction : allowedClusterActions) { |
| 399 | + checkClusterAccess(crossProjectSearchUser, role, clusterAction, true); |
| 400 | + } |
| 401 | + |
| 402 | + checkClusterAccess( |
| 403 | + crossProjectSearchUser, |
| 404 | + role, |
| 405 | + randomFrom(ClusterStateAction.NAME, XPackInfoAction.NAME, TransportService.HANDSHAKE_ACTION_NAME), |
| 406 | + false |
| 407 | + ); |
| 408 | + |
| 409 | + } |
| 410 | + |
361 | 411 | private static SimpleRole getLocalClusterRole(InternalUser internalUser) {
|
362 | 412 | final FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY);
|
363 | 413 | return Role.buildFromRoleDescriptor(
|
|
0 commit comments