Skip to content

Commit daf384e

Browse files
committed
allow to disable TLS certificate verification
1 parent b69a0df commit daf384e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

arango/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
)
2121
from arango.version import version
2222

23-
2423
class ArangoClient:
2524
"""ArangoDB client.
2625
@@ -45,6 +44,8 @@ class ArangoClient:
4544
the de-serialized object. If not given, ``json.loads`` is used by
4645
default.
4746
:type deserializer: callable
47+
:param verify_certificate: Verify TLS certificates.
48+
:type verify_certificate: bool
4849
"""
4950

5051
def __init__(
@@ -55,6 +56,7 @@ def __init__(
5556
http_client: Optional[HTTPClient] = None,
5657
serializer: Callable[..., str] = lambda x: dumps(x),
5758
deserializer: Callable[[str], Any] = lambda x: loads(x),
59+
verify_certificate: bool = True,
5860
) -> None:
5961
if isinstance(hosts, str):
6062
self._hosts = [host.strip("/") for host in hosts.split(",")]
@@ -75,6 +77,10 @@ def __init__(
7577
self._serializer = serializer
7678
self._deserializer = deserializer
7779
self._sessions = [self._http.create_session(h) for h in self._hosts]
80+
81+
# set flag for SSL/TLS certificate verification
82+
for session in self._sessions:
83+
session.verify = verify_certificate
7884

7985
def __repr__(self) -> str:
8086
return f"<ArangoClient {','.join(self._hosts)}>"
@@ -110,6 +116,7 @@ def db(
110116
verify: bool = False,
111117
auth_method: str = "basic",
112118
superuser_token: Optional[str] = None,
119+
verify_certificate: bool = True,
113120
) -> StandardDatabase:
114121
"""Connect to an ArangoDB database and return the database API wrapper.
115122
@@ -130,6 +137,8 @@ def db(
130137
If set, parameters **username**, **password** and **auth_method**
131138
are ignored. This token is not refreshed automatically.
132139
:type superuser_token: str
140+
:param verify_certificate: Verify TLS certificates.
141+
:type verify_certificate: bool
133142
:return: Standard database API wrapper.
134143
:rtype: arango.database.StandardDatabase
135144
:raise arango.exceptions.ServerConnectionError: If **verify** was set

docs/certificates.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
TLS certificate verification
2+
----------------------------
3+
4+
When connecting against a server using an https/TLS connection, TLS certificates
5+
are verified by default.
6+
By default, self-signed certificates will cause trouble when connecting.
7+
8+
.. code-block:: python
9+
10+
client = ArangoClient(hosts="https://localhost:8529")
11+
12+
In order to make connections work even when using self-signed certificates, the
13+
`verify_certificates` option can be disabled when creating the `ArangoClient`
14+
instance:
15+
16+
.. code-block:: python
17+
18+
client = ArangoClient(hosts="https://localhost:8529", verify_certificate=False)
19+
20+
This will allow connecting, but the underlying `urllib3` library may still issue
21+
warnings due to the insecurity of using self-signed certificates.
22+
23+
To turn off these warnings as well, you can add the following code to your client
24+
application:
25+
26+
.. code-block:: python
27+
28+
import requests
29+
requests.packages.urllib3.disable_warnings()
30+

0 commit comments

Comments
 (0)