Merge AuthenticationContex into Authentication#85255
Merged
ywangd merged 8 commits intoelastic:masterfrom Apr 26, 2022
Merged
Conversation
This PR removes the AuthenticationContext class introduced in elastic#80926 and merges its functions into Authentication. It becomes more apparent that the most useful refactoring in elastic#80926 is the new Subject class, which is also what AuthenticationContext provides most of its value. The AuthenticationContext is essentially just a thin wrapper of two subjects which represents the existing Authentication object in a more structured format. The original plan was to replace Authentication with AuthenticationContext. However, it has practical challenges that the usage of Authentication is too wide spread. It's hard to have a series of scoped changes to replace it. Therefore the new plan is to stick with Authentication, agumenting it with subjects similar to what AuthenticationContext has and remove AuthenticationContext. This PR also deprecates methods that should be replaced by methods of Subjects. In future, the plan is to remove the deprecated methods, also rework the User class so it does not need nest another User to represent run-as (which is another main reason for the original refactor elastic#80926). Overall, the new plan makes it easier to spread the work in a few more tightly scoped PRs while achieving the same original goal.
Collaborator
|
Pinging @elastic/es-security (Team:Security) |
tvernum
reviewed
Apr 26, 2022
| } else { | ||
| authenticatingSubject = effectiveSubject = new Subject(user, authenticatedBy, version, metadata); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Are we sure this method doesn't need to be thread-safe (because it's not).
Member
Author
There was a problem hiding this comment.
On a second thought, this method needs to be thread-safe because it's setting two variables so inherently not atomic.
Taking a step back, I was trying to save some computation by delay the initialising the subjects. But I think the save here is too marginal. Introducing a synchornisation is likely to defeat the purpose. So I just inlined it into the constructors.
...ck/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Authentication.java
Outdated
Show resolved
Hide resolved
a278de5 to
6ec1809
Compare
tvernum
approved these changes
Apr 26, 2022
ywangd
added a commit
to ywangd/elasticsearch
that referenced
this pull request
Apr 26, 2022
In elastic#85255, some mocking of Authentication class got replaced by randomly creating actual Authentication objects. This is a general direction we want to head towards because Authentication object has plenty internal logics which makes it hard to mock correctly (and also undesirable). The recent change in elastic#85590 adds a test helper which makes randomising Authentication object easier for tests. For ApiKeyServiceTests.testGetApiKeyMetadata, the randomisation is however too broad (broader then what the mocking provided) and can sometimes creates authentication object that does not pass the assertion. The assertion expects no API key authentication. But the randomisation can generate such one because it randomises whether the authentication has run-as even when the effective user is from a realm. Since API keys can run-as, the resulted Authentication object can be an overall API key authentication object. This PR reduces the randomness by not allow run-as so that the resulted Authentication cannot be API keys. Relates: elastic#85255 Resolves: elastic#86179
ywangd
added a commit
that referenced
this pull request
Apr 26, 2022
In #85255, some mocking of Authentication class got replaced by randomly creating actual Authentication objects. This is a general direction we want to head towards because Authentication object has plenty internal logics which makes it hard to mock correctly (and also undesirable). The recent change in #85590 adds a test helper which makes randomising Authentication object easier for tests. For ApiKeyServiceTests.testGetApiKeyMetadata, the randomisation is however too broad (broader then what the mocking provided) and can sometimes creates authentication object that does not pass the assertion. The assertion expects no API key authentication. But the randomisation can generate such one because it randomises whether the authentication has run-as even when the effective user is from a realm. Since API keys can run-as, the resulted Authentication object can be an overall API key authentication object. This PR reduces the randomness by not allow run-as so that the resulted Authentication cannot be API keys. Relates: #85255 Resolves: #86179
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR removes the AuthenticationContext class introduced in #80926 and
merges its functions into Authentication.
It becomes more apparent that the most useful refactoring in #80926 is
the new Subject class, which is also what AuthenticationContext provides
most of its value. The AuthenticationContext is essentially just a thin
wrapper of two subjects which represents the existing Authentication
object in a more structured format. The original plan was to replace
Authentication with AuthenticationContext. However, it has practical
challenges that the usage of Authentication is too wide spread. It's
hard to have a series of scoped changes to replace it. Therefore the new
plan is to stick with Authentication, agumenting it with subjects
similar to what AuthenticationContext has and remove
AuthenticationContext. This PR also deprecates methods that should be
replaced by methods of Subjects. In future, the plan is to remove the
deprecated methods, also rework the User class so it does not need
nest another User to represent run-as (which is another main reason for
the original refactor #80926). Overall, the new plan makes it easier to
spread the work in a few more tightly scoped PRs while achieving the
same original goal.