Skip to content

Commit

Permalink
Fix identification of action type in error message
Browse files Browse the repository at this point in the history
Some actions that start with "indices:" are actually handled by
cluster privileges in ES security (e.g. indices:admin/template/*)
In elastic#60357 and elastic#66900 we added better context information for the
error messages that are generated when an action is denied, but the
generation of that message did not correctly classify actions between
cluster and index level privileges.

This change does 2 things:
1. It fixes the code that determines whether an action is handled by a
   cluster privilege or an index privilege
2. Includes the words "cluster" and "index" in the error message so
   that classification is clear to the reader

The latter change is not directly related to the issue being resolved,
but in the course of fixing the issue it became evident that the
message lacked clarity because it did not tell the reader what type of
privilege would be needed to resolve the access denied issue.

Backport of: elastic#68260
  • Loading branch information
tvernum committed Feb 3, 2021
1 parent 926eb91 commit c3f90ef
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ public void testCanManageIndexWithNoPermissions() throws Exception {
assertThat(indexExplain.get("failed_step"), equalTo("wait-for-shard-history-leases"));
Map<String, String> stepInfo = (Map<String, String>) indexExplain.get("step_info");
assertThat(stepInfo.get("type"), equalTo("security_exception"));
assertThat(stepInfo.get("reason"), equalTo("action [indices:monitor/stats] is unauthorized for user [test_ilm]" +
" on indices [not-ilm], this action is granted by the privileges [monitor,manage,all]"));
assertThat(stepInfo.get("reason"), equalTo("action [indices:monitor/stats] is unauthorized" +
" for user [test_ilm]" +
" on indices [not-ilm]," +
" this action is granted by the index privileges [monitor,manage,all]"));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,14 +1257,14 @@ private Client getClientForRunAsUser() {
private void assertErrorMessage(final ElasticsearchSecurityException ese, String action, String userName, String apiKeyId) {
assertThat(ese, throwableWithMessage(
containsString("action [" + action + "] is unauthorized for API key id [" + apiKeyId + "] of user [" + userName + "]")));
assertThat(ese, throwableWithMessage(containsString(", this action is granted by the privileges [")));
assertThat(ese, throwableWithMessage(containsString(", this action is granted by the cluster privileges [")));
assertThat(ese, throwableWithMessage(containsString("manage_api_key,manage_security,all]")));
}

private void assertErrorMessage(final ElasticsearchSecurityException ese, String action, String userName) {
assertThat(ese, throwableWithMessage(
containsString("action [" + action + "] is unauthorized for user [" + userName + "]")));
assertThat(ese, throwableWithMessage(containsString(", this action is granted by the privileges [")));
assertThat(ese, throwableWithMessage(containsString(", this action is granted by the cluster privileges [")));
assertThat(ese, throwableWithMessage(containsString("manage_api_key,manage_security,all]")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,17 @@ private ElasticsearchSecurityException denialException(Authentication authentica
message = message + " " + context;
}

if (isIndexAction(action)) {
final Collection<String> privileges = IndexPrivilege.findPrivilegesThatGrant(action);
if (ClusterPrivilegeResolver.isClusterAction(action)) {
final Collection<String> privileges = ClusterPrivilegeResolver.findPrivilegesThatGrant(action, request, authentication);
if (privileges != null && privileges.size() > 0) {
message = message + ", this action is granted by the privileges [" + collectionToCommaDelimitedString(privileges) + "]";
message = message + ", this action is granted by the cluster privileges ["
+ collectionToCommaDelimitedString(privileges) + "]";
}
} else if (ClusterPrivilegeResolver.isClusterAction(action)) {
final Collection<String> privileges = ClusterPrivilegeResolver.findPrivilegesThatGrant(action, request, authentication);
} else if (isIndexAction(action)) {
final Collection<String> privileges = IndexPrivilege.findPrivilegesThatGrant(action);
if (privileges != null && privileges.size() > 0) {
message = message + ", this action is granted by the privileges [" + collectionToCommaDelimitedString(privileges) + "]";
message = message + ", this action is granted by the index privileges ["
+ collectionToCommaDelimitedString(privileges) + "]";
}
}

Expand Down
Loading

0 comments on commit c3f90ef

Please sign in to comment.