Support neural queries with hybrid DLS - #6428
Conversation
PR Reviewer Guide 🔍(Review updated until commit 80f8fe1)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 80f8fe1 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 7994f47
Suggestions up to commit 2e5b9fb
Suggestions up to commit bc86fd0
Suggestions up to commit 1d66f2f
Suggestions up to commit 3e57e8b
|
|
Persistent review updated to latest commit 5a90870 |
|
Persistent review updated to latest commit ce5a1cd |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6428 +/- ##
=======================================
Coverage 75.75% 75.75%
=======================================
Files 457 457
Lines 30508 30556 +48
Branches 4615 4630 +15
=======================================
+ Hits 23111 23149 +38
- Misses 5276 5284 +8
- Partials 2121 2123 +2
🚀 New features to boost your workflow:
|
|
@sharp-pixel can you please fix the conflicts post-merge of hybrid query support? |
looking |
ce5a1cd to
5aff58b
Compare
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit 5aff58b. ⛔ 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. |
|
Persistent review updated to latest commit 5aff58b |
|
Multi-knn hybrid queries fail closed under DLS. The Repro — originals Any hybrid with 2+ knn clauses (multi-vector-field search) throws. It fails closed, so not a security hole — but it breaks a legitimate workflow, and Verified against neural-search |
|
I am reviewing in depth because several things are broken in their current state. |
|
Persistent review updated to latest commit 8afbad7 |
|
Persistent review updated to latest commit 3e57e8b |
|
I reworked the implementation |
| private static final Function<QueryBuilder, Object> KNN_EXPAND_NESTED_GETTER = ReflectiveAttributeAccessors.objectMethod( | ||
| "getExpandNested", | ||
| Object.class | ||
| ); |
There was a problem hiding this comment.
I'm wary of this reflection surface (DlsFilterLevelActionHandler.java:87-127). Reflected bindings to ~10 KNNQueryBuilder/NeuralQueryBuilder getters are fragile: they're concrete method names on optional-plugin internals with no version guard, so a rename or signature change silently disables knn/neural hybrid DLS (fails closed, but the feature just stops working) and unit tests can't catch it since they mock QueryBuilder.
Worth noting applying the filter already uses a core contract - QueryBuilder#filter(QueryBuilder) and #visit(...). The reflection only exists to verify the result. So the clean fix is a core extension point for that verification - e.g. a way to introspect the filter embedded in a leaf builder - so Security can confirm the DLS filter landed without reaching into plugin internals. I'd prefer that over reflection.
If a core change isn't feasible in this PR's timeline, please add a version guard (min k-NN/neural or OpenSearch version where these accessors are known-stable) so drift fails predictably at a known boundary rather than silently.
There was a problem hiding this comment.
Thanks for raising this. Keeping in mind that we will need to backport the fix, version guard is a bit tricky.
I am removing the reflection and will propose a better alernative.
There was a problem hiding this comment.
@DarshitChanpura Can you check the revised implementation?
|
Persistent review updated to latest commit 1d66f2f |
|
Cross-repo gap: dense- opensearch-project/neural-search#1957 targets 3.9, same as this PR's |
|
Persistent review updated to latest commit bc86fd0 |
|
Persistent review updated to latest commit 2e5b9fb |
Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Fail closed unless neural and k-NN branches retain their original query semantics and store the exact DLS filter. Preserve query metadata and boolean matching behavior while validating multiple hybrid branches. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Exercise fail-closed neural accessor handling and every k-NN query parameter. Cover opaque snapshot values, structural fallback, and reflective method success and failure paths. Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
2e5b9fb to
7994f47
Compare
|
Cross-plugin coordination note: after this Security change lands, hybrid queries containing NeuralQueryBuilder will temporarily fail closed against the current Neural Search implementation because its embedded filter is not yet exposed through QueryBuilderVisitor. This is an availability/compatibility limitation, not a DLS bypass: unauthorized documents are not returned. opensearch-project/neural-search#1957 adds the required FILTER visitor traversal and cross-plugin integration coverage, enabling dense neural hybrid DLS. The two PRs are intended for a coordinated release, so the Security artifact should not be released without the companion Neural Search change. |
|
Persistent review updated to latest commit 7994f47 |
|
Persistent review updated to latest commit 80f8fe1 |
Description
This is a follow-up to #6416, which preserves a hybrid query as the top-level
query while applying Document-Level Security (DLS) to its execution branches.
The verification introduced by #6416 handles query builders that apply filters
through the standard boolean-wrapper contract. Neural and k-NN queries apply
filters differently:
neuralstores the filter internally and returns the same query builder;knnreturns a copied query builder containing the combined filter.As a result, otherwise valid hybrid requests containing these branches can fail
closed after DLS application.
This PR extends hybrid DLS handling without compile-time dependencies on either
optional plugin and without reflecting on plugin-specific getter names.
Security now relies on the public
QueryBuilder#filter(QueryBuilder)andQueryBuilder#visit(QueryBuilderVisitor)contract:visit();BooleanClause.Occur.FILTERchild;filter()preserves the original query semantics while adding the suppliedfilter.
After applying DLS, Security verifies that:
query name;
This contract-based approach remains valid for 3.9 and later releases without a
per-release upper-version allowlist. If a query builder does not expose its
branches or embedded filters through
visit(), changes query type, drops abranch, or fails to retain DLS, Security fails closed.
The change also:
boostand query name) when a filter-awarequery returns a copy;
minimum_should_matchbehavior when DLS is added to anembedded boolean filter;
neural_sparseon the generic boolean-wrapper path.No new setting, permission, REST API, optional-plugin dependency, or
plugin-specific reflection is introduced.
Companion PR and merge relationship
This PR and
opensearch-project/neural-search#1957
are interlocked for dense neural hybrid DLS:
NeuralQueryBuilder#visit()override todiscover the embedded neural filter. Without that traversal, Security fails
closed rather than applying DLS incompletely.
verification implemented by Security Support neural queries with hybrid DLS #6428.
This is not a compile-time dependency cycle: both repositories compile and run
their unit tests independently. The practical sequence is to merge and publish
Security #6428, validate Neural #1957 against that Security artifact, and then
merge Neural #1957. Both changes should ship together in OpenSearch 3.9.
Related work
opensearch-project/neural-search#1957.
opensearch-project/neural-search#1303.
Testing
Focused Security regression tests:
Result: passed.
Formatting and static analysis:
Result: passed.
JaCoCo reports 100% line coverage and 91.3% branch coverage across the modified
Security verification methods. The new direct-filter visitor has 100% line and
branch coverage.
The companion
HybridQueryDlsITsuite was run against the locally publishedSecurity plugin on a three-node Neural Search cluster. Five of six tests pass,
including direct k-NN, existing-filter, single-clause, suggestion, aggregation,
and hit-filtering coverage. The dense-neural test is currently blocked during
ML model registration by #6433, before the neural query executes.
Check List
dependency, and support boundaries are documented above and in code comments;
no user-facing setting or API is introduced
— N/A, no roles or permissions were added
completes an existing public
QueryBuildercontract without adding APIsurface
--signoffBy submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.