Skip to content
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 runAs to Subject interface and introduce IdentityAwarePlugin extension point #14630

Merged
merged 87 commits into from
Aug 28, 2024

Conversation

cwperks
Copy link
Member

@cwperks cwperks commented Jul 2, 2024

Description

Companion Security PR: opensearch-project/security#4665

This PR adds new method to the Subject interface called runAs and introduces a new extension point called IdentityAwarePlugin. This new method can be utilized to run a callable block of code in the context of the subject.

This PR also introduces the notion of an IdentityAwarePlugin which contains a single method to initialize the plugin. The IdentityPlugin will get to define which subject is passed to IdentityAwarePlugins on initialization. Practically, the Security Plugin is the IdentityPlugin and the subject passed to IdentityAwarePlugins is a special pluginSystemSubject which can be utilized to perform transport actions in the plugin system context and outside of the authenticated user context.

Subject.runAs() is intended to be an abstraction and replacement on the current pattern of System index interaction in which plugins will utilize the ThreadContext class and stash the context before performing transport actions on system indices.

With the changes in this PR, the NoopIdentityPlugin will assign a NoopPluginSubject to IdentityAwarePlugins. When using NoopPluginSubject.runAs(() -> { ... }) it runs the Callable within a block where the ThreadContext is stashed which is the same behavior plugins use today so its a direct replacement to try (ThreadContext.StoredContext ctx = threadContext.stashContext()) { ... }.

By itself, this PR is not very interesting, but with the changes in this PR it enables the Security plugin (the IdentityPlugin) to define an implementation for PluginSubject. If you look at the companion PR, the Security implementation of PluginSubject injects a pluginUser into the ThreadContext so that we can start using the existing security authz mechanisms to gate way plugins can do within the runAs block.

Related Issues

Related to: opensearch-project/security#4439

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Contributor

github-actions bot commented Jul 2, 2024

❌ Gradle check result for 444fde7: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

dblock pushed a commit that referenced this pull request Aug 29, 2024
…nsion point (#14630) (#15477)

* Create ExecutionContext and show example with ActionPluginProxy



* Only allow core to set the ExecutionContext



* WIP on plugin aware thread context



* Plugin Aware API Handling



* Add test to verify that ExecutionContext is being populated during RestHandling



* Clear context in a finally block



* Create switchContext method in ThreadContext and make pluginExecutionStack a stack



* WIP on plugin aware stash context



* Create class called PluginAwareNodeClient that provides a method called switchContext



* Remove ExecutionContext class



* Update javadoc



* Change createComponents to take in PluginAwareNodeClient



* Update all instances of createComponents



* Initialize clients



* Remove casting



* WIP on notion of ContextSwitcher



* Make stashContext package-private



* Make markAsSystemContext package-private



* Add javadoc on param



* Remove SystemContextSwitcher



* Merge with main



* Cleanup



* Remove SystemIndexFilter



* Add notion of Forbidden Headers to the ThreadContext



* Fix tests



* Fix test



* Add method to initialize plugins



* Create concept of pluginNodeClient that can be used for executing transport actions as the plugin



* Add test



* Add another test for setPluginNodeClient



* Remove newline



* Add another test



* Subject.runAs and introduce PluginSubject



* Do nothing when runAs is called for ShiroSubject and NoopSubject



* Remove extraneous changes



* Test all methods in PluginSubject



* Pass a Callable to runAs



* Update import



* Simplify PR, make NoopPluginSubject and introduce IdentityAwarePlugin



* Add final



* Remove server dependency



* Remove AbstractSubject



* Remove unnecessary changes



* Add javadoc to NoopPluginSubject



* Rename to assignSubject



* Add experimental label



* Add getPluginSubject(plugin) to IdentityPlugin



* Make runAs generic



* package-private constructor



* Move IdentityAwarePlugin initialization



* Create separate PluginSubject interface



* Remove authenticate method



* Remove import



* Separate UserSubject and PluginSubject



* Terminate TestThreadPool



* mock ThreadPool in RestSendToExtensionActionTests



* Fix Thread leak



* Add to CHANGELOG



* Rename to getCurrentSubject



* Add type check



* Rename to pluginSubject



* Add runAs to ActionRequest and surround doExecute in AbstractClient



* Return this



* Switch back to void



* Revert change to ActionRequest



---------


(cherry picked from commit ee17eca)

Signed-off-by: Craig Perkins <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ankit Jain <[email protected]>
akolarkunnu pushed a commit to akolarkunnu/OpenSearch that referenced this pull request Sep 10, 2024
…nsion point (opensearch-project#14630)

* Create ExecutionContext and show example with ActionPluginProxy

Signed-off-by: Craig Perkins <[email protected]>

* Only allow core to set the ExecutionContext

Signed-off-by: Craig Perkins <[email protected]>

* WIP on plugin aware thread context

Signed-off-by: Craig Perkins <[email protected]>

* Plugin Aware API Handling

Signed-off-by: Craig Perkins <[email protected]>

* Add test to verify that ExecutionContext is being populated during RestHandling

Signed-off-by: Craig Perkins <[email protected]>

* Clear context in a finally block

Signed-off-by: Craig Perkins <[email protected]>

* Create switchContext method in ThreadContext and make pluginExecutionStack a stack

Signed-off-by: Craig Perkins <[email protected]>

* WIP on plugin aware stash context

Signed-off-by: Craig Perkins <[email protected]>

* Create class called PluginAwareNodeClient that provides a method called switchContext

Signed-off-by: Craig Perkins <[email protected]>

* Remove ExecutionContext class

Signed-off-by: Craig Perkins <[email protected]>

* Update javadoc

Signed-off-by: Craig Perkins <[email protected]>

* Change createComponents to take in PluginAwareNodeClient

Signed-off-by: Craig Perkins <[email protected]>

* Update all instances of createComponents

Signed-off-by: Craig Perkins <[email protected]>

* Initialize clients

Signed-off-by: Craig Perkins <[email protected]>

* Remove casting

Signed-off-by: Craig Perkins <[email protected]>

* WIP on notion of ContextSwitcher

Signed-off-by: Craig Perkins <[email protected]>

* Make stashContext package-private

Signed-off-by: Craig Perkins <[email protected]>

* Make markAsSystemContext package-private

Signed-off-by: Craig Perkins <[email protected]>

* Add javadoc on param

Signed-off-by: Craig Perkins <[email protected]>

* Remove SystemContextSwitcher

Signed-off-by: Craig Perkins <[email protected]>

* Merge with main

Signed-off-by: Craig Perkins <[email protected]>

* Cleanup

Signed-off-by: Craig Perkins <[email protected]>

* Remove SystemIndexFilter

Signed-off-by: Craig Perkins <[email protected]>

* Add notion of Forbidden Headers to the ThreadContext

Signed-off-by: Craig Perkins <[email protected]>

* Fix tests

Signed-off-by: Craig Perkins <[email protected]>

* Fix test

Signed-off-by: Craig Perkins <[email protected]>

* Add method to initialize plugins

Signed-off-by: Craig Perkins <[email protected]>

* Create concept of pluginNodeClient that can be used for executing transport actions as the plugin

Signed-off-by: Craig Perkins <[email protected]>

* Add test

Signed-off-by: Craig Perkins <[email protected]>

* Add another test for setPluginNodeClient

Signed-off-by: Craig Perkins <[email protected]>

* Remove newline

Signed-off-by: Craig Perkins <[email protected]>

* Add another test

Signed-off-by: Craig Perkins <[email protected]>

* Subject.runAs and introduce PluginSubject

Signed-off-by: Craig Perkins <[email protected]>

* Do nothing when runAs is called for ShiroSubject and NoopSubject

Signed-off-by: Craig Perkins <[email protected]>

* Remove extraneous changes

Signed-off-by: Craig Perkins <[email protected]>

* Test all methods in PluginSubject

Signed-off-by: Craig Perkins <[email protected]>

* Pass a Callable to runAs

Signed-off-by: Craig Perkins <[email protected]>

* Update import

Signed-off-by: Craig Perkins <[email protected]>

* Simplify PR, make NoopPluginSubject and introduce IdentityAwarePlugin

Signed-off-by: Craig Perkins <[email protected]>

* Add final

Signed-off-by: Craig Perkins <[email protected]>

* Remove server dependency

Signed-off-by: Craig Perkins <[email protected]>

* Remove AbstractSubject

Signed-off-by: Craig Perkins <[email protected]>

* Remove unnecessary changes

Signed-off-by: Craig Perkins <[email protected]>

* Add javadoc to NoopPluginSubject

Signed-off-by: Craig Perkins <[email protected]>

* Rename to assignSubject

Signed-off-by: Craig Perkins <[email protected]>

* Add experimental label

Signed-off-by: Craig Perkins <[email protected]>

* Add getPluginSubject(plugin) to IdentityPlugin

Signed-off-by: Craig Perkins <[email protected]>

* Make runAs generic

Signed-off-by: Craig Perkins <[email protected]>

* package-private constructor

Signed-off-by: Craig Perkins <[email protected]>

* Move IdentityAwarePlugin initialization

Signed-off-by: Craig Perkins <[email protected]>

* Create separate PluginSubject interface

Signed-off-by: Craig Perkins <[email protected]>

* Remove authenticate method

Signed-off-by: Craig Perkins <[email protected]>

* Remove import

Signed-off-by: Craig Perkins <[email protected]>

* Separate UserSubject and PluginSubject

Signed-off-by: Craig Perkins <[email protected]>

* Terminate TestThreadPool

Signed-off-by: Craig Perkins <[email protected]>

* mock ThreadPool in RestSendToExtensionActionTests

Signed-off-by: Craig Perkins <[email protected]>

* Fix Thread leak

Signed-off-by: Craig Perkins <[email protected]>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <[email protected]>

* Rename to getCurrentSubject

Signed-off-by: Craig Perkins <[email protected]>

* Add type check

Signed-off-by: Craig Perkins <[email protected]>

* Rename to pluginSubject

Signed-off-by: Craig Perkins <[email protected]>

* Add runAs to ActionRequest and surround doExecute in AbstractClient

Signed-off-by: Craig Perkins <[email protected]>

* Return this

Signed-off-by: Craig Perkins <[email protected]>

* Switch back to void

Signed-off-by: Craig Perkins <[email protected]>

* Revert change to ActionRequest

Signed-off-by: Craig Perkins <[email protected]>

---------

Signed-off-by: Craig Perkins <[email protected]>
@cwperks cwperks mentioned this pull request Sep 20, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch enhancement Enhancement or improvement to existing feature or request v2.17.0 v3.0.0 Issues and PRs related to version 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants