-
Notifications
You must be signed in to change notification settings - Fork 336
Adds a list setting to explicitly specify resources to be protected #5671
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
DarshitChanpura
merged 5 commits into
opensearch-project:main
from
DarshitChanpura:resource-type-setting
Oct 1, 2025
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a546d61
Adds a list setting to explicitly specify resources to be protected
DarshitChanpura 11274d0
Adds changelog entry
DarshitChanpura d527da5
Fixes comments and correct registration flow
DarshitChanpura 92980f6
Updates verifyAccess to return true if resource is not marked as prot…
DarshitChanpura bacfeab
Merge branch 'main' into resource-type-setting
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
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
89 changes: 89 additions & 0 deletions
89
...onTest/java/org/opensearch/sample/resource/feature/enabled/ExcludedResourceTypeTests.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,89 @@ | ||
/* | ||
* 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.sample.resource.feature.enabled; | ||
|
||
import java.util.List; | ||
|
||
import com.carrotsearch.randomizedtesting.RandomizedRunner; | ||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; | ||
import org.apache.http.HttpStatus; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.opensearch.sample.resource.TestUtils; | ||
import org.opensearch.test.framework.cluster.LocalCluster; | ||
import org.opensearch.test.framework.cluster.TestRestClient; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.opensearch.sample.resource.TestUtils.FULL_ACCESS_USER; | ||
import static org.opensearch.sample.resource.TestUtils.LIMITED_ACCESS_USER; | ||
import static org.opensearch.sample.resource.TestUtils.NO_ACCESS_USER; | ||
import static org.opensearch.sample.resource.TestUtils.RESOURCE_SHARING_INDEX; | ||
import static org.opensearch.sample.resource.TestUtils.newCluster; | ||
import static org.opensearch.test.framework.TestSecurityConfig.User.USER_ADMIN; | ||
|
||
/** | ||
* Test resource access when sample-resource is not marked as protected resource, even-though resource sharing protection is enabled. | ||
*/ | ||
@RunWith(RandomizedRunner.class) | ||
@ThreadLeakScope(ThreadLeakScope.Scope.NONE) | ||
public class ExcludedResourceTypeTests { | ||
|
||
// do not include sample resource as protected resource, should behave as if feature was disable for that resource | ||
@ClassRule | ||
public static LocalCluster cluster = newCluster(true, true, List.of()); | ||
|
||
private final TestUtils.ApiHelper api = new TestUtils.ApiHelper(cluster); | ||
private String resourceId; | ||
|
||
@Before | ||
public void setup() { | ||
resourceId = api.createSampleResourceAs(USER_ADMIN); | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
api.wipeOutResourceEntries(); | ||
} | ||
|
||
@Test | ||
public void testSampleResourceSharingIndexDoesNotExist() { | ||
try (TestRestClient client = cluster.getRestClient(cluster.getAdminCertificate())) { | ||
TestRestClient.HttpResponse response = client.get("_cat/indices?expand_wildcards=all"); | ||
response.assertStatusCode(HttpStatus.SC_OK); | ||
assertThat(response.getBody(), not(containsString(RESOURCE_SHARING_INDEX))); | ||
} | ||
} | ||
|
||
@Test | ||
public void fullAccessUser_canCRUD() { | ||
api.assertApiGet(resourceId, FULL_ACCESS_USER, HttpStatus.SC_OK, "sample"); | ||
api.assertApiUpdate(resourceId, FULL_ACCESS_USER, "sampleUpdateAdmin", HttpStatus.SC_OK); | ||
api.assertApiDelete(resourceId, FULL_ACCESS_USER, HttpStatus.SC_OK); | ||
} | ||
|
||
@Test | ||
public void limitedAccessUser_canCRUD() { | ||
api.assertApiGet(resourceId, LIMITED_ACCESS_USER, HttpStatus.SC_OK, "sample"); | ||
api.assertApiUpdate(resourceId, LIMITED_ACCESS_USER, "sampleUpdateAdmin", HttpStatus.SC_FORBIDDEN); | ||
api.assertApiDelete(resourceId, LIMITED_ACCESS_USER, HttpStatus.SC_FORBIDDEN); | ||
} | ||
|
||
@Test | ||
public void noAccessUser_canCRUD() { | ||
api.assertApiGet(resourceId, NO_ACCESS_USER, HttpStatus.SC_FORBIDDEN, ""); | ||
api.assertApiUpdate(resourceId, NO_ACCESS_USER, "sampleUpdateAdmin", HttpStatus.SC_FORBIDDEN); | ||
api.assertApiDelete(resourceId, NO_ACCESS_USER, HttpStatus.SC_FORBIDDEN); | ||
} | ||
} |
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
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.
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.