-
Notifications
You must be signed in to change notification settings - Fork 320
Use SystemIndexRegistry from core to determine if request contains system indices #4471
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
willyborankin
merged 13 commits into
opensearch-project:main
from
cwperks:on-system-index
Jul 11, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ab0f108
Implement onSystemIndices
cwperks 15c9031
Add integration test that demonstrates getting system indices from core
cwperks f1fd262
Merge branch 'main' into on-system-index
cwperks 381d3f9
WIP on getting system indices from IndexNameExpressionResolver
cwperks 0e56367
Update SecurityIndexAccessEvaluatorTest
cwperks 4c9a625
Moved WildcardMatcher to core and systemIndexMatching logic to core
cwperks b62c6fb
Merge branch 'main' into on-system-index
cwperks 92a2a47
Use SystemIndexRegistry from core
cwperks 56cd713
Merge branch 'main' into on-system-index
cwperks 4f87c41
Rename test
cwperks 83f93a7
Merge branch 'main' into on-system-index
cwperks dec2d9b
Enable system index protection for testing
cwperks 5369120
Add License header
cwperks 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
83 changes: 83 additions & 0 deletions
83
src/integrationTest/java/org/opensearch/security/SystemIndexTests.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,83 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
package org.opensearch.security; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.security.http.ExampleSystemIndexPlugin; | ||
import org.opensearch.test.framework.TestSecurityConfig.AuthcDomain; | ||
import org.opensearch.test.framework.cluster.ClusterManager; | ||
import org.opensearch.test.framework.cluster.LocalCluster; | ||
import org.opensearch.test.framework.cluster.TestRestClient; | ||
import org.opensearch.test.framework.cluster.TestRestClient.HttpResponse; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.opensearch.security.support.ConfigConstants.SECURITY_RESTAPI_ROLES_ENABLED; | ||
import static org.opensearch.security.support.ConfigConstants.SECURITY_SYSTEM_INDICES_ENABLED_KEY; | ||
import static org.opensearch.test.framework.TestSecurityConfig.Role.ALL_ACCESS; | ||
import static org.opensearch.test.framework.TestSecurityConfig.User.USER_ADMIN; | ||
|
||
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) | ||
@ThreadLeakScope(ThreadLeakScope.Scope.NONE) | ||
public class SystemIndexTests { | ||
|
||
public static final AuthcDomain AUTHC_DOMAIN = new AuthcDomain("basic", 0).httpAuthenticatorWithChallenge("basic").backend("internal"); | ||
|
||
@ClassRule | ||
public static final LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.SINGLENODE) | ||
.anonymousAuth(false) | ||
.authc(AUTHC_DOMAIN) | ||
.users(USER_ADMIN) | ||
.plugin(ExampleSystemIndexPlugin.class) | ||
.nodeSettings( | ||
Map.of( | ||
SECURITY_RESTAPI_ROLES_ENABLED, | ||
List.of("user_" + USER_ADMIN.getName() + "__" + ALL_ACCESS.getName()), | ||
SECURITY_SYSTEM_INDICES_ENABLED_KEY, | ||
true | ||
) | ||
) | ||
.build(); | ||
|
||
@Test | ||
public void adminShouldNotBeAbleToDeleteSecurityIndex() { | ||
try (TestRestClient client = cluster.getRestClient(USER_ADMIN)) { | ||
HttpResponse response = client.delete(".opendistro_security"); | ||
|
||
assertThat(response.getStatusCode(), equalTo(RestStatus.FORBIDDEN.getStatus())); | ||
|
||
// Create regular index | ||
client.put("test-index"); | ||
|
||
// regular user can delete non-system index | ||
HttpResponse response2 = client.delete("test-index"); | ||
|
||
assertThat(response2.getStatusCode(), equalTo(RestStatus.OK.getStatus())); | ||
|
||
// regular use can create system index | ||
HttpResponse response3 = client.put(".system-index1"); | ||
|
||
assertThat(response3.getStatusCode(), equalTo(RestStatus.OK.getStatus())); | ||
|
||
// regular user cannot delete system index | ||
HttpResponse response4 = client.delete(".system-index1"); | ||
|
||
assertThat(response4.getStatusCode(), equalTo(RestStatus.FORBIDDEN.getStatus())); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/integrationTest/java/org/opensearch/security/http/ExampleSystemIndexPlugin.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,27 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
package org.opensearch.security.http; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.indices.SystemIndexDescriptor; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.plugins.SystemIndexPlugin; | ||
|
||
public class ExampleSystemIndexPlugin extends Plugin implements SystemIndexPlugin { | ||
|
||
@Override | ||
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) { | ||
final SystemIndexDescriptor systemIndexDescriptor = new SystemIndexDescriptor(".system-index1", "System index 1"); | ||
return Collections.singletonList(systemIndexDescriptor); | ||
} | ||
} |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.