-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Merge AuthenticationContex into Authentication #85255
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
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.
|
Pinging @elastic/es-security (Team:Security) |
| } else { | ||
| authenticatingSubject = effectiveSubject = new Subject(user, authenticatedBy, version, metadata); | ||
| } | ||
| } |
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.
Are we sure this method doesn't need to be thread-safe (because it's not).
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.
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
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
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 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.