Skip to content

Commit ebaa1ca

Browse files
committed
[Test] provide role descriptors for API key creation
The role descriptors became optional since version 7.3.0. For earlier versions, they must be specified. This PR specifies them conditionally based on the old cluster version. This also serves a variation of the test to show that dropping write access to system indices from the limiting role will prevent the key from writing to system indices as a whole. Resolves: elastic#82785
1 parent 60a260d commit ebaa1ca

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,29 @@ public void testApiKeySuperuser() throws IOException {
353353
)
354354
)
355355
);
356-
createApiKeyRequest.setJsonEntity("""
357-
{
358-
"name": "super_legacy_key"
359-
}""");
356+
if (getOldClusterVersion().onOrAfter(Version.V_7_3_0)) {
357+
createApiKeyRequest.setJsonEntity("""
358+
{
359+
"name": "super_legacy_key"
360+
}""");
361+
} else {
362+
createApiKeyRequest.setJsonEntity("""
363+
{
364+
"name": "super_legacy_key",
365+
"role_descriptors": {
366+
"super": {
367+
"cluster": [ "all" ],
368+
"indices": [
369+
{
370+
"names": [ "*" ],
371+
"privileges": [ "all" ],
372+
"allow_restricted_indices": true
373+
}
374+
]
375+
}
376+
}
377+
}""");
378+
}
360379
final Map<String, Object> createApiKeyResponse = entityAsMap(client().performRequest(createApiKeyRequest));
361380
final byte[] keyBytes = (createApiKeyResponse.get("id") + ":" + createApiKeyResponse.get("api_key")).getBytes(
362381
StandardCharsets.UTF_8

0 commit comments

Comments
 (0)