-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Sniffing ignores authorization options and x-opaque-id #2005
Comments
This appears to still be an issue on elasticsearch-py version 8.5.0 and elasticsearch version 8.5.3. The misleading error message cost us quite some time re-evaluating our elasticsearch configuration. Would be nice if someone could take a look at it. |
I have experienced the same issue. And indeed it
due to the observed behavior being:
Client was configured using RFC-1738 formatted URL, which is one of the officially proposed and supported options. connections.configure(
default={
"hosts": [settings.ES_URL], # URL formatted as "http://user:password@host:port"
"retry_on_timeout": True,
"sniffer_timeout": 3600,
}
) Nevertheless, after sniffing was done, connection pool lost all auth info and attempted to make unauthenticated requests. The solution was either from yarl import URL
es_url = URL(settings.ES_URL) # here ES_URL is parsed into components
connections.configure(
default={
"hosts": [str(es_url.origin())], # "host:port"
"http_auth": f"{es_url.user}:{es_url.password}",
"retry_on_timeout": True,
"sniffer_timeout": 3600,
}
) I find this behavior misleading and not intuitive. It is also not described anywhere seemingly. |
Just ran into this today. Our Elasticsearch API is exposed via an Nginx reverse proxy protected by basic auth. The reverse proxy itself uses HTTPS with self signed certificate Trying to instantiate Elasticsearch with
fails with
And nginx logs show that 401 was raised. However, if we instantiate Elasticsearch with |
Is there any way to have |
Howdy, I ran into this problem upgrading our clients from 7.x to 8.8 and wrote a workaround by overwriting the internal callback that does these sniff requests. Hope this issue can be addressed soon, but in the meantime you can still use the sniff options by initializing the connection like so (note this is for the sync client, and may need changes depending on your client version and needs): https://gist.github.com/jhopkins219/2b5b38061f1b87515c7a5c29ca91a0a3 |
@jhopkins219 Thanks for your fix. I have tried it and it works with some adaptation (I need api key in my case). But next step is a new problem, direct queries on nodes seems to lost my
I'm currently investigating in URLlilb, HttpRequest from |
Bumping cause this 2022 issue is still persistent.....classic enterprise devs lol |
I can confirm @jhopkins219 patch fixes this issue for me! Props |
is this fix released? facing the same on 8.12 elasticsearch-py |
nope. lazy enterprise devs still havent paid attention to this 2 year old issue..... https://github.com/elastic/elasticsearch-py/blob/8.12/elasticsearch/_sync/client/_base.py#L166 I have also sent in a PR for a potential fix to this issue...but with this issue being from 2022, who knows when the developers will push this to the upstream. |
Elasticsearch version (
bin/elasticsearch --version
):Version: 8.2.2, Build: default/docker/9876968ef3c745186b94fdabd4483e01499224ef/2022-05-25T15:47:06.259735307Z, JVM: 18.0.1.1
elasticsearch-py
version (elasticsearch.__versionstr__
):8.2.3
Sniffing callback uses Transport instance directly to perform
/_nodes/_all/http
requests.elasticsearch-py/elasticsearch/_async/client/_base.py
Line 172 in 0da2ba9
However, both Authorization and opaque-id headers are NOT passed to Transport class during initialization.
elasticsearch-py/elasticsearch/_async/client/__init__.py
Line 324 in 0da2ba9
Instead they are saved to Elasticsearch client instance after Transport is already created
elasticsearch-py/elasticsearch/_async/client/__init__.py
Line 407 in 0da2ba9
and used for API requests only.
elasticsearch-py/elasticsearch/_async/client/__init__.py
Line 407 in 0da2ba9
As the result sniffing fails with Exception
elastic_transport.SniffingError: No viable nodes were discovered on the initial sniff attempt
while the real problem isThe problem is the same for both Sync and Async clients.
The fix might be to build opaque-id and authorization headers before transport intialization to and pass them to
client_node_configs
method (headers
argument). However, I am not sure if it will work "as intended" with.options()
feature and internal_transport
constructor argument ofElasticsearch
andAsyncElasticsearch
classes.The text was updated successfully, but these errors were encountered: