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

Consolidate user role resolution for API keys #88542

Merged
merged 21 commits into from
Jul 20, 2022

Conversation

n1v0lg
Copy link
Contributor

@n1v0lg n1v0lg commented Jul 14, 2022

This refactor extracts the user role resolution logic for API keys from
ApiKeyGenerator. It plugs the shared resolver class into API key
creation and update handling. It also removes ApiKeyGenerator since
the class is now trivial. A new REST base handler for API key-related
REST actions ensures that the API key service is enabled before we
perform role resolution, which was the only other responsibility left
to ApiKeyGenerator.

Relates:
https://github.com/elastic/elasticsearch/pull/88186/files#r910515818

@n1v0lg n1v0lg added >refactoring :Security/Security Security issues without another label labels Jul 14, 2022
@n1v0lg n1v0lg self-assigned this Jul 14, 2022
@n1v0lg n1v0lg changed the title Generalize ApiKeyGenerator to handle API key updates Consolidate user role handling for API key updates Jul 14, 2022

import java.util.Set;

public class ApiKeyUserRoleDescriptorResolver {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can also add a test for ApiKeyUpdateHandler however it's very simple and already exercised by our integration tests.

@n1v0lg n1v0lg marked this pull request as ready for review July 14, 2022 14:23
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Jul 14, 2022
@elasticmachine
Copy link
Collaborator

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

@n1v0lg n1v0lg requested a review from ywangd July 14, 2022 15:56
Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

The essence of ApiKeyGenerator is really just about resolving the owner user's role descriptors. Once this part is refactored out to its own class, there is no good reason to still keep this class around. I'd suggest we simply remove it and let the handler classes (TransportCreateApiKeyAction and TransportGrantApiKeyAction etc) to be the true handlers. It will be a bit bigger change. But that's OK for a refactoring PR.

@n1v0lg n1v0lg changed the title Consolidate user role handling for API key updates Consolidate user role resolution for API keys Jul 19, 2022
@n1v0lg n1v0lg requested a review from ywangd July 19, 2022 20:44
Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM

@n1v0lg n1v0lg merged commit efd8ecf into elastic:master Jul 20, 2022
@n1v0lg n1v0lg deleted the update-api-keys-api-key-manager branch July 20, 2022 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :Security/Security Security issues without another label Team:Security Meta label for security team v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants