Today CCR sends its cross-cluster requests using a client which switches thread context to one with the right authorisation headers just before sending the request to the remote cluster (see e.g. CcrLicenseChecker#wrapClient). Instead we should run all the relevant code in the right thread context to begin with, and then just switch to a regular client. This would prevent surprises such as https://github.com/elastic/elasticsearch/issues/61308 and https://github.com/elastic/elasticsearch/pull/84409 and would also let us propagate other headers across clusters (e.g. for tracing).
Today CCR sends its cross-cluster requests using a client which switches thread context to one with the right authorisation headers just before sending the request to the remote cluster (see e.g.
CcrLicenseChecker#wrapClient
). Instead we should run all the relevant code in the right thread context to begin with, and then just switch to a regular client. This would prevent surprises such as https://github.com/elastic/elasticsearch/issues/61308 and https://github.com/elastic/elasticsearch/pull/84409 and would also let us propagate other headers across clusters (e.g. for tracing).