-
Notifications
You must be signed in to change notification settings - Fork 341
Implement new extension points in IdentityPlugin and add ContextProvidingPluginSubject #4896
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
cwperks
merged 21 commits into
opensearch-project:main
from
cwperks:security-subject-rebase
Jan 14, 2025
Merged
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
779d9d3
Rebasing security subject
cwperks de50e87
Complete rebase
cwperks 9a997b2
Fix tests
cwperks 372c657
Leave action out of error message for now
cwperks fdf7256
Merge branch 'main' into security-subject-rebase
cwperks c25e1ab
Remove calls to isPluginUser
cwperks 0adcd76
Merge branch 'main' into security-subject-rebase
cwperks 941c131
Pluralize
cwperks 071cca9
Merge branch 'main' into security-subject-rebase
cwperks 2a0aa3a
Merge branch 'main' into security-subject-rebase
cwperks 3e353c9
Address review feedback
cwperks ce80b7c
Check if pluginUser
cwperks 154556c
Remove overloaded method
cwperks fce023a
Merge branch 'main' into security-subject-rebase
cwperks 1f7417c
Respond to PR feedback
cwperks cb06896
Add unit tests
cwperks 40c89ec
Create RestMatchers
cwperks cf1a4d9
Add license header
cwperks 6537f14
Check for injected roles
cwperks 3242b30
Rename to UserSubjectImpl
cwperks 2fdb4b9
Add comment
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
27 changes: 0 additions & 27 deletions
27
src/integrationTest/java/org/opensearch/security/http/ExampleSystemIndexPlugin.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...tegrationTest/java/org/opensearch/security/plugin/IndexDocumentIntoSystemIndexAction.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,22 @@ | ||
| /* | ||
| * 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.plugin; | ||
|
|
||
| import org.opensearch.action.ActionType; | ||
|
|
||
| public class IndexDocumentIntoSystemIndexAction extends ActionType<IndexDocumentIntoSystemIndexResponse> { | ||
| public static final IndexDocumentIntoSystemIndexAction INSTANCE = new IndexDocumentIntoSystemIndexAction(); | ||
| public static final String NAME = "cluster:mock/systemindex/index"; | ||
|
|
||
| private IndexDocumentIntoSystemIndexAction() { | ||
| super(NAME, IndexDocumentIntoSystemIndexResponse::new); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...egrationTest/java/org/opensearch/security/plugin/IndexDocumentIntoSystemIndexRequest.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,48 @@ | ||
| /* | ||
| * 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.plugin; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.opensearch.action.ActionRequest; | ||
| import org.opensearch.action.ActionRequestValidationException; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
|
|
||
| public class IndexDocumentIntoSystemIndexRequest extends ActionRequest { | ||
|
|
||
| private final String indexName; | ||
|
|
||
| private final String runAs; | ||
|
|
||
| public IndexDocumentIntoSystemIndexRequest(String indexName, String runAs) { | ||
| this.indexName = indexName; | ||
| this.runAs = runAs; | ||
| } | ||
|
|
||
| public IndexDocumentIntoSystemIndexRequest(StreamInput in) throws IOException { | ||
| super(in); | ||
| this.indexName = in.readString(); | ||
| this.runAs = in.readOptionalString(); | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| return null; | ||
| } | ||
|
|
||
| public String getIndexName() { | ||
| return this.indexName; | ||
| } | ||
|
|
||
| public String getRunAs() { | ||
| return this.runAs; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...grationTest/java/org/opensearch/security/plugin/IndexDocumentIntoSystemIndexResponse.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,48 @@ | ||
| /* | ||
| * 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.plugin; | ||
|
|
||
| // CS-SUPPRESS-SINGLE: RegexpSingleline It is not possible to use phrase "cluster manager" instead of master here | ||
| import java.io.IOException; | ||
|
|
||
| import org.opensearch.action.support.master.AcknowledgedResponse; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
| import org.opensearch.core.xcontent.ToXContent; | ||
| import org.opensearch.core.xcontent.ToXContentObject; | ||
| import org.opensearch.core.xcontent.XContentBuilder; | ||
| // CS-ENFORCE-SINGLE | ||
|
|
||
| public class IndexDocumentIntoSystemIndexResponse extends AcknowledgedResponse implements ToXContentObject { | ||
|
|
||
| private String plugin; | ||
|
|
||
| public IndexDocumentIntoSystemIndexResponse(boolean status, String plugin) { | ||
| super(status); | ||
| this.plugin = plugin; | ||
| } | ||
|
|
||
| public IndexDocumentIntoSystemIndexResponse(StreamInput in) throws IOException { | ||
| super(in); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| out.writeString(plugin); | ||
| } | ||
|
|
||
| @Override | ||
| public void addCustomFields(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
| super.addCustomFields(builder, params); | ||
| builder.field("plugin", plugin); | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
.../java/org/opensearch/security/plugin/RestBulkIndexDocumentIntoMixOfSystemIndexAction.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,77 @@ | ||
| /* | ||
| * 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.plugin; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.opensearch.action.bulk.BulkRequest; | ||
| import org.opensearch.action.bulk.BulkRequestBuilder; | ||
| import org.opensearch.action.index.IndexRequest; | ||
| import org.opensearch.action.support.WriteRequest; | ||
| import org.opensearch.client.Client; | ||
| import org.opensearch.client.node.NodeClient; | ||
| import org.opensearch.core.action.ActionListener; | ||
| import org.opensearch.core.rest.RestStatus; | ||
| import org.opensearch.core.xcontent.ToXContent; | ||
| import org.opensearch.rest.BaseRestHandler; | ||
| import org.opensearch.rest.BytesRestResponse; | ||
| import org.opensearch.rest.RestChannel; | ||
| import org.opensearch.rest.RestRequest; | ||
| import org.opensearch.security.identity.PluginContextSwitcher; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
| import static org.opensearch.rest.RestRequest.Method.PUT; | ||
| import static org.opensearch.security.plugin.SystemIndexPlugin1.SYSTEM_INDEX_1; | ||
| import static org.opensearch.security.plugin.SystemIndexPlugin2.SYSTEM_INDEX_2; | ||
|
|
||
| public class RestBulkIndexDocumentIntoMixOfSystemIndexAction extends BaseRestHandler { | ||
|
|
||
| private final Client client; | ||
| private final PluginContextSwitcher contextSwitcher; | ||
|
|
||
| public RestBulkIndexDocumentIntoMixOfSystemIndexAction(Client client, PluginContextSwitcher contextSwitcher) { | ||
| this.client = client; | ||
| this.contextSwitcher = contextSwitcher; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Route> routes() { | ||
| return singletonList(new Route(PUT, "/try-create-and-bulk-mixed-index")); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "test_bulk_index_document_into_mix_of_system_index_action"; | ||
| } | ||
|
|
||
| @Override | ||
| public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
| return new RestChannelConsumer() { | ||
|
|
||
| @Override | ||
| public void accept(RestChannel channel) throws Exception { | ||
| contextSwitcher.runAs(() -> { | ||
| BulkRequestBuilder builder = client.prepareBulk(); | ||
| builder.add(new IndexRequest(SYSTEM_INDEX_1).source("content", 1)); | ||
| builder.add(new IndexRequest(SYSTEM_INDEX_2).source("content", 1)); | ||
| builder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); | ||
| BulkRequest bulkRequest = builder.request(); | ||
| client.bulk(bulkRequest, ActionListener.wrap(r -> { | ||
| channel.sendResponse( | ||
| new BytesRestResponse(RestStatus.OK, r.toXContent(channel.newBuilder(), ToXContent.EMPTY_PARAMS)) | ||
| ); | ||
| }, fr -> { channel.sendResponse(new BytesRestResponse(RestStatus.FORBIDDEN, String.valueOf(fr))); })); | ||
| return null; | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } |
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.