Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure PKI's delegated_by_realm metadata respect run-as (#91173) #91241

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/91173.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 91173
summary: Ensure PKI's `delegated_by_realm` metadata respect run-as
area: Authentication
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void buildUser(X509AuthenticationToken token, String principal, ActionLi
"pki_delegated_by_user",
token.getDelegateeAuthentication().getUser().principal(),
"pki_delegated_by_realm",
token.getDelegateeAuthentication().getAuthenticatedBy().getName()
token.getDelegateeAuthentication().getEffectiveSubject().getRealm().getName()
);
} else {
metadata = Map.of("pki_dn", token.dn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,26 @@ public void testAuthenticationDelegationSuccess() throws Exception {
assertThat(result.getValue().roles().length, is(0));
assertThat(result.getValue().metadata().get("pki_delegated_by_user"), is("mockup_delegate_username"));
assertThat(result.getValue().metadata().get("pki_delegated_by_realm"), is("mockup_delegate_realm"));

// Delegatee is run-as
final Authentication runAsAuthentication = AuthenticationTestHelper.builder().realm().build(true);
assertThat(runAsAuthentication.isRunAs(), is(true));
delegatedToken = X509AuthenticationToken.delegated(new X509Certificate[] { certificate }, runAsAuthentication);
realmWithDelegation.expireAll(); // clear the cache so the user is built again
result = authenticate(delegatedToken, realmWithDelegation);
assertThat(result.getStatus(), equalTo(AuthenticationResult.Status.SUCCESS));
assertThat(result.getValue(), is(notNullValue()));
assertThat(result.getValue().principal(), is("Elasticsearch Test Node"));
assertThat(result.getValue().roles(), is(notNullValue()));
assertThat(result.getValue().roles().length, is(0));
assertThat(
result.getValue().metadata().get("pki_delegated_by_user"),
is(runAsAuthentication.getEffectiveSubject().getUser().principal())
);
assertThat(
result.getValue().metadata().get("pki_delegated_by_realm"),
is(runAsAuthentication.getEffectiveSubject().getRealm().getName())
);
}

public void testAuthenticationDelegationFailure() throws Exception {
Expand Down