elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.71k stars 8.13k forks source link

Failure to instantiate elasticsearchClient.asSecondaryAuthUser with fake request #192004

Closed klacabane closed 2 days ago

klacabane commented 1 week ago

Calling client.asSecondaryAuthUser from a client scoped to a fake request returns the following error: Error: asSecondaryAuthUser called from a client scoped to a request without 'authorization' header.

The issue appears to be in this ternary that extracts auth headers from the request. When provided a fake request, isRealRequest(request) will return true triggering the wrong branch, leading to empty headers while request.headers are set.

How to reproduce:

const fakeRequest = getFakeKibanaRequest({ id: apiKey.id, api_key: apiKey.apiKey });
const esClient = server.core.elasticsearch.client.asScoped(fakeRequest).asSecondaryAuthUser;
elasticmachine commented 1 week ago

Pinging @elastic/kibana-core (Team:Core)