Skip to content

Commit 9a42f3f

Browse files
Relax the index access control check for scroll searches (#61446)
The check introduced by #60640 for scroll searches, in which we log if the index access control before the query and fetch phases differs from when the scroll context is created, is too strict, leading to spurious warning log messages. The check verifies instance equality but this assumes that the fetch phase is executed in the same thread context as the scroll context validation. However, this is not true if the scroll search is executed cross-cluster, and even for local scroll searches it is an unfounded assumption. The check is hence reduced to a null check for the index access. The fact that the access control is suitable given the indices that are actually accessed (by the scroll) will be done in a follow-up, after we better regulate the creation of index access controls in general.
1 parent 88c2a75 commit 9a42f3f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/SecuritySearchOperationListener.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,12 @@ public void onPreQueryPhase(SearchContext searchContext) {
9696

9797
void ensureIndicesAccessControlForScrollThreadContext(SearchContext searchContext) {
9898
if (licenseState.isAuthAllowed() && searchContext.scrollContext() != null) {
99-
IndicesAccessControl scrollIndicesAccessControl =
100-
searchContext.scrollContext().getFromContext(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
10199
IndicesAccessControl threadIndicesAccessControl =
102100
threadContext.getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
103-
if (scrollIndicesAccessControl != threadIndicesAccessControl) {
104-
throw new ElasticsearchSecurityException("[" + searchContext.id() + "] expected scroll indices access control [" +
105-
scrollIndicesAccessControl.toString() + "] but found [" + threadIndicesAccessControl.toString() + "] in thread " +
106-
"context");
101+
if (null == threadIndicesAccessControl) {
102+
throw new ElasticsearchSecurityException("Unexpected null indices access control for search context [" +
103+
searchContext.id() + "] for request [" + searchContext.request().getDescription() + "] with source [" +
104+
searchContext.source() + "]");
107105
}
108106
}
109107
}
@@ -124,7 +122,7 @@ static void ensureAuthenticatedUserIsSame(Authentication original, Authenticatio
124122
if (original.getUser().isRunAs()) {
125123
if (current.getUser().isRunAs()) {
126124
sameRealmType = original.getLookedUpBy().getType().equals(current.getLookedUpBy().getType());
127-
} else {
125+
} else {
128126
sameRealmType = original.getLookedUpBy().getType().equals(current.getAuthenticatedBy().getType());
129127
}
130128
} else if (current.getUser().isRunAs()) {

0 commit comments

Comments
 (0)