Skip to content

Commit 359789c

Browse files
committed
Fix
1 parent bd84c31 commit 359789c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,29 @@ public String actionDenied(
100100
}
101101
} else if (isIndexAction(action)) {
102102
String[] indices = AuthorizationEngine.RequestInfo.indices(request);
103+
if (indices == null || indices.length == 0) {
104+
final Collection<String> privileges = findIndexPrivilegesThatGrant(action, IndexComponentSelector.DATA);
105+
if (privileges != null && false == privileges.isEmpty()) {
106+
message = message
107+
+ ", this action is granted by the index privileges ["
108+
+ collectionToCommaDelimitedString(privileges)
109+
+ "]";
110+
}
111+
return message;
112+
}
103113
boolean hasFailuresSelector = false;
104114
boolean hasNullOrDataSelector = false;
105-
if (indices != null) {
106-
for (String index : indices) {
107-
if (IndexNameExpressionResolver.hasSelector(index, IndexComponentSelector.FAILURES)) {
108-
hasFailuresSelector = true;
109-
} else {
110-
hasNullOrDataSelector = true;
111-
}
112-
// we found both selectors, we can stop
113-
if (hasNullOrDataSelector && hasFailuresSelector) {
114-
break;
115-
}
115+
for (String index : indices) {
116+
if (IndexNameExpressionResolver.hasSelector(index, IndexComponentSelector.FAILURES)) {
117+
hasFailuresSelector = true;
118+
} else {
119+
hasNullOrDataSelector = true;
120+
}
121+
// we found both selectors, we can stop
122+
if (hasNullOrDataSelector && hasFailuresSelector) {
123+
break;
116124
}
117125
}
118-
119126
if (hasNullOrDataSelector) {
120127
final Collection<String> privileges = findIndexPrivilegesThatGrant(action, IndexComponentSelector.DATA);
121128
if (privileges != null && false == privileges.isEmpty()) {
@@ -132,7 +139,7 @@ public String actionDenied(
132139
message = message
133140
+ " for data access, or ["
134141
+ collectionToCommaDelimitedString(privileges)
135-
+ "] for access with the failures selector";
142+
+ "] for access via the failures selector";
136143
} else {
137144
message = message
138145
+ ", this action is granted by the index privileges ["
@@ -141,7 +148,6 @@ public String actionDenied(
141148
}
142149
}
143150
}
144-
145151
}
146152

147153
return message;

0 commit comments

Comments
 (0)