Skip to content

Commit 757e950

Browse files
committed
Use "verify_ssl_cert=True" as a default on the CrateDB HTTP client
Recently, this has been made a default on the CrateDB connection object, but apparently it has been missed to also flip the switch on this end. Also, adjust the respective doctests accordingly.
1 parent fe6f1c1 commit 757e950

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed

src/crate/client/doctests/https.txt

+28-31
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
.. _https_connection:
22

33
========================
4-
HTTPS Connection support
4+
HTTPS connection support
55
========================
66

7-
The CrateDB Client is able to connect via https.
7+
The CrateDB client is able to connect via HTTPS.
88

9-
.. note::
9+
A check against a specific CA certificate can be made by creating the client
10+
with the path to the CA certificate file using the keyword argument
11+
``ca_cert``.
1012

11-
By default, ssl server certificates are **NOT** verified.
13+
.. note::
1214

13-
To enable verification, use the keyword argument ``verify_ssl_cert``.
14-
If it is set to ``True``, the server certificate is validated, if set to
15-
``False`` or ommitted, no verification will be done whatsoever.
15+
By default, SSL server certificates are verified. To disable verification,
16+
use the keyword argument ``verify_ssl_cert``. If it is set to ``False``,
17+
server certificate validation will be skipped.
1618

17-
One can check against a single CA certificate
18-
by creating the client with the a path to a CA certificate file to check against
19-
in keyword argument ``ca_cert``.
2019

2120
.. rubric:: Table of Contents
2221

@@ -26,45 +25,44 @@ in keyword argument ``ca_cert``.
2625
Examples
2726
--------
2827

29-
By default, certificates are not verified. This call is against a server with
30-
a self signed certificate::
31-
32-
>>> http_client = HttpClient([crate_host])
33-
>>> http_client.server_infos(http_client._get_server())
34-
('https://localhost:65534', 'test', '0.0.0')
35-
3628
When switching on verification without a ``ca_cert`` file provided, the
37-
connection will fail::
29+
connection will fail because we are using a self-signed server certificate::
3830

39-
>>> verifying_client = HttpClient([crate_host], verify_ssl_cert=True)
31+
>>> verifying_client = HttpClient([crate_host])
4032
>>> verifying_client.server_infos(crate_host)
4133
Traceback (most recent call last):
4234
...
4335
crate.client.exceptions.ConnectionError: Server not available, ...certificate verify failed...
4436

45-
Also when providing an invalid ``ca_cert`` an error is raised::
37+
Also, when providing an invalid ``ca_cert`` an error is raised::
4638

47-
>>> verifying_client = HttpClient([crate_host], ca_cert=invalid_ca_cert, verify_ssl_cert=True)
39+
>>> verifying_client = HttpClient([crate_host], ca_cert=invalid_ca_cert)
4840
>>> verifying_client.server_infos(crate_host)
4941
Traceback (most recent call last):
5042
...
5143
crate.client.exceptions.ConnectionError: Server not available, ...certificate verify failed...
5244

53-
Without verification, the given ``ca_cert`` is ignored and the connection will be
54-
established, to Eves satisfaction.
45+
Connecting to a host whose certificate is verified with a valid CA certificate::
46+
47+
>>> verifying_valid_client = HttpClient([crate_host], ca_cert=valid_ca_cert)
48+
>>> verifying_valid_client.server_infos(verifying_valid_client._get_server())
49+
('https://localhost:65534', 'test', '0.0.0')
5550

56-
>>> non_verifying_client = HttpClient([crate_host], ca_cert=invalid_ca_cert, verify_ssl_cert=False)
51+
When turning off certificate verification, calling the server will succeed::
52+
53+
>>> non_verifying_client = HttpClient([crate_host], verify_ssl_cert=False)
5754
>>> non_verifying_client.server_infos(crate_host)
5855
('https://localhost:65534', 'test', '0.0.0')
5956

60-
Connecting to a host whose certificate is verified with a valid CA certificate::
57+
Without verification, calling the server will even work when using an invalid
58+
``ca_cert``::
6159

62-
>>> verifying_valid_client = HttpClient([crate_host], ca_cert=valid_ca_cert, verify_ssl_cert=True)
63-
>>> verifying_valid_client.server_infos(verifying_valid_client._get_server())
60+
>>> non_verifying_client = HttpClient([crate_host], verify_ssl_cert=False, ca_cert=invalid_ca_cert)
61+
>>> non_verifying_client.server_infos(crate_host)
6462
('https://localhost:65534', 'test', '0.0.0')
6563

6664

67-
Client Certificate
65+
Client certificate
6866
------------------
6967

7068
The client supports client certificates.
@@ -73,12 +71,11 @@ The ``HttpClient`` constructor takes two keyword arguments: ``cert_file`` and
7371
``key_file``. Both should be a string pointing to the path of the client
7472
certificate and key file.
7573

76-
Below an example, in this case it fails because the supplied certificate is
74+
This example uses that options, however it fails because the certificate is
7775
invalid::
7876

79-
>>> client = HttpClient([crate_host], cert_file=invalid_ca_cert, key_file=invalid_ca_cert, verify_ssl_cert=True)
77+
>>> client = HttpClient([crate_host], cert_file=invalid_ca_cert, key_file=invalid_ca_cert, timeout=10)
8078
>>> client.server_infos(crate_host)
8179
Traceback (most recent call last):
8280
...
8381
crate.client.exceptions.ConnectionError: Server not available, exception: ...[SSL: ...
84-

src/crate/client/http.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def _get_socket_opts(keepalive=True,
312312

313313
class Client(object):
314314
"""
315-
Crate connection client using crate's HTTP API.
315+
Crate connection client using CrateDB's HTTP API.
316316
"""
317317

318318
SQL_PATH = '/_sql'
@@ -328,7 +328,7 @@ def __init__(self,
328328
servers=None,
329329
timeout=None,
330330
backoff_factor=0,
331-
verify_ssl_cert=False,
331+
verify_ssl_cert=True,
332332
ca_cert=None,
333333
error_trace=False,
334334
cert_file=None,

0 commit comments

Comments
 (0)