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.
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.
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.
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
getRealmmethod from Authentication, having agetDomainfeels going backwards.
There was a problem hiding this comment.
Agreed that it doesn't make sense to expose either of the domain methods beyond tests.
...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.
Agreed that it doesn't make sense to expose either of the domain methods beyond tests.
|
|
||
| public class AuthenticationTests extends ESTestCase { | ||
|
|
||
| public void testWillGetLookedUpByWhenItExists() { |
There was a problem hiding this comment.
Optional: would cover isFailedRunAs here
There was a problem hiding this comment.
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