-
Notifications
You must be signed in to change notification settings - Fork 281
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
Implement new extension points in IdentityPlugin and add ContextProvidingPluginSubject #4665
Closed
Closed
Changes from 17 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
e65b248
Implement new extension points in IdentityPlugin and add ContextProvi…
cwperks 55a7e45
Remove code from UserService
cwperks 44c0d76
Remove commented out code
cwperks 3e17b57
Use guice dependencies
cwperks 0add3d8
Move TransportActionDependencies
cwperks b76a5b8
Use NamedPrincipal
cwperks 2da6f2a
Add end to end test to show stronger index protection for plugins
cwperks 9cf80ae
Add end to end test to show stronger index protection for plugins
cwperks 21fc225
Move to constructor
cwperks f08f311
Remove unused constant
cwperks 2de9a5f
Add test that demonstrates cluster action forbidden when running with…
cwperks 22795df
Add bulk index test
cwperks e075ae8
Ensure bulk request with mix of actions blocks as expected
cwperks e12f673
Use subclass instead of attribute
cwperks f9adcc4
Rename TransportActionDependencies to PluginContextSwitcher
cwperks 2074dab
Prevent pluginUser from being serialized to nodes before 2.17.0 for b…
cwperks 0960ce0
Demonstrate how a role can be created in-memory to re-use authz
cwperks 8c2b7ba
Add missing license headers
cwperks 675f20a
Remove unused code
cwperks 8d3eb1c
Remove unused field
cwperks 115fa0e
Implement getCurrentSubject
cwperks f6650eb
Use transport for cluster health tests
cwperks 77b728d
Show use of default
cwperks a649257
Show an example of switching subjects within a transport action
cwperks 7170c82
Show example of attaching subject to ActionRequest
cwperks 9c205a6
Revert "Show example of attaching subject to ActionRequest"
cwperks 690144e
Remove copy of SystemIndexRegistry and use exposed methods from core
cwperks b18d3aa
Merge branch 'main' into security-subject
cwperks e781e37
Fix failing tests
cwperks 3c60808
Fix SystemIndexPermissionEnabledTests tests
cwperks e42a4a0
Fix tests
cwperks 41e83b1
Fix disabled tests
cwperks c9f1ff7
Fix more tests
cwperks 72c155b
Merge branch 'main' into security-subject
cwperks 0a696ff
Add license headers
cwperks c4b5e17
Add tests
cwperks 1d1bb57
Test PluginContextSwitcher
cwperks 27be3c3
Test getPrincipal
cwperks 634cf7b
Add test on createSecurityRole
cwperks 1af4b65
Increase test coverage
cwperks 64fb161
Allow import for AcknowledgedResponse
cwperks dc8868e
Address code review comments
cwperks 565fa20
Address code review feedback
cwperks 23e62bf
Merge branch 'main' into security-subject
cwperks e5855ab
Change calls to isPluginUser and create InMemorySecurityRoles
cwperks b8c333c
Add missing license header
cwperks 9b0c3df
Use plugin: prefix
cwperks abea484
Remove PluginUser
cwperks 86c3336
Merge branch 'main' into security-subject
cwperks ed13ecb
Remove Identity FeatureFlag
cwperks 68ff270
Fix tests
cwperks 70bb6ef
Merge branch 'main' into security-subject
cwperks dbb723a
Merge branch 'main' into security-subject
cwperks 275a346
Merge branch 'main' into security-subject
cwperks 0216cc0
Address code review feedback
cwperks 05890d5
Create common method for getting SecurityRoles and move plugin specif…
cwperks 877fd42
Merge branch 'main' into security-subject
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 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 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 = "mock:systemindex/index"; | ||
|
||
private IndexDocumentIntoSystemIndexAction() { | ||
super(NAME, IndexDocumentIntoSystemIndexResponse::new); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...egrationTest/java/org/opensearch/security/plugin/IndexDocumentIntoSystemIndexRequest.java
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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; | ||
|
||
public IndexDocumentIntoSystemIndexRequest(String indexName) { | ||
this.indexName = indexName; | ||
} | ||
|
||
public IndexDocumentIntoSystemIndexRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.indexName = in.readString(); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
public String getIndexName() { | ||
return this.indexName; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...grationTest/java/org/opensearch/security/plugin/IndexDocumentIntoSystemIndexResponse.java
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.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; | ||
|
||
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); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
.../java/org/opensearch/security/plugin/RestBulkIndexDocumentIntoMixOfSystemIndexAction.java
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
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.common.xcontent.XContentType; | ||
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}", XContentType.JSON)); | ||
builder.add(new IndexRequest(SYSTEM_INDEX_2).source("{\"content\":1}", XContentType.JSON)); | ||
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.
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 had a created a separate test-suite, SystemIndexPermissionEnabledTests.java, where this feature flag is enabled. Should the new tests be moved there?
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.
This is from a previous commit that can be removed now. In a previous iteration I created an in-memory role with a SystemIndexPermission, but have since updated the
SystemIndexAccessEvaluator
to check if the current user is a pluginUser. The SystemIndexAccessEvaluator logic will always kick in for a pluginUser regardless of what the action being performed is.