-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add a new async search security origin #52141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
albertzaharovits
merged 3 commits into
elastic:master
from
albertzaharovits:async-search-security-origin
Feb 11, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...plugin/core/src/main/java/org/elasticsearch/xpack/core/security/user/AsyncSearchUser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| package org.elasticsearch.xpack.core.security.user; | ||
|
|
||
| import org.elasticsearch.xpack.core.security.authz.RoleDescriptor; | ||
| import org.elasticsearch.xpack.core.security.authz.permission.Role; | ||
| import org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames; | ||
| import org.elasticsearch.xpack.core.security.support.MetadataUtils; | ||
|
|
||
| public class AsyncSearchUser extends User { | ||
|
|
||
| public static final String NAME = UsernamesField.ASYNC_SEARCH_NAME; | ||
| public static final AsyncSearchUser INSTANCE = new AsyncSearchUser(); | ||
| public static final String ROLE_NAME = UsernamesField.ASYNC_SEARCH_ROLE; | ||
| public static final Role ROLE = Role.builder(new RoleDescriptor(ROLE_NAME, | ||
| null, | ||
| new RoleDescriptor.IndicesPrivileges[] { | ||
| RoleDescriptor.IndicesPrivileges.builder() | ||
| .indices(RestrictedIndicesNames.ASYNC_SEARCH_PREFIX + "*") | ||
| .privileges("all") | ||
| .allowRestrictedIndices(true).build(), | ||
| }, | ||
| null, | ||
| null, | ||
| null, | ||
| MetadataUtils.DEFAULT_RESERVED_METADATA, | ||
| null), null).build(); | ||
|
|
||
| private AsyncSearchUser() { | ||
| super(NAME, ROLE_NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| return INSTANCE == o; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return System.identityHashCode(this); | ||
| } | ||
|
|
||
| public static boolean is(User user) { | ||
| return INSTANCE.equals(user); | ||
| } | ||
|
|
||
| public static boolean is(String principal) { | ||
| return NAME.equals(principal); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...in/security/src/test/java/org/elasticsearch/xpack/security/user/AsyncSearchUserTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| package org.elasticsearch.xpack.security.user; | ||
|
|
||
| import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsAction; | ||
| import org.elasticsearch.action.admin.cluster.state.ClusterStateAction; | ||
| import org.elasticsearch.action.admin.cluster.stats.ClusterStatsAction; | ||
| import org.elasticsearch.action.delete.DeleteAction; | ||
| import org.elasticsearch.action.get.GetAction; | ||
| import org.elasticsearch.action.index.IndexAction; | ||
| import org.elasticsearch.action.search.SearchAction; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.elasticsearch.transport.TransportRequest; | ||
| import org.elasticsearch.xpack.core.security.authc.Authentication; | ||
| import org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames; | ||
| import org.elasticsearch.xpack.core.security.user.AsyncSearchUser; | ||
| import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchAction; | ||
| import org.hamcrest.Matchers; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.function.Predicate; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| public class AsyncSearchUserTests extends ESTestCase { | ||
|
|
||
| public void testAsyncSearchUserCannotAccessNonRestrictedIndices() { | ||
| for (String action : Arrays.asList(GetAction.NAME, DeleteAction.NAME, SearchAction.NAME, IndexAction.NAME)) { | ||
| Predicate<String> predicate = AsyncSearchUser.ROLE.indices().allowedIndicesMatcher(action); | ||
| String index = randomAlphaOfLengthBetween(3, 12); | ||
| if (false == RestrictedIndicesNames.isRestricted(index)) { | ||
| assertThat(predicate.test(index), Matchers.is(false)); | ||
| } | ||
| index = "." + randomAlphaOfLengthBetween(3, 12); | ||
| if (false == RestrictedIndicesNames.isRestricted(index)) { | ||
| assertThat(predicate.test(index), Matchers.is(false)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void testAsyncSearchUserCanAccessOnlyAsyncSearchRestrictedIndices() { | ||
| for (String action : Arrays.asList(GetAction.NAME, DeleteAction.NAME, SearchAction.NAME, IndexAction.NAME)) { | ||
| final Predicate<String> predicate = AsyncSearchUser.ROLE.indices().allowedIndicesMatcher(action); | ||
| for (String index : RestrictedIndicesNames.RESTRICTED_NAMES) { | ||
| assertThat(predicate.test(index), Matchers.is(false)); | ||
| } | ||
| assertThat(predicate.test(RestrictedIndicesNames.ASYNC_SEARCH_PREFIX + randomAlphaOfLengthBetween(0, 3)), Matchers.is(true)); | ||
| } | ||
| } | ||
|
|
||
| public void testAsyncSearchUserHasNoClusterPrivileges() { | ||
| for (String action : Arrays.asList(ClusterStateAction.NAME, GetWatchAction.NAME, ClusterStatsAction.NAME, NodesStatsAction.NAME)) { | ||
| assertThat(AsyncSearchUser.ROLE.cluster().check(action, mock(TransportRequest.class), mock(Authentication.class)), | ||
| Matchers.is(false)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍