Skip to content

Handle role descriptor retrieval for internal users#85049

Merged
ywangd merged 4 commits intoelastic:masterfrom
ywangd:robust-get-role-descriptor
Mar 18, 2022
Merged

Handle role descriptor retrieval for internal users#85049
ywangd merged 4 commits intoelastic:masterfrom
ywangd:robust-get-role-descriptor

Conversation

@ywangd
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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

@elasticsearchmachine
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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