Skip to content

Commit 6021160

Browse files
committed
Updated docs for secure channels
1 parent c2dd5fd commit 6021160

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

docs/client.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,31 @@ Here is how to establish a secure connection to a public gRPC server:
5959
6060
In this case ``grpclib`` uses system CA certificates. But ``grpclib`` has also
6161
a built-in support for a certifi_ package which contains actual Mozilla's
62-
collection of CA certificates. All you need is to install it and keep it
63-
updated -- this is a more favorable way than relying on system CA certificates:
62+
collection of CA certificates. All you need is to install it and keep it up to
63+
date -- this is a more favorable way than relying on system CA certificates:
6464

6565
.. code-block:: console
6666
6767
$ pip3 install certifi
6868
69+
Another way to tell which CA certificates to use is by using
70+
:py:func:`python:ssl.get_default_verify_paths` function:
71+
72+
.. code-block:: python
73+
74+
channel = Channel(host, port, ssl=ssl.get_default_verify_paths())
75+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76+
77+
This function also supports reading ``SSL_CERT_FILE`` and ``SSL_CERT_DIR``
78+
environment variables to override your system defaults. It returns
79+
``DefaultVerifyPaths`` named tuple structure which you can customize and provide
80+
your own ``cafile`` and ``capath`` values without using environment variables or
81+
placing certificates into a distribution-specific directory:
82+
83+
.. code-block:: python3
84+
85+
ssl.get_default_verify_paths()._replace(cafile=YOUR_CA_FILE)
86+
6987
``grpclib`` also allows you to use a custom SSL configuration by providing a
7088
:py:class:`~python:ssl.SSLContext` object. We have a simple mTLS auth example
7189
in our code repository to illustrate how this works.

grpclib/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ def __init__(
645645
``ProtoStatusDetailsCodec`` is used by default
646646
647647
:param ssl: ``True`` or :py:class:`~python:ssl.SSLContext` object or
648-
:py:class:`~python:ssl.DefaultVerifyPaths` object; if ``True``,
649-
default SSL context is used.
648+
``ssl.DefaultVerifyPaths`` object; if ``True``, default SSL context
649+
is used.
650650
"""
651651
if path is not None and (host is not None or port is not None):
652652
raise ValueError("The 'path' parameter can not be used with the "

0 commit comments

Comments
 (0)