-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Fix bugs for unexpired API keys and id filtering #76208
Conversation
Pinging @elastic/es-security (Team:Security) |
expiredQuery.should(QueryBuilders.rangeQuery("expiration_time").lte(Instant.now().toEpochMilli())); | ||
expiredQuery.should(QueryBuilders.rangeQuery("expiration_time").gt(Instant.now().toEpochMilli())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the old bug. But this piece of code was never exercised till now.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new bug.
new CreateApiKeyRequest("long-lived", null, TimeValue.timeValueDays(1), null)) | ||
.actionGet() | ||
.getId(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
💔 Backport failed
To backport manually run: |
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.
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 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.I am tagging this PR as
>non-issue
because the code having the old bug was never used till now and the new bug has not been released yet.