Skip to content

Commit 532e8ff

Browse files
make run-as unsupported for cloud api keys
1 parent 3e4099c commit 532e8ff

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ public boolean supportsRunAs(@Nullable AnonymousUser anonymousUser) {
571571
return false;
572572
}
573573

574+
// We may allow cloud API keys to run-as in the future, but for now there is no requirement
575+
if (isCloudApiKey()) {
576+
return false;
577+
}
578+
574579
// There is no reason for internal users to run-as. This check prevents either internal user itself
575580
// or a token created for it (though no such thing in current code) to run-as.
576581
if (getEffectiveSubject().getUser() instanceof InternalUser) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ public static String randomInternalRoleName() {
244244
);
245245
}
246246

247+
public static Authentication randomCloudApiKeyAuthentication() {
248+
return randomCloudApiKeyAuthentication(null, null);
249+
}
250+
247251
public static Authentication randomCloudApiKeyAuthentication(String apiKeyId) {
248252
return randomCloudApiKeyAuthentication(null, apiKeyId);
249253
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@ public void testSupportsRunAs() {
768768

769769
// Remote access cannot run-as
770770
assertThat(AuthenticationTestHelper.builder().crossClusterAccess().build().supportsRunAs(anonymousUser), is(false));
771+
772+
// Cloud API key cannot run-as
773+
assertThat(AuthenticationTestHelper.randomCloudApiKeyAuthentication().supportsRunAs(anonymousUser), is(false));
771774
}
772775

773776
private void assertCanAccessResources(Authentication authentication0, Authentication authentication1) {

0 commit comments

Comments
 (0)