elasticsearch-py: ssl verification fails despite verify_certs=false
In elasticsearch version 6.6.1 and elasticsearch-dsl version 6.1.0, ssl verification seems to ignore the verify_certs option. When set to True, the cert is still verified and fails on self-signed certs.
In version elasticsearch 5.5.1, and elasticsearch-dsl version 5.4.0, the verify_certs options works as expected.
client = Elasticsearch( hosts=['localhost'], verify_certs=False, timeout=60 )
elasticsearch.exceptions.SSLError: ConnectionError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)) caused by: SSLError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777))
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 28 (8 by maintainers)
I went through the debugger a bunch and found that
verify_certsis ignored ifca_certsisNoneor set to some value (Noneis taken as “use defaults”, which results in certs being set to required). Simply set this to aFalsevalue of some sort that isn’tNoneand it should work.This seems to be an issue with the underlying Python library, but it’s difficult to figure that out due to the way keyword args are passed around in the Elasticsearch library.
@gnarlyman thanks for the issue and the good eye. I’ll get this fixed asap.
But please note that the use of
verify_certsis depreicated.Please try creating an ssl_context object and set the verification mode on the context.
I experienced a similar problem and the following way seems to work for elastic 6.3.1 and urllib3 1.25.3.
In a nutshell, the default connection class is Urllib3HttpConnection, which raises the exception below:
If the connection class is set to
RequestsHttpConnection, just a warning message will appear:UserWarning: Connecting to https://localhost:9200 using SSL with verify_certs=False is insecure.For me, it only worked after removing list and dict, and simply using the raw connection string. ES version 6.6.0 and elasticsearch6 (6.4.2) python package.
Hi @geajack ,
Have you tried the following code?
find more details here https://github.com/elastic/elasticsearch-py/issues/712#issuecomment-497251933
I gave the workaround a try and I could not make it work. I tried two variations, one with a
cafile(from certifi) and one without acafilewhen creating the SSL context (+ I also explicitly setverify_certstoFalse).This is my test program:
It always fails with:
When running this in the REPL, I noticed that
ssl_context.verify_modehas been set toVerifyMode.CERT_REQUIREDagain after the (failing) calles.info().Tbh, I did not completely debug the issue. I think the reason is that when creating
Urllib3HttpConnectionca_cert is always set and further down the line urrlib3 overrides the verification mode again when a certificate is provided.Did anyone manage to make it work with python3.5 and latest urllib3?
@vibha0411 , you can try downgrading elasticsearch to 7.9.1. It helped in my case. The new version is too strict.
I’m still having trouble with this. I have the OpenDistro ElasticSearch docker running on port 9200. I can get through to it with curl:
Note that the connection is HTTPS, but the
--insecureoption tells curl not to check the certificate. However, this code fails in Python:yielding the same error as in the OP:
I’m using the latest version of elasticsearch as far as I know, I installed it with pip on Python 3.7 just today.