Skip to content

Commit 1ee3625

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 0501bfd commit 1ee3625

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* A {@link SearchOperationListener} that is used to provide authorization for scroll requests.
32-
*
32+
* <p>
3333
* In order to identify the user associated with a scroll request, we replace the {@link ReaderContext}
3434
* on creation with a custom implementation that holds the {@link Authentication} object. When
3535
* this context is accessed again in {@link SearchOperationListener#onPreQueryPhase(SearchContext)}
@@ -82,7 +82,7 @@ public void validateSearchContext(ReaderContext readerContext, TransportRequest
8282
if (null == securityContext.getThreadContext().getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY)) {
8383
// fill in the DLS and FLS permissions for the scroll search action from the scroll context
8484
IndicesAccessControl scrollIndicesAccessControl =
85-
readerContext.getFromContext(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
85+
readerContext.getFromContext(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
8686
assert scrollIndicesAccessControl != null : "scroll does not contain index access control";
8787
securityContext.getThreadContext().putTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY,
8888
scrollIndicesAccessControl);
@@ -93,24 +93,22 @@ public void validateSearchContext(ReaderContext readerContext, TransportRequest
9393

9494
@Override
9595
public void onPreFetchPhase(SearchContext searchContext) {
96-
ensureIndicesAccessControlForScrollThreadContext(searchContext.readerContext());
96+
ensureIndicesAccessControlForScrollThreadContext(searchContext);
9797
}
9898

9999
@Override
100100
public void onPreQueryPhase(SearchContext searchContext) {
101-
ensureIndicesAccessControlForScrollThreadContext(searchContext.readerContext());
101+
ensureIndicesAccessControlForScrollThreadContext(searchContext);
102102
}
103103

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

0 commit comments

Comments
 (0)