Skip to content

Commit 0df30be

Browse files
committed
CCS fix
Signed-off-by: Nils Bandener <nils.bandener@eliatra.com>
1 parent b0d0997 commit 0df30be

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/main/java/org/opensearch/security/privileges/actionlevel/nextgen/PrivilegesEvaluator.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -413,25 +413,33 @@ PrivilegesEvaluatorResponse checkIndexPermissionBasic(
413413
}
414414
}
415415
} else if (!presponse.isAllowed()) {
416-
// If the user has no privileges, there are certain conditions where we return an empty result instead of a 403 error
417-
// These are:
418-
// - The action supports it
419-
// - The index expression contains a pattern expression or ignore_unavailable is true
420-
// - The user has privileges for the given actions on some indices
421-
422-
if (isIndexReductionForNoPrivilegesPossible(request) && optionallyResolvedIndices instanceof ResolvedIndices resolvedIndices) {
423-
// We only allow returning empty results if the current user has at least the necessary privileges for any index
424-
PrivilegesEvaluatorResponse allowedForAnyIndex = actionPrivileges.hasIndexPrivilegeForAnyIndex(
425-
context,
426-
requiredIndexPermissions
427-
);
428-
429-
if (allowedForAnyIndex.isAllowed() && this.indicesRequestModifier.setLocalIndicesToEmpty(request, resolvedIndices)) {
430-
return PrivilegesEvaluatorResponse.ok()
431-
.reason("Not allowed for any indices; returning empty result")
432-
.originalResult(presponse);
416+
417+
if (isIndexReductionForIncompletePrivilegesPossible(request)
418+
&& optionallyResolvedIndices instanceof ResolvedIndices resolvedIndices
419+
&& !resolvedIndices.remote().isEmpty()) {
420+
// If remote indices are requested, we reduce to these and let the request pass
421+
if (this.indicesRequestModifier.setLocalIndicesToEmpty(request, resolvedIndices)) {
422+
return PrivilegesEvaluatorResponse.ok().reason("Only allowed for remote indices").originalResult(presponse);
423+
}
424+
} else if (isIndexReductionForNoPrivilegesPossible(request)
425+
&& optionallyResolvedIndices instanceof ResolvedIndices resolvedIndices) {
426+
// If the user has no privileges, there are certain conditions where we return an empty result instead of a 403 error
427+
// These are:
428+
// - The action supports it
429+
// - The index expression contains a pattern expression or ignore_unavailable is true
430+
// - The user has privileges for the given actions on some indices
431+
432+
PrivilegesEvaluatorResponse allowedForAnyIndex = actionPrivileges.hasIndexPrivilegeForAnyIndex(
433+
context,
434+
requiredIndexPermissions
435+
);
436+
437+
if (allowedForAnyIndex.isAllowed() && this.indicesRequestModifier.setLocalIndicesToEmpty(request, resolvedIndices)) {
438+
return PrivilegesEvaluatorResponse.ok()
439+
.reason("Not allowed for any indices; returning empty result")
440+
.originalResult(presponse);
441+
}
433442
}
434-
}
435443
}
436444

437445
return presponse;

0 commit comments

Comments
 (0)