Skip to content

Commit 1cb97a2

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 0407f1d commit 1cb97a2

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
@@ -102,14 +102,12 @@ public void onPreQueryPhase(SearchContext searchContext) {
102102

103103
void ensureIndicesAccessControlForScrollThreadContext(SearchContext searchContext) {
104104
if (licenseState.isSecurityEnabled() && searchContext.scrollContext() != null) {
105-
IndicesAccessControl scrollIndicesAccessControl =
106-
searchContext.scrollContext().getFromContext(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
107105
IndicesAccessControl threadIndicesAccessControl =
108106
securityContext.getThreadContext().getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
109-
if (scrollIndicesAccessControl != threadIndicesAccessControl) {
110-
throw new ElasticsearchSecurityException("[" + searchContext.id() + "] expected scroll indices access control [" +
111-
scrollIndicesAccessControl.toString() + "] but found [" + threadIndicesAccessControl.toString() + "] in thread " +
112-
"context");
107+
if (null == threadIndicesAccessControl) {
108+
throw new ElasticsearchSecurityException("Unexpected null indices access control for search context [" +
109+
searchContext.id() + "] for request [" + searchContext.request().getDescription() + "] with source [" +
110+
searchContext.source() + "]");
113111
}
114112
}
115113
}
@@ -130,7 +128,7 @@ static void ensureAuthenticatedUserIsSame(Authentication original, Authenticatio
130128
if (original.getUser().isRunAs()) {
131129
if (current.getUser().isRunAs()) {
132130
sameRealmType = original.getLookedUpBy().getType().equals(current.getLookedUpBy().getType());
133-
} else {
131+
} else {
134132
sameRealmType = original.getLookedUpBy().getType().equals(current.getAuthenticatedBy().getType());
135133
}
136134
} else if (current.getUser().isRunAs()) {

0 commit comments

Comments
 (0)