Skip to content

Commit 00aecf8

Browse files
Revert "Relax the index access control check for scroll searches (#61446)"
This reverts commit 9a42f3f.
1 parent 9a42f3f commit 00aecf8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ 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);
99101
IndicesAccessControl threadIndicesAccessControl =
100102
threadContext.getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
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() + "]");
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");
105107
}
106108
}
107109
}
@@ -122,7 +124,7 @@ static void ensureAuthenticatedUserIsSame(Authentication original, Authenticatio
122124
if (original.getUser().isRunAs()) {
123125
if (current.getUser().isRunAs()) {
124126
sameRealmType = original.getLookedUpBy().getType().equals(current.getLookedUpBy().getType());
125-
} else {
127+
} else {
126128
sameRealmType = original.getLookedUpBy().getType().equals(current.getAuthenticatedBy().getType());
127129
}
128130
} else if (current.getUser().isRunAs()) {

0 commit comments

Comments
 (0)