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

Bulk invalidate API keys using a list of IDs #63224

Merged
merged 7 commits into from
Oct 6, 2020

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented Oct 5, 2020

Following discussions in #47609, I am reverting back to the approach of adding a new ids field to support bulk invalidation by specifying an array of API key ids.
This PR intentionally keeps the existing id field as is on the API level. Deprecation may as well be introduced for it in the future. But it is not done in this PR to reduce the scope.

I would also like to raise the priority of this PR because of #59376, where a new cache is introduced for API key document. The new cache requires a cache clear call to be issued after API key invalidation. It is helpful if the cache clear call is issued for a collection of API key ids instead of one for each of them. Hence being able to specifiying multiple IDs for invalidation improves the efficiency of the cache clearing call.

Resolves: #47609
Supersedes: #63081, #63127

@ywangd ywangd added >enhancement :Security/Security Security issues without another label v8.0.0 v7.10.0 labels Oct 5, 2020
@ywangd ywangd marked this pull request as ready for review October 5, 2020 04:10
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Security Meta label for security team label Oct 5, 2020
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.

Overall, LGTM, with a couple of comments.

}
} else {
out.writeOptionalString(apiKeyId);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wow. I can't believe we need to have this. We definitely need to look at removing this class in a follow up PR.

security.invalidate_api_key:
body: >
{
"ids": [ "${api_key_id_2}", "${api_key_id_3}" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you consider putting key _1 in here, and checking previously_invalidated_api_keys: 1 ?
It seems like a useful test of the error handling for multiple ids.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately no. The code filters out invalidated keys before calling indexInvalidate, i.e.

findApiKeysForUserRealmApiKeyIdAndNameCombination(realmName, username, apiKeyName, apiKeyId, true, false,

Not sure if it is intended?

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 mean I will add key 1 here, but the response won't change.

ywangd and others added 4 commits October 5, 2020 18:49
Copy link
Contributor

@albertzaharovits albertzaharovits 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 ywangd merged commit 472efef into elastic:master Oct 6, 2020
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Oct 6, 2020
Add a new ids field to the API of invalidating API keys so that it supports bulk
invalidation with a list of IDs.
Note the existing id field is kept as is and it is an error if both id and ids are specified.
ywangd added a commit that referenced this pull request Oct 6, 2020
Add a new ids field to the API of invalidating API keys so that it supports bulk
invalidation with a list of IDs.
Note the existing id field is kept as is and it is an error if both id and ids are specified.
@tvernum
Copy link
Contributor

tvernum commented Oct 12, 2020

@ywangd It looks like we missed updating the API docs in this change. Can you take care of that?

@ywangd
Copy link
Member Author

ywangd commented Oct 12, 2020

@ywangd It looks like we missed updating the API docs in this change. Can you take care of that?

I intentionally left it out because I wasn't sure whether we should start advertising the new field without deprecating the existing id field. But I may have been unnecessarily cautious since we do want the ids field to stay regardless of the process for the id field. So I will add the docs.

@ywangd
Copy link
Member Author

ywangd commented Oct 12, 2020

Just remember the other reason that made me not updating the docs, the HLRC. This PR didn't touch the HLRC code and docs. So I thought for consistency, I should not update the Rest API docs either. Now if we are updating the Rest API docs, I think we should also update the HLRC side (including code and docs). Does it make sense to you?

ywangd added a commit that referenced this pull request Oct 21, 2020
Follow-up for #63224 and adds the missing doc update for the new ids field.
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Oct 21, 2020
Follow-up for elastic#63224 and adds the missing doc update for the new ids field.
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Oct 21, 2020
Follow-up for elastic#63224 and adds the missing doc update for the new ids field.
ywangd added a commit that referenced this pull request Oct 21, 2020
Follow-up for #63224 and adds the missing doc update for the new ids field.
ywangd added a commit that referenced this pull request Oct 21, 2020
Follow-up for #63224 and adds the missing doc update for the new ids field.
ywangd added a commit that referenced this pull request Dec 20, 2020
This PR deprecates the usage of the id field in the payload for the
InvalidateApiKey API. The ids field introduced in #63224 is now the recommended
way for performing (bulk) API key invalidation.
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Dec 21, 2020
This PR deprecates the usage of the id field in the payload for the
InvalidateApiKey API. The ids field introduced in elastic#63224 is now the recommended
way for performing (bulk) API key invalidation.
ywangd added a commit that referenced this pull request Dec 22, 2020
This PR deprecates the usage of the id field in the payload for the
InvalidateApiKey API. The ids field introduced in #63224 is now the recommended
way for performing (bulk) API key invalidation.

This PR also includes the test fix from #66696
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Security/Security Security issues without another label Team:Security Meta label for security team v7.10.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support invalidating multiple API keys by their ID
5 participants