Skip to content

Commit afbcaff

Browse files
ankit--sethin1v0lgslobodanadamovicelasticsearchmachine
authored
Feature/prevent create api with cloud api key (#129966)
* [UIAM] Cloud API key authentication * Clean up * Nit * Fix more tests * Nit * Fix sig * Fix not * Nit * Authenticator * More * Javadoc * Javadoc * Fix tests * Exception handling * Javadoc * add new transport version * add todo to followup in ES-11961 * test cloud API key authentication serialization * add a validation * fix merge * fix merge * code review feedback + test * Update x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyServiceTests.java Co-authored-by: Slobodan Adamović <[email protected]> * Update x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyServiceTests.java Co-authored-by: Slobodan Adamović <[email protected]> * [CI] Auto commit changes from spotless --------- Co-authored-by: Nikolaj Volgushev <[email protected]> Co-authored-by: Slobodan Adamovic <[email protected]> Co-authored-by: Slobodan Adamović <[email protected]> Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 1585c4b commit afbcaff

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ public void createApiKey(
368368
ensureEnabled();
369369
if (authentication == null) {
370370
listener.onFailure(new IllegalArgumentException("authentication must be provided"));
371+
} else if (authentication.isCloudApiKey()) {
372+
listener.onFailure(new IllegalArgumentException("creating elasticsearch api keys using cloud api keys is not supported"));
371373
} else {
372374
final TransportVersion transportVersion = getMinTransportVersion();
373375
if (validateRoleDescriptorsForMixedCluster(listener, request.getRoleDescriptors(), transportVersion) == false) {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyServiceTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,6 +2557,16 @@ public void testCreationWillFailIfHashingThreadPoolIsSaturated() {
25572557
assertThat(e, is(rejectedExecutionException));
25582558
}
25592559

2560+
public void testCreationFailsIfAuthenticationIsCloudApiKey() throws InterruptedException {
2561+
final Authentication authentication = AuthenticationTestHelper.randomCloudApiKeyAuthentication();
2562+
final CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest(randomAlphaOfLengthBetween(3, 8), null, null);
2563+
ApiKeyService service = createApiKeyService(Settings.EMPTY);
2564+
final PlainActionFuture<CreateApiKeyResponse> future = new PlainActionFuture<>();
2565+
service.createApiKey(authentication, createApiKeyRequest, Set.of(), future);
2566+
final IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, future);
2567+
assertThat(iae.getMessage(), equalTo("creating elasticsearch api keys using cloud api keys is not supported"));
2568+
}
2569+
25602570
public void testCachedApiKeyValidationWillNotBeBlockedByUnCachedApiKey() throws IOException, ExecutionException, InterruptedException {
25612571
final String apiKeyId1 = randomAlphaOfLength(12);
25622572
final String apiKey1 = randomAlphaOfLength(16);

0 commit comments

Comments
 (0)