Repository navigation
Reach the report indices through the plugin subject - #1232
joshuali925 merged 5 commits into
Conversation
doExecute had no catch, so an exception raised while switching to the plugin subject left doExecute as a throw and the listener was never completed. A caller that only waits on the listener then waits forever. Complete it with listener.onFailure instead. Also lowers the line that names the subject's principal from info to debug, so an identity is not written on every transport action at a level that is on by default, and marks the subject volatile because assignSubject writes it from a different thread than the transport actions that read it. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Both index classes wrapped the node client in SecureIndexClient, which stashed the thread context in every override, and the index creation path stashed again around admin().indices().create(). Point them at PluginClient instead, so every read and write to .opendistro-reports-definitions and .opendistro-reports-instances runs as the subject assigned through IdentityAwarePlugin, and delete SecureIndexClient. With the plugin client in place at initialize time, the per-request client choice in getAllReportDefinitions and getAllReportInstances resolves to the same client on both sides of the resource-sharing branch, so the parameter threaded in from the two list actions goes away. Which access list the search carries is still decided by the resource-sharing check. The index creation path reaches admin().indices(), which FilterClient routes back through doExecute, so it now runs as the plugin subject where previously SecureIndexClient delegated admin() to the raw client and the call site stashed by hand. The stash in PluginBaseAction is left in place. It is not system index access: it moves the caller's context onto the coroutine's pooled thread for the length of the request and leaves that thread as it was found. A comment now says so. Adds plugin-additional-permissions.yml with an empty cluster_permissions list. Index actions on a registered system index need no entry and this plugin issues only create, get, index, update, delete and search, none of which security classifies as a cluster permission. The key is present rather than the file omitted because security appends bulk to the parsed list. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit a892d0d. ⛔ Hard block: Issues at High severity or above will block this PR from merging.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
PR Reviewer Guide 🔍(Review updated until commit a892d0d)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to a892d0d Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit a892d0d
Suggestions up to commit a892d0d
Suggestions up to commit 96e1168
Suggestions up to commit 019a6cd
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1232 +/- ##
============================================
+ Coverage 73.12% 74.48% +1.36%
+ Complexity 406 396 -10
============================================
Files 68 67 -1
Lines 2221 2152 -69
Branches 236 233 -3
============================================
- Hits 1624 1603 -21
+ Misses 463 418 -45
+ Partials 134 131 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PluginClient no longer catches around runAs. A failure the wrapped client throws synchronously, such as a missing action or a cancelled task, now reaches the caller as it does from any other client, and the listener is not also notified. Core already reports validation and filter chain failures through the listener, so the catch only changed the contract for this one client, and when the caller's listener itself threw during synchronous completion it notified that listener a second time. This supersedes the earlier commit on this branch, "Report a synchronous PluginClient failure through the listener"; the version on main, which let these failures escape, already matched core. The listener is wrapped with ContextPreservingActionListener.wrapPreservingContext instead of newStoredContext(false) with ActionListener.runBefore. The listener still sees the caller's context, but the responding thread gets its own context back afterwards instead of keeping the caller's, and response headers the action added are kept. The subject is typed PluginSubject and held in an AtomicReference. It can be set once: the same subject again is a no-op, and a different one throws. getRemoteClusterClient throws UnsupportedOperationException, because FilterClient would return the delegate's remote client, which does not run as the subject. Nothing in the plugin calls it. PluginClientTests is rewritten around a fake PluginSubject that stashes and restores its context the way the real subjects do. It covers running inside the subject, the caller's context in the listener on response and on failure, the responding thread's context afterwards, response headers, synchronous failures reaching the caller, a throwing listener notified once, set-once assignment, the remote client refusal and use before assignment. The test that expected a synchronous failure to reach the listener is removed. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
|
Persistent review updated to latest commit 96e1168 |
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
The local PluginClient copied the client that common-utils now provides as the abstract org.opensearch.commons.client.PluginClient. It is now a subclass of that class with the one constructor the plugin calls, and keeps its package and name, so the call sites do not change and the plugin keeps its own runtime class for component binding. Removed: the copied subject handling, the context restoring listener wrapper, the remote cluster override, the two-argument constructor that only tests used, and the tests that re-tested the copied client, which common-utils now tests. Behaviour is unchanged: the base class runs each action inside the subject's runAs, restores the caller's context with ContextPreservingActionListener, sets the subject once and rejects a different one, and refuses a remote cluster client, as the copy did. common-utils is already bundled in the plugin zip. Adds a test that the PluginClient returned from createComponents runs its actions as the subject passed to assignSubject. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
|
Persistent review updated to latest commit a892d0d |
|
Persistent review updated to latest commit a892d0d |
|
Persistent review updated to latest commit a892d0d |
|
@ps48 @joshuali925 @derek-ho this is out of draft and CI is green, including the resource sharing leg. Could you review when you have a moment? The Testing section explains why a run can fail with "not found" after a create when it picks up a security |
Description
Replaces
ThreadContext.stashContextwith the plugin subject assigned throughIdentityAwarePlugin, so reporting reaches its own system indices as its plugin subject rather than from an unrestricted stashed context.IdentityAwarePluginandutil.PluginClientare already onmain; this finishes the job by moving the remaining call sites onto them.30 of the 32 stash calls being removed were inside
SecureIndexClient, aClient-by-delegation wrapper that stashed in every override, wired at one site each inReportDefinitionsIndexandReportInstancesIndex. That class is deleted and both index classes now hold thePluginClient. The other two were the explicit stash around index creation in each of those classes.Both index classes touch exactly one index each,
.opendistro-reports-definitionsand.opendistro-reports-instances, and both are already registered throughgetSystemIndexDescriptors.Because the plugin client is now the client the index classes hold, the per-request client choice in
getAllReportDefinitionsandgetAllReportInstancesresolves to the same client on both sides of the resource-sharing branch, so the parameter threaded in from the two list actions is gone. Which access list the search carries is still decided by the resource-sharing check, unchanged.Two behaviour changes worth review:
SecureIndexClientdelegatedadmin()to the raw client, soadmin().indices().create()ran as the caller inside a hand written stash.PluginClientextendsFilterClient, whoseadmin()routes back throughdoExecute, so index creation now runs as the plugin subject as well.util.PluginClientis now a subclass of the sharedorg.opensearch.commons.client.PluginClientfrom common-utils, which reporting already bundles. It keeps its package and name, so the call sites are unchanged, and it has its own runtime class, so no other plugin's client can be injected in its place. The base class restores the caller's thread context around the listener with core'sContextPreservingActionListener.wrapPreservingContext, which puts the responding thread's own context back afterwards and keeps response headers the action added. It does not catch aroundrunAs: a failure raised synchronously by the wrapped client reaches the caller as it does with any other client, and the listener is not also notified. The subject is typedPluginSubject, so a non plugin subject cannot be assigned and run actions in the caller's context; it can be assigned once, and assigning a different one throws.getRemoteClusterClientthrows, because the remote client it would return does not run as the subject. The line naming the subject's principal is logged at debug, so an identity is not written on every transport action at a level that is on by default.The stash in
PluginBaseActionis deliberately kept. It is not system index access: the action captures the caller's context on the transport thread, then on the coroutine's pooled thread it stashes whatever the previous task left there, restores the caller's context for the length of the request, and lets the stash put the pooled thread back as it was found. Removing it would both run the request with a stale context and leave the caller's context on that thread for the next task. A comment now records why it is there.Also adds
plugin-additional-permissions.ymlwith an emptycluster_permissionslist. For index actions a plugin subject is already granted everything on its own registered system indices, and the migrated call sites issue onlyindices:admin/create, get, index, update, delete and search. None of the operations that security classifies as cluster permissions despite acting on indices (mget, msearch, scroll, multi term vectors, reindex, template admin) are used anywhere in the plugin, so there is nothing to grant. The key is present rather than the file omitted because security appends bulk to the list it parses.Testing
assemble,test,ktlintanddetektpass on JDK 21. 106 unit tests, no skips and no failures, against a baseline of 105 onmain; the newReportsSchedulerPluginTestsis the whole delta.The behaviour of the client itself is tested in common-utils, so this PR does not repeat those tests.
ReportsSchedulerPluginTestschecks the wiring that is specific to reporting: thePluginClientthatcreateComponentsreturns runs its actions inside the subject given toassignSubject. It was checked by makingassignSubjectdo nothing and confirming the test fails.Not verified by execution: the permissions file and the behaviour of the migrated call sites against a cluster with security installed. Unit tests do not go through the security plugin, so the reasoning about which actions need granting comes from reading security's privileges evaluator, not from a run. This repository does have a with security workflow, including a resource sharing enabled matrix leg, so CI will exercise it here; it was not run locally.
The integration tests read a document right after writing it, so they need opensearch-project/security#6668, which keeps a plugin's GET on its own system index realtime. The IT cluster takes the latest
opensearch-security:3.10.0.0-SNAPSHOTzip, and security'smainand3.10branches both publish that coordinate; the3.10build does not include 6668. A run that picks up a3.10build fails with "not found" right after a create. Against amainbuild all 28 integration tests and the 10 resource sharing tests pass locally.Related
Tracking issue: opensearch-project/opensearch-plugins#238
RFC: opensearch-project/security#4439
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.