-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more context to cluster access denied messages (#66900)
In #60357 we improved the error message when access to perform an action on an index was denied by including the index name and the privileges that would grant the action. This commit extends the second part of that change (the list of privileges that would resolve the problem) to situations when a cluster action is denied. This implementation for cluster privileges is slightly more complex than that of index privileges because cluster privileges can be dependent on parameters in the request, not just the action name. For example, "manage_own_api_key" should be suggested as a matching privilege when a user attempts to create an API key, or delete their own API key, but should not be suggested when that same user attempts to delete another user's API key. Relates: #42166
- Loading branch information
Showing
12 changed files
with
362 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolverTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.authz.privilege; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.SortedMap; | ||
|
||
import static org.hamcrest.Matchers.contains; | ||
|
||
public class ClusterPrivilegeResolverTests extends ESTestCase { | ||
|
||
public void testSortByAccessLevel() throws Exception { | ||
final List<NamedClusterPrivilege> privileges = new ArrayList<>(List.of( | ||
ClusterPrivilegeResolver.ALL, | ||
ClusterPrivilegeResolver.MONITOR, | ||
ClusterPrivilegeResolver.MANAGE, | ||
ClusterPrivilegeResolver.MANAGE_OWN_API_KEY, | ||
ClusterPrivilegeResolver.MANAGE_API_KEY, | ||
ClusterPrivilegeResolver.MANAGE_SECURITY | ||
)); | ||
Collections.shuffle(privileges, random()); | ||
final SortedMap<String, NamedClusterPrivilege> sorted = ClusterPrivilegeResolver.sortByAccessLevel(privileges); | ||
// This is: | ||
// "manage_own_api_key", "monitor" (neither of which grant anything else in the list), sorted by name | ||
// "manage" and "manage_api_key",(which each grant 1 other privilege in the list), sorted by name | ||
// "manage_security" and "all", sorted by access level ("all" implies "manage_security") | ||
assertThat(sorted.keySet(), contains("manage_own_api_key", "monitor", "manage", "manage_api_key", "manage_security", "all")); | ||
} | ||
|
||
} |
Oops, something went wrong.