Skip to content

Commit 4bd853a

Browse files
authored
Add "grant_api_key" cluster privilege (#54042)
This change adds a new cluster privilege "grant_api_key" that allows the use of the new /_security/api_key/grant endpoint Backport of: #53527
1 parent 9e3f7f4 commit 4bd853a

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

x-pack/docs/en/rest-api/security/get-builtin-privileges.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ A successful call returns an object with "cluster" and "index" fields.
6464
"all",
6565
"create_snapshot",
6666
"delegate_pki",
67+
"grant_api_key",
6768
"manage",
6869
"manage_api_key",
6970
"manage_autoscaling",

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.xpack.core.ilm.action.StartILMAction;
2323
import org.elasticsearch.xpack.core.ilm.action.StopILMAction;
2424
import org.elasticsearch.xpack.core.security.action.DelegatePkiAuthenticationAction;
25+
import org.elasticsearch.xpack.core.security.action.GrantApiKeyAction;
2526
import org.elasticsearch.xpack.core.security.action.token.InvalidateTokenAction;
2627
import org.elasticsearch.xpack.core.security.action.token.RefreshTokenAction;
2728
import org.elasticsearch.xpack.core.security.action.user.HasPrivilegesAction;
@@ -49,6 +50,7 @@ public class ClusterPrivilegeResolver {
4950
private static final Set<String> MANAGE_OIDC_PATTERN = Collections.singleton("cluster:admin/xpack/security/oidc/*");
5051
private static final Set<String> MANAGE_TOKEN_PATTERN = Collections.singleton("cluster:admin/xpack/security/token/*");
5152
private static final Set<String> MANAGE_API_KEY_PATTERN = Collections.singleton("cluster:admin/xpack/security/api_key/*");
53+
private static final Set<String> GRANT_API_KEY_PATTERN = Collections.singleton(GrantApiKeyAction.NAME + "*");
5254
private static final Set<String> MONITOR_PATTERN = Collections.singleton("cluster:monitor/*");
5355
private static final Set<String> MONITOR_TRANSFORM_PATTERN = Collections.unmodifiableSet(
5456
Sets.newHashSet("cluster:monitor/data_frame/*", "cluster:monitor/transform/*"));
@@ -118,6 +120,7 @@ public class ClusterPrivilegeResolver {
118120
public static final NamedClusterPrivilege MANAGE_SAML = new ActionClusterPrivilege("manage_saml", MANAGE_SAML_PATTERN);
119121
public static final NamedClusterPrivilege MANAGE_OIDC = new ActionClusterPrivilege("manage_oidc", MANAGE_OIDC_PATTERN);
120122
public static final NamedClusterPrivilege MANAGE_API_KEY = new ActionClusterPrivilege("manage_api_key", MANAGE_API_KEY_PATTERN);
123+
public static final NamedClusterPrivilege GRANT_API_KEY = new ActionClusterPrivilege("grant_api_key", GRANT_API_KEY_PATTERN);
121124
public static final NamedClusterPrivilege MANAGE_PIPELINE = new ActionClusterPrivilege("manage_pipeline",
122125
Collections.singleton("cluster:admin/ingest/pipeline/*"));
123126
public static final NamedClusterPrivilege MANAGE_AUTOSCALING = new ActionClusterPrivilege(
@@ -160,6 +163,7 @@ public class ClusterPrivilegeResolver {
160163
MANAGE_SAML,
161164
MANAGE_OIDC,
162165
MANAGE_API_KEY,
166+
GRANT_API_KEY,
163167
MANAGE_PIPELINE,
164168
MANAGE_ROLLUP,
165169
MANAGE_AUTOSCALING,

x-pack/plugin/security/qa/security-trial/src/test/java/org/elasticsearch/xpack/security/apikey/ApiKeyRestIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class ApiKeyRestIT extends SecurityOnTrialLicenseRestTestCase {
4747
@Before
4848
public void createUsers() throws IOException {
4949
createUser(SYSTEM_USER, SYSTEM_USER_PASSWORD, Collections.singletonList("system_role"));
50-
createRole("system_role", Collections.singleton("manage_api_key"));
50+
createRole("system_role", Collections.singleton("grant_api_key"));
5151
createUser(END_USER, END_USER_PASSWORD, Collections.singletonList("user_role"));
5252
createRole("user_role", Collections.singleton("monitor"));
5353
}

x-pack/plugin/src/test/resources/rest-api-spec/test/privileges/11_builtin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ setup:
1515
# This is fragile - it needs to be updated every time we add a new cluster/index privilege
1616
# I would much prefer we could just check that specific entries are in the array, but we don't have
1717
# an assertion for that
18-
- length: { "cluster" : 35 }
18+
- length: { "cluster" : 36 }
1919
- length: { "index" : 18 }

0 commit comments

Comments
 (0)