Skip to content

Conversation

@ywangd
Copy link
Member

@ywangd ywangd commented Dec 21, 2021

This PR replaces superuser role of an API key with the new limited
superuser role to prevent write access to system indices.

The replacement should only happen to the builtin superuser role.
If there is a user-created role that has the exact same definition as
the superuser role, it will not be replaced because we consider users
are explicitly opt-in for ALL access in this scenario.

Since API key captures (snapshots) user roles when creating the key,
it is not always straightforward to decide whether the captured role descriptor
is indeed the builtin superuser, e.g. before #82049, the key role descriptors can
be created exactly like the builtin superuer (including the _reserved metadata
field). The solution is to only replace role descriptors from the limited-by roles because:

  • Currently the limited-by roles are either sourced from the role providers using "names"
    or they are empty (derived keys)
  • If we decide to expand support for derived keys in future, because of Add validation for API key role descriptors #82049, new keys
    will not have be able to have role descriptors with _reserved metadata field. For old
    keys, we can add additional checks to drop any invalid metadata field (or throw errors).
    In short, we should be able to prevent a custom role looks exactly like the builtin superuser
    role.

Relates: #81400

This PR replace superuser role of an API key with the new limited
superuser role to prevent write access to system indices.

Relates: elastic#81400
@ywangd ywangd added >breaking WIP :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC v8.1.0 labels Dec 21, 2021
@ywangd ywangd marked this pull request as ready for review January 12, 2022 02:24
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Jan 12, 2022
@elasticmachine
Copy link
Collaborator

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

@ywangd ywangd requested a review from tvernum January 12, 2022 02:24
@ywangd ywangd removed the WIP label Jan 12, 2022
Copy link
Contributor

@tvernum tvernum left a comment

Choose a reason for hiding this comment

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

I'm happy with the approach.
I haven't reviewed 100% of the changes, but I can do a final pass in the morning.

return List.of(limitedByRoleReference);
}
return List.of(new RoleReference.ApiKeyRoleReference(apiKeyId, roleDescriptorsBytes, "apikey_role"), limitedByRoleReference);
return List.of(new RoleReference.ApiKeyRoleReference(apiKeyId, roleDescriptorsBytes, false), limitedByRoleReference);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably a nit, but I think an enum would be better than a boolean. Something like:

enum ApiKeyRoleType {
  ASSIGNED_ROLES, LIMITED_BY_ROLES
}

(I'm happy with different names for them enum class, or members)

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 added the enum and also use the enum toString for the source of the roleKey to avoid having extra string constants. It might also become useful if later we decide to support layered limited-by. I think it's an overall improvement. Thanks for the suggestion.

@ywangd
Copy link
Member Author

ywangd commented Jan 13, 2022

@elasticmachine update branch

@ywangd ywangd requested a review from tvernum January 13, 2022 02:44
Copy link
Contributor

@tvernum tvernum left a comment

Choose a reason for hiding this comment

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

LGTM

@ywangd
Copy link
Member Author

ywangd commented Jan 17, 2022

CI Failure is not related and not reproducible. I raised #82647

@ywangd
Copy link
Member Author

ywangd commented Jan 17, 2022

@elasticmachine run elasticsearch-ci/part-1

@ywangd ywangd merged commit b6277d8 into elastic:master Jan 17, 2022
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Jan 17, 2022
This PR replace superuser role of an API key with the new limited
superuser role to prevent write access to system indices.

The replacement should only happen to the builtin superuser role.
If there is a user-created role that has the exact same definition as
the superuser role, it will not be replaced because we consider users
are explicitly opt-in for ALL access in this scenario.

Relates: elastic#81400
ywangd added a commit that referenced this pull request Jan 17, 2022
This PR replace superuser role of an API key with the new limited
superuser role to prevent write access to system indices.

The replacement should only happen to the builtin superuser role.
If there is a user-created role that has the exact same definition as
the superuser role, it will not be replaced because we consider users
are explicitly opt-in for ALL access in this scenario.

Backport: #82650
@ywangd ywangd added the v8.0.0 label Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>breaking :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Security Meta label for security team v8.0.0 v8.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants