-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Conversation
This PR removes the deprecated Authentication#getAuthenticatedBy method and replaces its usages with #getAuthenticatingSubject#getRealm Relates: elastic#88494
} else if (clientAuthentication.getAuthenticatingSubject() | ||
.getRealm() | ||
.getName() | ||
.equals(refreshToken.getAssociatedRealm()) == false) { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
final Realm realm = this.realms.realm(authentication.getAuthenticatedBy().getName()); | ||
final Realm realm = this.realms.realm(authentication.getEffectiveSubject().getRealm().getName()); |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here as well.
token.getDelegateeAuthentication().getAuthenticatedBy().getName() | ||
// TODO: this should be the realm of effective subject | ||
token.getDelegateeAuthentication().getAuthenticatingSubject().getRealm().getName() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Pinging @elastic/es-security (Team:Security) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
token.getDelegateeAuthentication().getAuthenticatedBy().getName() | ||
// TODO: this should be the realm of effective subject | ||
token.getDelegateeAuthentication().getAuthenticatingSubject().getRealm().getName() |
There was a problem hiding this comment.
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.
This PR removes the deprecated Authentication#getAuthenticatedBy method and replaces its usages with #getAuthenticatingSubject#getRealm
Relates: #88494