Handle role descriptor retrieval for internal users#85049
Merged
ywangd merged 4 commits intoelastic:masterfrom Mar 18, 2022
Merged
Handle role descriptor retrieval for internal users#85049ywangd merged 4 commits intoelastic:masterfrom
ywangd merged 4 commits intoelastic:masterfrom
Conversation
Internal users have hard-coded role descriptors which are not registered with any role store. This means they cannot simply be retrieved by names. This PR adds logic to check for internal users and return their role descriptor accordingly. This change also makes it possible to finally correct the role name used by the _xpack_security user. A test for enrollment token is also added to ensure the change to _xpack_security user do not break the enrollment flow. Relates: elastic#83627, elastic#84096
Collaborator
|
Pinging @elastic/es-security (Team:Security) |
Collaborator
|
Hi @ywangd, I've created a changelog YAML for you. |
ywangd
commented
Mar 17, 2022
Comment on lines
+374
to
+388
| final User user = subject.getUser(); | ||
| if (SystemUser.is(user)) { | ||
| throw new IllegalArgumentException( | ||
| "the user [" + user.principal() + "] is the system user and we should never try to get its role descriptors" | ||
| ); | ||
| } | ||
| if (XPackUser.is(user)) { | ||
| return Optional.of(XPackUser.ROLE_DESCRIPTOR); | ||
| } | ||
| if (XPackSecurityUser.is(user)) { | ||
| return Optional.of(XPackSecurityUser.ROLE_DESCRIPTOR); | ||
| } | ||
| if (AsyncSearchUser.is(user)) { | ||
| return Optional.of(AsyncSearchUser.ROLE_DESCRIPTOR); | ||
| } |
Member
Author
There was a problem hiding this comment.
I plan to capture internal users with a sealed subclass of User so that the check is future proof. It will be a separate PR.
tvernum
approved these changes
Mar 18, 2022
| AuthenticateAction.INSTANCE, | ||
| new AuthenticateRequest("_xpack_security") | ||
| ).actionGet(); | ||
| assertThat(authenticateResponse1.authentication().getUser().principal(), equalTo("_xpack_security")); |
Contributor
There was a problem hiding this comment.
I think this is actually wrong. I think it would be better if node enrollment keys were owned by a "_node_enrollment" user rather than _xpack_security.
But it is what it is.
Contributor
There was a problem hiding this comment.
I think so too, https://github.com/elastic/elasticsearch/pull/72186/files#r635377589 .
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.
Internal users have hard-coded role descriptors which are not registered
with any role store. This means they cannot simply be retrieved by
names. This PR adds logic to check for internal users and return their
role descriptor accordingly. This change also makes it possible to
finally correct the role name used by the _xpack_security user. A test
for enrollment token is also added to ensure the change to
_xpack_security user do not break the enrollment flow.
Relates: #83627, #84096