You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DLS for pluggable data formats and query execution - #6569
It mostly boils down to exposing DLS rules via the AccessPolicyProviderPlugin interface.
Testing
Unit tests cover unrestricted, fully restricted (match_none), combined role queries, grouped restrictions, and overlapping-group rejection.
Security integration tests install a mock logical-read consumer that obtains policies through ReadAccessPolicyService. They verify the actual Security provider returns the expected restriction for a DLS user and no restriction for an unrestricted user.
This complements the OpenSearch-side analytics QA test, which uses a mock AccessPolicyProviderPlugin to validate analytics enforcement independently of the Security plugin.
Check List
New functionality includes testing
Commits are signed per the DCO using --signoff
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.
Grouping is performed by QueryBuilder keys in a HashMap, which relies on equals/hashCode. For a fully-restricted index, combine returns a MatchNoneQueryBuilder from DlsRestriction.FULL's queries, and more generally different QueryBuilder instances with equivalent semantics may not implement equals reliably, so identical restrictions won't be grouped. Consider keying by the rendered query string (as DocumentPrivileges.RenderedDlsQuery already provides) to ensure stable grouping across indices.
QueryBuilder query = combine(restriction.getQueries());
+// Group by stable string representation to avoid relying on QueryBuilder.equals()
indicesByRestriction.computeIfAbsent(query, ignored -> new LinkedHashSet<>()).add(index);
Suggestion importance[1-10]: 6
__
Why: Valid concern that QueryBuilder.equals/hashCode may not reliably group semantically equivalent queries, which could lead to redundant index groups. However, the suggestion's improved_code is identical to the existing_code (only a comment is added), so the actual fix is not demonstrated.
Low
Validate required path parameter
request.param("indices") can be null if the parameter is absent, causing an NPE in split. Although this is test-only infrastructure, consider validating and returning a clear error so test failures are easier to diagnose.
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
- MockReadAccessRequest mockRequest = new MockReadAccessRequest(request.param("indices").split(","));+ String indicesParam = request.param("indices");+ if (indicesParam == null || indicesParam.isEmpty()) {+ throw new IllegalArgumentException("'indices' path parameter is required");+ }+ MockReadAccessRequest mockRequest = new MockReadAccessRequest(indicesParam.split(","));
return channel -> client.execute(MockReadAccessAction.INSTANCE, mockRequest, new RestToXContentListener<>(channel));
}
Suggestion importance[1-10]: 2
__
Why: This is test-only infrastructure where the path parameter {indices} is required by the route definition, so it will not be null. The suggestion offers negligible value.
Low
Possible issue
Guard against null DLS config
baseContext.config() may return null if DLS/FLS configuration has not yet been initialized (e.g. during early startup or in SSL-only mode), which would NPE here. Guard against a null config and treat it as unrestricted to be consistent with the null privilegesContext branch above.
Why: Defensive null-check for baseContext.config() is reasonable, but it's unclear whether config() can actually return null in practice given this provider is instantiated after configuration setup; the impact is minor.
Grouping by QueryBuilder key relies on equals/hashCode, but if the same index appears multiple times in context.concreteIndices() (duplicates), it would be silently added only once to the group but still passed into ReadAccessPolicyImpl, which throws on duplicates across groups. Deduplicate input indices or guard against duplicates to avoid an unexpected IllegalArgumentException on legitimate caller input.
Map<QueryBuilder, Set<String>> indicesByRestriction = new LinkedHashMap<>();
Set<String> unrestrictedIndices = new LinkedHashSet<>();
+Set<String> seen = new LinkedHashSet<>();
for (String index : context.concreteIndices()) {
+ if (seen.add(index) == false) {+ continue;+ }
DlsRestriction restriction = baseContext.config().getDocumentPrivileges().getRestriction(privilegesContext, index);
if (restriction.isUnrestricted()) {
unrestrictedIndices.add(index);
} else {
QueryBuilder query = combine(restriction.getQueries());
indicesByRestriction.computeIfAbsent(query, ignored -> new LinkedHashSet<>()).add(index);
}
}
Suggestion importance[1-10]: 5
__
Why: Valid edge case: duplicate indices in context.concreteIndices() could cause ReadAccessPolicyImpl to throw IllegalArgumentException since addGroup fails on duplicate index entries. Moderate impact as duplicates may not be common but could occur.
Low
Fix hasRestrictions computation accuracy
hasRestrictions is set to true whenever the input map is non-empty, but a key may map to an empty collection of indices, in which case no actual restriction is applied to any index. Compute hasRestrictions based on whether any group with a restriction was actually added, to prevent reporting restrictions that are not enforced.
Why: The suggestion addresses a minor edge case where the input map has keys mapping to empty collections. The impact is limited since callers typically don't pass empty value collections, but the improvement makes the computation more semantically accurate.
Using a QueryBuilder as a Map key relies on equals/hashCode, which many QueryBuilder subclasses (e.g., BoolQueryBuilder built from multiple role queries) do implement, but the combine method creates a new BoolQueryBuilder per index even for identical inputs. Two indices with the same set of role queries will produce two BoolQueryBuilder instances that must be equal to be grouped — verify equality holds, or group by the underlying List (or its rendered-string form) before combining to guarantee grouping works as tested.
-Map<QueryBuilder, Set<String>> indicesByRestriction = new LinkedHashMap<>();+Map<List<DocumentPrivileges.RenderedDlsQuery>, Set<String>> indicesByRestrictionKey = new LinkedHashMap<>();+Map<List<DocumentPrivileges.RenderedDlsQuery>, QueryBuilder> combinedByKey = new LinkedHashMap<>();
Set<String> unrestrictedIndices = new LinkedHashSet<>();
for (String index : context.concreteIndices()) {
DlsRestriction restriction = baseContext.config().getDocumentPrivileges().getRestriction(privilegesContext, index);
if (restriction.isUnrestricted()) {
unrestrictedIndices.add(index);
} else {
- QueryBuilder query = combine(restriction.getQueries());- indicesByRestriction.computeIfAbsent(query, ignored -> new LinkedHashSet<>()).add(index);+ List<DocumentPrivileges.RenderedDlsQuery> key = restriction.getQueries();+ combinedByKey.computeIfAbsent(key, k -> combine(k));+ indicesByRestrictionKey.computeIfAbsent(key, ignored -> new LinkedHashSet<>()).add(index);
}
}
+Map<QueryBuilder, Set<String>> indicesByRestriction = new LinkedHashMap<>();+indicesByRestrictionKey.forEach((k, v) -> indicesByRestriction.put(combinedByKey.get(k), v));
Suggestion importance[1-10]: 6
__
Why: The concern is valid: using freshly-constructed BoolQueryBuilder instances as map keys depends on equals/hashCode being properly implemented across subclasses. The test groupsIndicesWithEqualRestrictions passes only because QueryBuilder.equals is implemented, but the suggestion improves robustness by using a more explicit grouping key.
Low
Mirror super call in serialization
The writeTo method does not call super.writeTo(out), but the matching constructor calls super(in). While ActionResponse.writeTo is typically a no-op, the asymmetry is inconsistent with the request class in the same file which correctly calls super.writeTo(out). Add the super call for symmetry and future-proofing.
It should already be the complete implementation. I left it in draft state, because we have to coordinate merging on the core and security side (at the moment compilation fails because it is missing the new interfaces introduced in core).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds logical-plan DLS enforcement for analytics queries according to RFC spec in #22756 .
This implements the security plugin side of the core PR opensearch-project/OpenSearch#23168 .
It mostly boils down to exposing DLS rules via the
AccessPolicyProviderPlugininterface.Testing
match_none), combined role queries, grouped restrictions, and overlapping-group rejection.ReadAccessPolicyService. They verify the actual Security provider returns the expected restriction for a DLS user and no restriction for an unrestricted user.AccessPolicyProviderPluginto validate analytics enforcement independently of the Security plugin.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.