-
Notifications
You must be signed in to change notification settings - Fork 539
Description
With the latest changes in how an API Key is validated, invalid API Keys do no longer get cached.
When calling ES via the go-elasticsearch client an error is returned whenever resp.IsError() is true, which is the case for statusCode > 299. For existing API Keys the hasPrivileges request returns a 200 and the body holds the information for which requested privileges the API Key is valid. For non-existing API Keys the hasPrivileges request returns a 401.
With the latest changes in how the requests response is returned, an error is returned now for such cases.
When checking if an API Key is authorized, API Key requests resulting in an error, are not cached though. Initially these responses were not cached, as ES could e.g. be temporarily unavailable in which case a potentially valid API Key should not be cached as invalid, and 401 from ES were not returned as errors.
We need to find a way now to differentiate between server side errors and other errors on the consumer level of the Elasticsearch package, e.g. by also returning a statuscode for es.HasPrivileges, to ensure all API Keys are properly cached, while not caching false negatives on Elasticsearch server errors.
It is unclear to me why the system test testing the caching behavior for non-existing API Keys only started failing now.
Failing Test:
apm-server/tests/system/test_access.py
Line 167 in 4824cbb
| class TestAPIKeyCache(BaseAPIKey): |
Needs to be backported to 7.6.