Skip to content

Commit 3e4099c

Browse files
improve authorization denial messages for cloud API keys
1 parent 1455346 commit 3e4099c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ private boolean hasIndicesWithFailuresSelector(TransportRequest request) {
182182
}
183183

184184
private String authenticatedUserDescription(Authentication authentication) {
185-
String userText = (authentication.isServiceAccount() ? "service account" : "user")
186-
+ " ["
187-
+ authentication.getAuthenticatingSubject().getUser().principal()
188-
+ "]";
185+
String userText = (authentication.isServiceAccount() ? "service account"
186+
: authentication.isCloudApiKey() ? "cloud API key"
187+
: "user") + " [" + authentication.getAuthenticatingSubject().getUser().principal() + "]";
189188
if (authentication.isAuthenticatedAsApiKey() || authentication.isCrossClusterAccess()) {
190189
final String apiKeyId = (String) authentication.getAuthenticatingSubject()
191190
.getMetadata()
@@ -208,7 +207,7 @@ private String authenticatedUserDescription(Authentication authentication) {
208207
// package-private for tests
209208
String rolesDescription(Subject subject, @Nullable AuthorizationEngine.AuthorizationInfo authorizationInfo) {
210209
// We cannot print the roles if it's an API key or a service account (both do not have roles, but privileges)
211-
if (subject.getType() != Subject.Type.USER) {
210+
if (subject.getType() != Subject.Type.USER && subject.getType() != Subject.Type.CLOUD_API_KEY) {
212211
return "";
213212
}
214213

0 commit comments

Comments
 (0)