Skip to content

Conversation

@ywangd
Copy link
Member

@ywangd ywangd commented Oct 25, 2022

This PR removes the deprecated Authentication#getAuthenticatedBy method and replaces its usages with #getAuthenticatingSubject#getRealm

Relates: #88494

This PR removes the deprecated Authentication#getAuthenticatedBy method
and replaces its usages with #getAuthenticatingSubject#getRealm

Relates: elastic#88494
@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v8.6.0 labels Oct 25, 2022
Comment on lines +1516 to +1519
} else if (clientAuthentication.getAuthenticatingSubject()
.getRealm()
.getName()
.equals(refreshToken.getAssociatedRealm()) == false) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is inconsistent, i.e. it first checks effective user but then checks authenticating realm. But it is an existing bug (the token was created by capturing effective user + authenticating realm). So this is kept as is. Also it does not really matter much in practice because we now capture full authentication object for new tokens and these logics are not really used much.

public SamlAuthenticateResponse(Authentication authentication, String tokenString, String refreshToken, TimeValue expiresIn) {
this.principal = authentication.getEffectiveSubject().getUser().principal();
this.realm = authentication.getAuthenticatedBy().getName();
this.realm = authentication.getEffectiveSubject().getRealm().getName();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technically should be effectiveSubject. So I changed it be so. In practice, it does not matter because SAML realm authentication cannot have run-as. I add such assertion in other places (closer to where authentication is created).

final String token = request.getToken();
tokenService.getAuthenticationAndMetadata(token, ActionListener.wrap(tuple -> {
final Authentication authentication = tuple.v1();
assert false == authentication.isRunAs() : "oidc realm authentication cannot have run-as";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, oidc realm authentication cannot have run-as either.

Comment on lines -89 to +90
final Realm realm = this.realms.realm(authentication.getAuthenticatedBy().getName());
final Realm realm = this.realms.realm(authentication.getEffectiveSubject().getRealm().getName());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the other two places in this file are the same stroy as the saml realm authentication.

return;
}
assert authentication != null : "authentication should never be null at this point";
assert false == authentication.isRunAs() : "saml realm authentication cannot have run-as";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertion for saml realm not having run-as.

Comment on lines -137 to +140
final Authentication.RealmRef ref = authentication.getAuthenticatedBy();
final Authentication.RealmRef ref = authentication.getEffectiveSubject().getRealm();
if (ref == null || Strings.isNullOrEmpty(ref.getName())) {
throw SamlUtils.samlException("Authentication {} has no authenticating realm", authentication);
throw SamlUtils.samlException("Authentication {} has no effective realm", authentication);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here as well.

Comment on lines -217 to +218
token.getDelegateeAuthentication().getAuthenticatedBy().getName()
// TODO: this should be the realm of effective subject
token.getDelegateeAuthentication().getAuthenticatingSubject().getRealm().getName()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug. I'll have a separate PR just for it so it is not blended in a pure refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Happy to review that one, too.

@ywangd ywangd added >refactoring :Security/Security Security issues without another label and removed needs:triage Requires assignment of a team area label labels Oct 25, 2022
@ywangd ywangd requested a review from n1v0lg October 25, 2022 08:19
@elasticsearchmachine elasticsearchmachine added the Team:Security Meta label for security team label Oct 25, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

Copy link
Contributor

@n1v0lg n1v0lg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines -217 to +218
token.getDelegateeAuthentication().getAuthenticatedBy().getName()
// TODO: this should be the realm of effective subject
token.getDelegateeAuthentication().getAuthenticatingSubject().getRealm().getName()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Happy to review that one, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>refactoring :Security/Security Security issues without another label Team:Security Meta label for security team v8.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants