-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Handle role descriptor retrieval for internal users #85049
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
Pinging @elastic/es-security (Team:Security) |
Hi @ywangd, I've created a changelog YAML for you. |
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); | ||
} |
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 plan to capture internal users with a sealed subclass of User
so that the check is future proof. It will be a separate PR.
AuthenticateAction.INSTANCE, | ||
new AuthenticateRequest("_xpack_security") | ||
).actionGet(); | ||
assertThat(authenticateResponse1.authentication().getUser().principal(), equalTo("_xpack_security")); |
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 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.
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.
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