-
Notifications
You must be signed in to change notification settings - Fork 275
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
Add Integration Test to confirm Core Change to Fix Search template request Auth #2921
Merged
willyborankin
merged 10 commits into
opensearch-project:main
from
derek-ho:fix-search-template
Aug 16, 2023
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0122b60
fix search template auth to allow for search template requests on ind…
derek-ho 24aa368
fix and add tests
derek-ho b640386
spotless
derek-ho 445835d
Merge branch 'opensearch-project:main' into fix-search-template
derek-ho bbb1b86
revert PR to only be tests
derek-ho e78def3
add tests for other situations
derek-ho 387f1a6
spotless
derek-ho c4a3d5d
extract query to a constant
derek-ho 4e78c8d
Merge branch 'main' of github.com:opensearch-project/security into fi…
derek-ho f3e5d46
update integration tests
derek-ho 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 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.opensearch.script.mustache.MustacheModulePlugin; | ||
import org.opensearch.test.framework.TestSecurityConfig; | ||
import org.opensearch.test.framework.TestSecurityConfig.Role; | ||
import org.opensearch.test.framework.cluster.ClusterManager; | ||
|
@@ -44,10 +45,15 @@ public class PrivilegesEvaluatorTest { | |
new Role("negated_regex_role").indexPermissions("read").on("/^[a-z].*/").clusterPermissions("cluster_composite_ops") | ||
); | ||
|
||
protected final static TestSecurityConfig.User SEARCH_TEMPLATE = new TestSecurityConfig.User("search_template_user").roles( | ||
new Role("search_template_role").indexPermissions("read").on("/^[a-z].*/").clusterPermissions("indices:data/read/search/template") | ||
); | ||
|
||
@ClassRule | ||
public static LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS) | ||
.plugin(MustacheModulePlugin.class) | ||
.authc(AUTHC_HTTPBASIC_INTERNAL) | ||
.users(NEGATIVE_LOOKAHEAD, NEGATED_REGEX) | ||
.users(NEGATIVE_LOOKAHEAD, NEGATED_REGEX, SEARCH_TEMPLATE) | ||
.build(); | ||
|
||
@Test | ||
|
@@ -68,4 +74,17 @@ public void testRegexPattern() throws Exception { | |
} | ||
|
||
} | ||
|
||
@Test | ||
public void testSearchTemplateRequest() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before adding search template into isClusterPerm function this would fail since it would come back with a 403 response code |
||
try (TestRestClient client = cluster.getRestClient(SEARCH_TEMPLATE)) { | ||
assertThat( | ||
client.getWithJsonBody( | ||
"r*/_search/template", | ||
"{\"source\":{\"query\":{\"match\":{\"service\":\"{{service_name}}\"}}},\"params\":{\"service_name\":\"Oracle\"}}" | ||
).getStatusCode(), | ||
equalTo(HttpStatus.SC_OK) | ||
); | ||
} | ||
} | ||
} |
This file contains 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 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.
Thank you @derek-ho ! This change looks good to me. I only have one concern about breaking existing roles that are unknowingly working with the bug in place, but since it is a bug fix I think its alright to provide documentation on how to update a role to make it so that SearchTemplateRequests are working properly. I also think it is worthwhile to modify the
cluster_composite_ops_ro
static action group to include search template and msearch template.To be clear, the role below allows SearchTemplateRequests to work even with the bug in place:
and after this change the role would need to be changed to:
With the bug in place the following role would not permit search template requests to work properly
but that would be achievable now with the following role definition:
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.
I don't think we can make the change for 2.x since it will be a breaking change. While it is an edge case, I don't think it matters if it is for a bug fix or not. Unless I am mistaken, semantic versioning would dictate we wait until 3.0 to make this available.
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.
Can you remove the
clusterPermissions
section for this role?