Fix bugs for unexpired API keys and id filtering#76208
Merged
ywangd merged 2 commits intoelastic:masterfrom Aug 9, 2021
Merged
Fix bugs for unexpired API keys and id filtering#76208ywangd merged 2 commits intoelastic:masterfrom
ywangd merged 2 commits intoelastic:masterfrom
Conversation
Collaborator
|
Pinging @elastic/es-security (Team:Security) |
ywangd
commented
Aug 6, 2021
| if (filterOutExpiredKeys) { | ||
| final BoolQueryBuilder expiredQuery = QueryBuilders.boolQuery(); | ||
| expiredQuery.should(QueryBuilders.rangeQuery("expiration_time").lte(Instant.now().toEpochMilli())); | ||
| expiredQuery.should(QueryBuilders.rangeQuery("expiration_time").gt(Instant.now().toEpochMilli())); |
Member
Author
There was a problem hiding this comment.
This is the old bug. But this piece of code was never exercised till now.
ywangd
commented
Aug 6, 2021
| // Field names allowed at the index level | ||
| private static final Set<String> ALLOWED_EXACT_INDEX_FIELD_NAMES = | ||
| Set.of("doc_type", "name", "api_key_invalidated", "creation_time", "expiration_time"); | ||
| Set.of("_id", "doc_type", "name", "api_key_invalidated", "creation_time", "expiration_time"); |
tvernum
approved these changes
Aug 9, 2021
| new CreateApiKeyRequest("long-lived", null, TimeValue.timeValueDays(1), null)) | ||
| .actionGet() | ||
| .getId(); | ||
|
|
Contributor
There was a problem hiding this comment.
Should we ensure the clock has ticked here?
It should but eventually someone will run this on a machine that is so fast that the key hasn't expired by the time we search.
Member
Author
There was a problem hiding this comment.
Since the 1st key expires in just 1ms, the machine needs to be super fast and lucky to finish creating the 2nd key (hashing and wait_for) within that time frame. That said, it does not hurt to add a sleep for 10ms so I did it.
Collaborator
💔 Backport failed
To backport manually run: |
ywangd
added a commit
to ywangd/elasticsearch
that referenced
this pull request
Aug 9, 2021
This PR fixed an old bug and a new bug introduced elastic#75335. Interestingly, the two bugs somewhat cancelled each other in tests. In addition, the test setup also contributed to the overall issue. The old bug is about filtering out expired API keys, but the relationship was wrong in the search query. The new bug is that _id field should be allowed in the index level for the new API key search API. Because of the old bug, the query always gets rewritten because the tests do not have any API keys that are expired before the query time. The query rewriting effectively bypasses the _id field check. Hence the new bug is not triggered.
ywangd
added a commit
that referenced
this pull request
Aug 9, 2021
This PR fixed an old bug and a new bug introduced #75335. Interestingly, the two bugs somewhat cancelled each other in tests. In addition, the test setup also contributed to the overall issue. The old bug is about filtering out expired API keys, but the relationship was wrong in the search query. The new bug is that _id field should be allowed in the index level for the new API key search API. Because of the old bug, the query always gets rewritten because the tests do not have any API keys that are expired before the query time. The query rewriting effectively bypasses the _id field check. Hence the new bug is not triggered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixed an old bug and a new bug introduced #75335. Interestingly, the two bugs somewhat cancelled each other in tests. In addition, the test setup also contributed to the overall issue.
The old bug is about filtering out expired API keys, but the relationship was wrong in the search query. The new bug is that
_idfield should be allowed in the index level for the new API key search API. Because of the old bug, the query always gets rewritten because the tests do not have any API keys that are expired before the query time. The query rewriting effectively bypasses the_idfield check. Hence the new bug is not triggered.I am tagging this PR as
>non-issuebecause the code having the old bug was never used till now and the new bug has not been released yet.