Skip to content

Commit 27bc0d3

Browse files
committed
In access deny msg, only show indices if resolved
Our authorization engine has a short-circuit check for the intended action the takes place before resolving index names (wildcards). That is, a requests like GET /_search GET /logs-*/_search GET /logs-20210414/_search will fail fast if the user does not have read permission on any indices, and we will never resolve the list of indices that the request targets. Consequently, it is impossible to provide the list of denied indices in the error message because that list does exist (and, in the case of wildards would be empty even if we did resolve it). This change updates the access denied message so that it does not attempt to include the list of indices if the IndiceAccessControl object has an empty list of denied indices. Prior to this, we would generate messages such as action [indices:data/read/search] is unauthorized for user [test] with roles [test] on indices [], That "indices []" section is never useful since it does not name any indices, so it has now been dropped from the message if it is empty. Relates: elastic#42166, elastic#60357
1 parent a642cb3 commit 27bc0d3

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ public String getFailureContext() {
342342
}
343343

344344
public static String getFailureDescription(Collection<?> deniedIndices) {
345+
if (deniedIndices.isEmpty()) {
346+
return null;
347+
}
345348
return "on indices [" + Strings.collectionToCommaDelimitedString(deniedIndices) + "]";
346349
}
347350

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ public void testUnknownRoleCausesDenial() throws IOException {
679679
assertThat(securityException, throwableWithMessage(containsString(
680680
"[" + action + "] is unauthorized" +
681681
" for user [test user]" +
682-
" with roles [non-existent-role]" +
683-
" on indices [")));
682+
" with roles [non-existent-role],")));
684683
assertThat(securityException, throwableWithMessage(containsString("this action is granted by the index privileges [read,all]")));
685684

686685
verify(auditTrail).accessDenied(eq(requestId), eq(authentication), eq(action), eq(request), authzInfoRoles(Role.EMPTY.names()));
@@ -721,8 +720,7 @@ public void testThatRoleWithNoIndicesIsDenied() throws IOException {
721720
assertThat(securityException, throwableWithMessage(containsString(
722721
"[" + action + "] is unauthorized" +
723722
" for user [test user]" +
724-
" with roles [no_indices]" +
725-
" on indices [")));
723+
" with roles [no_indices],")));
726724
assertThat(securityException, throwableWithMessage(containsString("this action is granted by the index privileges [read,all]")));
727725

728726
verify(auditTrail).accessDenied(eq(requestId), eq(authentication), eq(action), eq(request),

0 commit comments

Comments
 (0)