Skip to content

[Backport] Fix identification of action type in error message #68426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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