Support hybrid search with adaptive DLS - #6416
Conversation
PR Reviewer Guide 🔍(Review updated until commit 7d11976)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 7d11976 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 5497e5c
Suggestions up to commit 85aa9be
Suggestions up to commit 26cb026
Suggestions up to commit 0ba09e3
|
Route top-level hybrid queries through filter-level DLS in adaptive mode and propagate the DLS filter to each hybrid subquery without wrapping the hybrid query. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Keep reader-level DLS active when adaptive mode pushes a DLS filter into hybrid query children. This protects aggregations, suggestions, and other search features outside the top-level query. Gate the new transport state on OpenSearch 3.9 and retain full filter-level handling for term lookup queries. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Run the existing star-tree restriction before skipping Lucene query wrapping for hybrid DLS. This prevents optimized search paths from bypassing document and field restrictions. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Avoid applying coordinating-cluster DLS filters to remote targets and preserve reader-level handling for parent/child hybrid queries. Stop placing request and DLS contents in internal debug markers. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Apply reader-level DLS for hybrid query markers so global aggregations cannot expose denied documents. Expand edge-case tests. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Fix P2-R2 by testing marker propagation to another local node and removal before a cross-cluster search request. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
0ba09e3 to
26cb026
Compare
|
Persistent review updated to latest commit 26cb026 |
Create and attach a search source before applying filter-level DLS so requests without an explicit source remain protected. Keep debug diagnostics useful without logging sensitive request or DLS query contents. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
|
Persistent review updated to latest commit 85aa9be |
Reject null results from the hybrid query filter contract. Document the optional-plugin query-name contract. Clarify how reader-level DLS remains active for hybrid searches. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
|
Persistent review updated to latest commit 5497e5c |
Fail closed if a hybrid query exposes parent or child clauses. Document source-less searches and internal header propagation. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
|
Persistent review updated to latest commit 7d11976 |
Description
Hybrid search requests can fail when they are executed by a user with Document-Level Security (DLS). Neural Search requires a
HybridQueryto remain the top-level Lucene query, while the Security plugin can wrap the user query inBooleanQueryandConstantScoreQueryobjects when enforcing DLS. Neural Search then rejects the query or fails while casting the wrapper toHybridQuery.The original report also observed inconsistent behavior: adding a suggestion could make an otherwise equivalent request succeed because it selected a different DLS path.
Old behavior
In adaptive DLS mode, a top-level hybrid query could be wrapped by the Security plugin. This changed the query shape expected by Neural Search and could cause every shard to fail with errors such as:
hybrid query must be a top level query and cannot be wrapped into other queriesBooleanQueryorConstantScoreQuerycannot be cast toHybridQueryNew behavior
For supported top-level hybrid requests in adaptive mode, the Security plugin now:
QueryBuilder.filter(...), preserving the hybrid query as the top-level query and propagating DLS into every hybrid subquery.Non-hybrid queries and unsupported hybrid configurations continue through their existing DLS paths.
Supported scope
The special hybrid handling is enabled only when all of these conditions are true:
adaptive.hybridquery.Within that scope, the fix supports:
Not supported by this change
The special handling is intentionally not enabled for:
filter_levelDLS mode.lucene_levelDLS mode.These cases retain their existing DLS behavior and are not claimed to be compatible with hybrid search by this PR.
This change introduces no new setting, permission, REST API, or dependency on the Neural Search plugin.
Issues Resolved
Addresses:
Related prior work:
Neural Search PR #1432 added support for recognizing and reconstructing the Security DLS wrapper shape available at the time. This PR complements that work on the Security side by avoiding the outer wrapper for supported hybrid requests.
This is not a backport.
These changes introduce no new permissions and require no Security Dashboards companion PR.
Testing
Security plugin unit tests
Added focused coverage for:
Executed:
./gradlew test \ --tests org.opensearch.security.configuration.DlsFlsFilterLeafReaderTest \ --tests org.opensearch.security.configuration.DlsFilterLevelActionHandlerTest \ --tests org.opensearch.security.configuration.DlsFlsValveImplTest \ --tests org.opensearch.security.privileges.dlsfls.DlsFlsBaseContextTest \ --tests org.opensearch.security.transport.SecurityInterceptorTestsResult: passed.
Result: passed.
The Security plugin bundle was also built successfully.
Cross-plugin integration testing
A companion Neural Search integration test was run against the locally built Security plugin:
Result: passed on a three-node cluster.
The test verifies the unrestricted administrator baseline, DLS-filtered hits, DLS-protected global aggregation counts and buckets, suggestions, composition with an existing hybrid filter, a single-clause hybrid query, no duplicate hits, and no failed shards.
Running the same test with the unmodified Security plugin reproduced the original top-level
BooleanQuery/HybridQueryfailure.The companion integration coverage is available in opensearch-project/neural-search#1957. That draft depends on this Security PR and should merge only after this fix is available to the Neural Search integration-test build.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.