Repository navigation
Keep plugin reads of their own system index realtime - #6668
DarshitChanpura merged 3 commits into
Conversation
The legacy privileges evaluator turns off realtime gets and the search request cache for every request on the security index or a system index. A realtime get of an unrefreshed document is read from the translog, which the security index searcher wrappers do not filter, and the request cache key does not include the user. For a plugin subject the wrappers do not filter its own system indices, unless they are protected indices. So a GET or multi-get by the plugin subject on its own system index missed a write made just before it until the next refresh, which did not happen when plugins read under a stashed thread context. Keep realtime and the request cache when a plugin subject requests only its own registered system indices, not as _all, and none of them is the security index or a protected index. All other requests keep the override. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
PR Reviewer Guide 🔍(Review updated until commit ee0d655)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to ee0d655 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit d1bdf3f
Suggestions up to commit 6a458ac
|
|
@DarshitChanpura when this happens I think that plugins should generally use RefreshPolicy.IMMEDIATE on writes to a system index. They are low volume enough writes that RefreshPolicy.IMMEDIATE is justified IMO. |
The security plugin reads the first plugin-additional-permissions.yml on a plugin's class path. The sample resource plugin's integration tests load the root integration test output before the sample plugin's own resources, so the root test plugin's file replaced the sample plugin's file and its plugin subject lost its cluster permissions. Move the root file to src/integrationTest/plugin-permissions, which is on the root integration test class path only. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
|
Persistent review updated to latest commit d1bdf3f |
|
Agreed that plugins should set a refresh policy on their writes to system indices. Those writes are low volume, and I'd still like to keep this change for GETs. Without the security plugin, a GET by id is realtime, so a plugin can read its own write with no refresh. Under a plugin subject the legacy evaluator makes that same GET non-realtime, so code that works with security off misses the write with security on, and nothing reports it. Covering that only through refresh policies means every write path in every plugin has to get it right, and a miss shows up only on a secured cluster. So I'd propose both:
|
|
Persistent review updated to latest commit ee0d655 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6668 +/- ##
==========================================
+ Coverage 76.81% 76.85% +0.04%
==========================================
Files 487 487
Lines 32228 32234 +6
Branches 4870 4871 +1
==========================================
+ Hits 24755 24773 +18
+ Misses 5252 5244 -8
+ Partials 2221 2217 -4
🚀 New features to boost your workflow:
|
|
@cwperks @RyanL1997 could you take a look when you have a moment? CI is green. Once this merges, reporting PR opensearch-project/reporting#1232 can come out of draft. |
Description
GET on a plugin's own system index is not realtime under the plugin subject.
Category: Bug fix
Why these changes are required?
Plugins are moving their system index reads and writes from
ThreadContext.stashContext()to the plugin subject (PluginSubject.runAs). Under a stashed context the transient user is null, soSecurityFilterdoes not evaluate the request, and a GET or multi-get keeps its defaultrealtime=true. Under the plugin subject the request is evaluated. With the default legacy privileges evaluator,SystemIndexAccessEvaluator.evaluatethen setsrealtime(false)andrequestCache(false)on every request that touches the security index or a system index. A plugin that indexes a document without a refresh and reads it back by id gets "not found" until the next refresh. Plugin integration tests that create and then get a document fail on this after the move.Why the override exists
The block came in with the first release of this plugin for the security index. It was extended to protected indices in opendistro-for-elasticsearch/security PR 126 and to system indices in opendistro-for-elasticsearch/security PR 690. Each change added the override together with a rule in the index searcher wrapper (
SystemIndexSearcherWrapper): an empty reader on the security index for anyone but the admin, on protected indices for users without a protected index role, and on system indices for users without system index access.DlsFlsValveImplturns realtime off for the same reason when DLS, FLS or field masking applies.InternalEngine.get,TranslogLeafReader). The index searcher wrappers do not apply to that read. Turning realtime off makes the GET read through the wrapped reader, so it returns what a search would return for the same user.The nextgen (v4) evaluator has no such override. Its authorization denies or removes indices that the user has no privileges for before the request runs.
What is the old behavior before changes and new behavior after changes?
Before: under the legacy evaluator, a GET, multi-get or size 0 search by a plugin subject on its own system index is not realtime and does not use the request cache.
After: the legacy evaluator keeps realtime and the request cache for a request from a plugin subject when every requested index is one of the plugin's own registered system indices, the request is not
_all, and none of the indices is the security index or a protected index. For such a request the wrappers return the full reader:isAdminDnOrPluginRequest()lets the plugin through the system index rule, andDlsFlsBaseContexthas no DLS or FLS context for plugin requests. A realtime read or a cached result therefore returns the same documents as a non-realtime read. Everything else keeps the override:The check uses the plugin's matching indices that the evaluator already computes for its authorization decision. That set is now computed once in
evaluateand passed down.Not changed:
ProtectedIndexAccessEvaluatorandDlsFlsValveImpl. A plugin subject's index action on its own system indices returns fromSystemIndexAccessEvaluatorbeforeProtectedIndexAccessEvaluatorruns, andDlsFlsValveImplreturns early for plugin requests. Its resource sharing branch rewrites onlySearchRequest, so a GET is not affected. For a search on a resource index, the resource sharing filter is part of the query, so it is part of the request cache key.indices:data/read/mgetin its declared permissions to use it. With system index permissions enabled it is also denied on the plugin's own system index unless the plugin declares the system index permission for it. Both are current behaviour.Issues Resolved
None filed.
Testing
New integration tests, all run against a real cluster with refresh disabled on the index so that only a realtime read sees an unrefreshed document:
PluginSystemIndexRealtimeIntTests, parameterized over the legacy evaluator, the legacy evaluator with system index permissions, and v4 (21 cases):PluginProtectedSystemIndexRealtimeIntTests: a plugin's own system index that is also a protected index stays non-realtime for the plugin subject.SystemIndexDisabledTests: with system index protection disabled, the plugin subject's GET on its own index is realtime (it was before this change too).PluginReadAfterWriteTestsin the sample resource plugin, with resource sharing enabled: the plugin's GET of a resource by id returns an update that has not been refreshed.SystemIndexAccessEvaluatorPluginSubjectTest(unit): one case per condition of the check (own indices, own and regular index,_all, the security index, a protected index).The test plugin declares
indices:data/read/mgetand read access to the regular index in a testplugin-additional-permissions.yml, as real plugins declare what they read. The file is insrc/integrationTest/plugin-permissions, which is on the class path of the root integration tests only. The sample resource plugin's integration tests load the root integration test output, and the security plugin reads the firstplugin-additional-permissions.ymlon the plugin's class path, so a copy insrc/integrationTest/resourceswould replace the sample plugin's own file.Without the change in
SystemIndexAccessEvaluator, 5 cases ofPluginSystemIndexRealtimeIntTests,PluginReadAfterWriteTestsand the own index unit case fail; with it all pass. Each control was checked by breaking the check: turning the system index override off for every user fails the 4 normal user cases and the mixed multi-get case, dropping the "every index" condition fails the mixed multi-get case and its unit case, dropping the protected index condition failsPluginProtectedSystemIndexRealtimeIntTestsand its unit case, and dropping the_allor security index condition fails its unit case. In the legacy configuration without system index permissions, skipping the override for every user makes a normal user's GET return a document that the same user's search does not return.Check List
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.