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

Remove deprecated Authentication#getAuthenticatedBy #91104

Merged
merged 2 commits into from
Oct 25, 2022

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.

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).

@@ -66,6 +66,7 @@ protected void doExecute(Task task, OpenIdConnectLogoutRequest request, ActionLi
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.

@@ -69,6 +69,7 @@ protected void doExecute(Task task, SamlAuthenticateRequest request, ActionListe
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