-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 the deprecated Authentication#getSourceRealm method #92222
Remove the deprecated Authentication#getSourceRealm method #92222
Conversation
This PR removes the deprecated Authentication#getSourceRealm method. Its usage is mostly replaced by #getEffectiveSubject#getRealm except for ApiKeyService#getCreatorRealmName and ApiKeyService#getCreatorRealmType which has a special handling to return authenticatingSubject's realm when run-as lookup fails. This is to maintain BWC since these information is used in audit logs. Therefore, even it is technically incorrect, we should not break it without careful planning.
Pinging @elastic/es-security (Team:Security) |
* | ||
* The authentication is consisted of two {@link Subject}s | ||
* <ul> | ||
* <li>{@link #authenticatingSubject}</li> performs the authentication, i.e. it provides a credential.</li> | ||
* <li>{@link #effectiveSubject} The subject that {@link #authenticatingSubject} impersonates ({@link #isRunAs()})</li> | ||
* </ul> | ||
* If {@link #isRunAs()} is {@code false}, the two {@link Subject}s will be the same object. | ||
* | ||
* Authentication also has a {@link #type} that tells which mechanism the {@link #authenticatingSubject} | ||
* uses to perform the authentication. | ||
* | ||
* The Authentication's version is its {@link Subject}'s version, i.e. {@code getEffectiveSubject().getVersion()}. | ||
* It is guaranteed that the versions are identical for the two Subjects. Hence {@code getAuthenticatingSubject().getVersion()} | ||
* will give out the same result. But using {@code getEffectiveSubject()} is more idiomatic since most callers | ||
* of this class should just need to know about the {@link #effectiveSubject}. That is, often times, the caller | ||
* begins with {@code authentication.getEffectiveSubject()} for interrogating an Authentication object. |
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.
Added some more javadoc as discussed in #91067 (comment)
if (isAssignedToDomain() && false == newAuthentication.isAssignedToDomain()) { | ||
logger.info("Rewriting authentication [" + this + "] without domain"); | ||
} |
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.
Relocated this logging inside the RealmRef itself which I think is a better location and also get rid of the usages of isAssignedToDomain
public @Nullable RealmDomain getDomain() { | ||
return getSourceRealm().getDomain(); | ||
@Nullable | ||
RealmDomain getDomain() { |
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.
I changed this method (also isAssignedToDomain
) to package private because:
- It is not really used in production code
- I am not sure whether we want them. Since we removed
getRealm
method from Authentication, having agetDomain
feels going backwards.
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.
Agreed that it doesn't make sense to expose either of the domain methods beyond tests.
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!
...ck/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Authentication.java
Outdated
Show resolved
Hide resolved
...ck/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Authentication.java
Outdated
Show resolved
Hide resolved
...ck/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Authentication.java
Outdated
Show resolved
Hide resolved
public @Nullable RealmDomain getDomain() { | ||
return getSourceRealm().getDomain(); | ||
@Nullable | ||
RealmDomain getDomain() { |
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.
Agreed that it doesn't make sense to expose either of the domain methods beyond tests.
@@ -40,30 +40,6 @@ | |||
|
|||
public class AuthenticationTests extends ESTestCase { | |||
|
|||
public void testWillGetLookedUpByWhenItExists() { |
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.
Optional: would cover isFailedRunAs
here
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 point! I adapted the tests for isFailedRunAs
. Also added new assertions in ApiKeyServiceTests to ensure the behaviours of getCreatorRealmName
and getCreatorRealmType
do not change.
Co-authored-by: Nikolaj Volgushev <n1v0lg@users.noreply.github.com>
@elasticmachine update branch |
CI failure is unrelated and already tracked at #91800 |
…-get-source-realm
This PR removes the deprecated Authentication#getSourceRealm method. Its usage is mostly replaced by #getEffectiveSubject#getRealm except for ApiKeyService#getCreatorRealmName and ApiKeyService#getCreatorRealmType which has a special handling to return authenticatingSubject's realm when run-as lookup fails. This is to maintain BWC since these information is used in audit logs. Therefore, even it is technically incorrect, we should not break it without careful planning.
Relates: #88494