Skip to content
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

Merged
merged 4 commits into from
Mar 18, 2022

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented Mar 17, 2022

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

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
@ywangd ywangd added >bug :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC v8.2.0 labels Mar 17, 2022
@ywangd ywangd requested a review from tvernum March 17, 2022 05:27
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Mar 17, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@elasticsearchmachine
Copy link
Collaborator

Hi @ywangd, I've created a changelog YAML for you.

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);
}
Copy link
Member Author

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"));
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ywangd ywangd merged commit 40dc0fb into elastic:master Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Security Meta label for security team v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants