Skip to content
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

[Core] Add TLS/SSL support to gRPC channels #18631

Merged
merged 80 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
efe18dd
Add use_tls_ member to GrpcServer
oscarknagg Sep 8, 2021
d38af35
Hacky TLS
oscarknagg Sep 8, 2021
3b5f210
Create secure gRPC channels in Python code
oscarknagg Sep 8, 2021
01c5cd9
Remove unecessary std::cout
oscarknagg Sep 8, 2021
2769675
More TLS
oscarknagg Sep 8, 2021
c6ad485
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 8, 2021
2962be3
Linting
oscarknagg Sep 8, 2021
64be21a
Add secure grpc in tests
oscarknagg Sep 8, 2021
d38e2b0
Fix secure grpc server initialisation
oscarknagg Sep 8, 2021
7aaa8ac
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 8, 2021
1668ecc
Use single environment variable as feature flag
oscarknagg Sep 9, 2021
621cfc7
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 9, 2021
a2c49d6
Pass environment in test_client_builder.py
oscarknagg Sep 9, 2021
0b73c38
Read RAY_USE_TLS in client worker
oscarknagg Sep 9, 2021
ddc8749
Unify init_grpc_channel and init_aiogrpc_channel functions
oscarknagg Sep 10, 2021
966fc49
Make function to add port to grpc server
oscarknagg Sep 10, 2021
b173b78
Upgrade to mTLS
oscarknagg Sep 10, 2021
bc39b8f
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 10, 2021
65361a2
Function to load certs from env variables
oscarknagg Sep 10, 2021
2dcff3a
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 13, 2021
f19e7a7
Add example cluster yaml which generates self-signed keys
oscarknagg Sep 13, 2021
b57c2e2
Add TLS auth test
oscarknagg Sep 14, 2021
a4cc458
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 14, 2021
65f0080
Add some fixtures to run test_basic.py with TLS auth
oscarknagg Sep 15, 2021
da45c78
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 15, 2021
b4dc0ca
Fix test_tls_auth.py
oscarknagg Sep 15, 2021
16c0cb3
Remove duplicated ReadFile function
oscarknagg Sep 15, 2021
30bebae
Formatting
oscarknagg Sep 15, 2021
c551c30
Remove EKS cluster YAML
oscarknagg Sep 15, 2021
1fa0fbf
Don't assume TLS env vars are set
oscarknagg Sep 15, 2021
2b0bc68
Add cryptography requirement to generate testing certs
oscarknagg Sep 15, 2021
ef5025a
Linting
oscarknagg Sep 15, 2021
d79fdd7
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 16, 2021
de36d6a
Fix new_dashboard->dashboard merge
oscarknagg Sep 16, 2021
92627a8
Remove possibility of nullptr from RAY_USE_TLS
oscarknagg Sep 16, 2021
d3b47dc
clang-format 7.0.0 linting
oscarknagg Sep 16, 2021
08fc4b0
Linting
oscarknagg Sep 16, 2021
a70a355
Fix failing test_grpc_credentials test
oscarknagg Sep 16, 2021
cd613df
Make dashboard head classes use async grpc again
oscarknagg Sep 16, 2021
b296a8a
Add test_tls_auth to BUILD
oscarknagg Sep 16, 2021
1cc7744
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 17, 2021
5528b51
Relax cryptography requirement
oscarknagg Sep 20, 2021
69f0618
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 20, 2021
c77d97a
Lint
oscarknagg Sep 20, 2021
3cf6271
Worker._secure looks at env var
oscarknagg Sep 20, 2021
b84dbe6
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 23, 2021
b82c932
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Sep 27, 2021
ddfa148
Apply changes from ci/travis/lint.sh
oscarknagg Sep 27, 2021
32acd64
Skip TLS tests on MacOS
oscarknagg Sep 27, 2021
d04fe6d
format.sh changes
oscarknagg Sep 27, 2021
53896b3
Address comments
oscarknagg Sep 27, 2021
09884ad
Merge branch 'tls' of github.com:oscarknagg/ray into tls
oscarknagg Oct 12, 2021
aea3e4e
Revert "Address comments"
oscarknagg Oct 12, 2021
8f02386
Merge master
oscarknagg Oct 12, 2021
6b0bced
Merge branch 'master' into tls
oscarknagg Oct 12, 2021
f57a61e
Merge remote-tracking branch 'upstream/master' into tls
oscarknagg Oct 12, 2021
78bbb34
Squashed commit of the following:
oscarknagg Oct 12, 2021
7639a65
Replace getenv with RayConfig
oscarknagg Oct 12, 2021
d95419a
Remove lingering errors from earlier merge
oscarknagg Oct 12, 2021
1c92af2
Address comments pt2
oscarknagg Oct 14, 2021
f2e1e55
Merge remote-tracking branch 'upstream/master' into tls
oscarknagg Oct 14, 2021
7c3f7b2
Tidy up
oscarknagg Oct 14, 2021
8d204c5
Hopefully fix lint
oscarknagg Oct 15, 2021
6954178
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Oct 15, 2021
94a52ae
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Oct 18, 2021
74d1652
Lint
oscarknagg Oct 18, 2021
c96043d
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Oct 18, 2021
50c2da2
Remove unecessary logic in ray_config_def.h
oscarknagg Oct 19, 2021
8599854
Actually check for ConnectionError in test_client_connect_to_tls_server
oscarknagg Oct 19, 2021
60355a2
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Oct 19, 2021
9dfd106
Remove unused ReadFile declaration
oscarknagg Oct 19, 2021
4feae45
Lint
oscarknagg Oct 19, 2021
5b57d7d
Replace grpc.insercure_channel with ray._private.utils.init_grpc_chan…
oscarknagg Oct 19, 2021
a600eaf
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Oct 19, 2021
67d32b7
Trigger retest
ericl Oct 19, 2021
6fa08dc
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Oct 20, 2021
f4032f1
Attempt to fix windows build
oscarknagg Oct 20, 2021
7fb64f0
Merge branch 'master' of https://github.com/ray-project/ray into tls
oscarknagg Oct 20, 2021
f4c8ae7
Merge branch 'master' into tls
ericl Oct 21, 2021
e74d707
Update worker.py
ericl Oct 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Squashed commit of the following:
commit 1593350efe1e9520171eb52ade25fd1022c512f6
Merge: 504399b 2c93708
Author: Oscar Knagg <[email protected]>
Date:   Tue Oct 12 16:05:41 2021 +0100

    Merge remote-tracking branch 'origin' into tls-working

commit 504399b
Author: Oscar Knagg <[email protected]>
Date:   Tue Oct 12 14:56:17 2021 +0100

    format.sh changes

commit 7b23f9e
Author: Oscar Knagg <[email protected]>
Date:   Tue Oct 12 14:54:13 2021 +0100

    Fix tests

commit fdbe8eb
Author: Oscar Knagg <[email protected]>
Date:   Tue Oct 12 13:46:17 2021 +0100

    Move functions around

commit 36ce6ac
Merge: a33e32f 8241a03
Author: Oscar Knagg <[email protected]>
Date:   Tue Oct 12 13:40:10 2021 +0100

    Merge branch 'master' of https://github.com/ray-project/ray into tls-working

commit a33e32f
Author: Oscar Knagg <[email protected]>
Date:   Tue Oct 12 13:33:51 2021 +0100

    Fix bad import

commit 263e8f6
Author: Oscar Knagg <[email protected]>
Date:   Tue Oct 12 12:57:41 2021 +0100

    Add TLS configuration to ray_config_def.h

commit 425ce87
Author: Oscar Knagg <[email protected]>
Date:   Tue Oct 12 12:57:17 2021 +0100

    Formatting

commit b510a7b
Author: Oscar Knagg <[email protected]>
Date:   Mon Oct 11 15:48:54 2021 +0100

    Move tests into separate file

commit 97df185
Author: Oscar Knagg <[email protected]>
Date:   Mon Oct 11 14:09:25 2021 +0100

    load_certs_from_env -> tls_utils

commit fb1b05c
Author: Oscar Knagg <[email protected]>
Date:   Mon Oct 11 14:08:09 2021 +0100

    Docs v1

commit 9e95bb1
Author: Oscar Knagg <[email protected]>
Date:   Mon Oct 11 11:52:17 2021 +0100

    tls_utils file

commit 8596893
Merge: d04fe6d ab55b80
Author: Oscar Knagg <[email protected]>
Date:   Mon Oct 11 11:46:07 2021 +0100

    Merge branch 'master' of https://github.com/ray-project/ray into tls
  • Loading branch information
oscarknagg committed Oct 12, 2021
commit 78bbb341c605b6ffda2c66c6b25c99ac08d58917
57 changes: 16 additions & 41 deletions dashboard/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import traceback

from grpc.experimental import aio as aiogrpc
from distutils.version import LooseVersion

import ray
import ray.dashboard.consts as dashboard_consts
Expand Down Expand Up @@ -84,7 +83,7 @@ def __init__(self,
assert self.ppid > 0
logger.info("Parent pid is %s", self.ppid)
self.server = aiogrpc.server(options=(("grpc.so_reuseport", 0), ))
self.grpc_port = ray._private.utils.add_port_to_grpc_server(
self.grpc_port = ray._private.tls_utils.add_port_to_grpc_server(
self.server, f"[::]:{self.dashboard_agent_port}")
logger.info("Dashboard agent grpc address: %s:%s", self.ip,
self.grpc_port)
Expand Down Expand Up @@ -144,12 +143,8 @@ async def _check_parent():
sys.exit(-1)

# Create a http session for all modules.
# aiohttp<4.0.0 uses a 'loop' variable, aiohttp>=4.0.0 doesn't anymore
if LooseVersion(aiohttp.__version__) < LooseVersion("4.0.0"):
self.http_session = aiohttp.ClientSession(
loop=asyncio.get_event_loop())
else:
self.http_session = aiohttp.ClientSession()
self.http_session = aiohttp.ClientSession(
loop=asyncio.get_event_loop())

# Start a grpc asyncio server.
await self.server.start()
Expand Down Expand Up @@ -342,8 +337,8 @@ async def _check_parent():
# https://github.com/ray-project/ray/issues/14026.
if sys.platform == "win32":
logger.warning(
"The dashboard is currently disabled on windows. "
"See https://github.com/ray-project/ray/issues/14026 "
"The dashboard is currently disabled on windows."
"See https://github.com/ray-project/ray/issues/14026"
"for more details")
while True:
time.sleep(999)
Expand All @@ -367,34 +362,14 @@ async def _check_parent():
loop = asyncio.get_event_loop()
loop.run_until_complete(agent.run())
except Exception as e:
# All these env vars should be available because
# they are provided by the parent raylet.
restart_count = os.environ["RESTART_COUNT"]
max_restart_count = os.environ["MAX_RESTART_COUNT"]
raylet_pid = os.environ["RAY_RAYLET_PID"]
node_ip = args.node_ip_address
if restart_count >= max_restart_count:
# Agent is failed to be started many times.
# Push an error to all drivers, so that users can know the
# impact of the issue.
redis_client = ray._private.services.create_redis_client(
args.redis_address, password=args.redis_password)
traceback_str = ray._private.utils.format_error_message(
traceback.format_exc())
message = (
f"(ip={node_ip}) "
f"The agent on node {platform.uname()[1]} failed to "
f"be restarted {max_restart_count} "
"times. There are 3 possible problems if you see this error."
"\n 1. The dashboard might not display correct "
"information on this node."
"\n 2. Metrics on this node won't be reported."
"\n 3. runtime_env APIs won't work."
"\nCheck out the `dashboard_agent.log` to see the "
"detailed failure messages.")
ray._private.utils.push_error_to_driver_through_redis(
redis_client, ray_constants.DASHBOARD_AGENT_DIED_ERROR,
message)
logger.error(message)
logger.exception(e)
exit(1)
# Something went wrong, so push an error to all drivers.
redis_client = ray._private.services.create_redis_client(
args.redis_address, password=args.redis_password)
traceback_str = ray._private.utils.format_error_message(
traceback.format_exc())
message = ("The agent on node {} failed with the following "
"error:\n{}".format(platform.uname()[1], traceback_str))
ray._private.utils.push_error_to_driver_through_redis(
redis_client, ray_constants.DASHBOARD_AGENT_DIED_ERROR, message)
logger.exception(message)
raise e
2 changes: 1 addition & 1 deletion dashboard/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(self, http_host, http_port, http_port_retries, redis_address,
ip, port = redis_address.split(":")
self.gcs_client = connect_to_gcs(ip, int(port), redis_password)
self.server = aiogrpc.server(options=(("grpc.so_reuseport", 0), ))
self.grpc_port = ray._private.utils.add_port_to_grpc_server(
self.grpc_port = ray._private.tls_utils.add_port_to_grpc_server(
self.server, "[::]:0")
logger.info("Dashboard head grpc address: %s:%s", self.ip,
self.grpc_port)
Expand Down
22 changes: 22 additions & 0 deletions doc/source/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ to localhost when the ray is started using ``ray.init``.
See the `Redis security documentation <https://redis.io/topics/security>`__
for more information.

TLS Authentication
------------------

Ray can be configured to use TLS on it's gRPC channels.
This has means that connecting to the Ray client on the head node will
require an appropriate set of credentials and also that data exchanged between
various processes (client, head, workers) will be encrypted.

Enabling TLS will cause a performance hit due to the extra overhead of mutual
authentication and encryption.
Testing has shown that this overhead is large for small workloads and becomes
relatively smaller for large workloads.
The exact overhead will depend on the nature of your workload.

TLS is enabled by setting environment variables.

- ``RAY_USE_TLS``: Either 1 or 0 to use/not-use TLS. If this is set to 1 then all of the environment variables below must be set. Default: 0.
- ``RAY_TLS_SERVER_CERT``: Location of a `certificate file` which is presented to other endpoints so as to achieve mutual authentication.
- ``RAY_TLS_SERVER_KEY``: Location of a `private key file` which is the cryptographic means to prove to other endpoints that you are the authorized user of a given certificate.
- ``RAY_TLS_CA_CERT``: Location of a `CA certificate file` which allows TLS to decide whether an endpoint's certificate has been signed by the correct authority.


Java Applications
-----------------

Expand Down
68 changes: 8 additions & 60 deletions python/ray/_private/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
import pathlib
import subprocess
import sys
import tempfile
import time
import timeit
import math
import traceback
import datetime
from typing import Optional, Any, List, Dict
from contextlib import redirect_stdout, redirect_stderr
import yaml
import socket
import pytest
import tempfile

import ray
import ray._private.services
import ray._private.utils
import ray._private.gcs_utils as gcs_utils
from ray._private.tls_utils import generate_self_signed_tls_certs
from ray.util.queue import Queue, _QueueActor, Empty
from ray.scripts.scripts import main as ray_main

try:
from prometheus_client.parser import text_string_to_metric_families
except (ImportError, ModuleNotFoundError):
Expand Down Expand Up @@ -690,57 +691,11 @@ async def get_batch(self,
return batch


def generate_self_signed_tls_certs():
"""Create self-signed key/cert pair for testing.

This method requires the library ``cryptography`` be installed.
"""
try:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.x509.oid import NameOID
except ImportError:
raise ImportError(
"Using `Security.temporary` requires `cryptography`, please "
"install it using either pip or conda")
key = rsa.generate_private_key(
public_exponent=65537, key_size=2048, backend=default_backend())
key_contents = key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
).decode()

ray_interal = x509.Name(
[x509.NameAttribute(NameOID.COMMON_NAME, "ray-internal")])
# This is the same logic used by the GCS server to acquire a
# private/interal IP address to listen on. If we just use localhost +
# 127.0.0.1 then we won't be able to connect to the GCS and will get
# an error like "No match found for server name: 192.168.X.Y"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
private_ip_address = s.getsockname()[0]
s.close()
altnames = x509.SubjectAlternativeName([
x509.DNSName(socket.gethostbyname(
socket.gethostname())), # Probably 127.0.0.1
x509.DNSName("127.0.0.1"),
x509.DNSName(private_ip_address), # 192.168.*.*
x509.DNSName("localhost"),
])
now = datetime.datetime.utcnow()
cert = (x509.CertificateBuilder()
.subject_name(ray_interal).issuer_name(ray_interal).add_extension(
altnames, critical=False).public_key(key.public_key())
.serial_number(x509.random_serial_number()).not_valid_before(now)
.not_valid_after(now + datetime.timedelta(days=365)).sign(
key, hashes.SHA256(), default_backend()))

cert_contents = cert.public_bytes(serialization.Encoding.PEM).decode()

return cert_contents, key_contents
def is_placement_group_removed(pg):
table = ray.util.placement_group_table(pg)
if "state" not in table:
return False
return table["state"] == "REMOVED"


def setup_tls():
Expand Down Expand Up @@ -772,10 +727,3 @@ def teardown_tls(key_filepath, cert_filepath, temp_dir):
del os.environ["RAY_TLS_SERVER_CERT"]
del os.environ["RAY_TLS_SERVER_KEY"]
del os.environ["RAY_TLS_CA_CERT"]


def is_placement_group_removed(pg):
table = ray.util.placement_group_table(pg)
if "state" not in table:
return False
return table["state"] == "REMOVED"
85 changes: 85 additions & 0 deletions python/ray/_private/tls_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import datetime
import os
import socket

import grpc


def generate_self_signed_tls_certs():
"""Create self-signed key/cert pair for testing.

This method requires the library ``cryptography`` be installed.
"""
try:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.x509.oid import NameOID
except ImportError:
raise ImportError(
"Using `Security.temporary` requires `cryptography`, please "
"install it using either pip or conda")
key = rsa.generate_private_key(
public_exponent=65537, key_size=2048, backend=default_backend())
key_contents = key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
).decode()

ray_interal = x509.Name(
[x509.NameAttribute(NameOID.COMMON_NAME, "ray-internal")])
# This is the same logic used by the GCS server to acquire a
# private/interal IP address to listen on. If we just use localhost +
# 127.0.0.1 then we won't be able to connect to the GCS and will get
# an error like "No match found for server name: 192.168.X.Y"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
private_ip_address = s.getsockname()[0]
s.close()
altnames = x509.SubjectAlternativeName([
x509.DNSName(socket.gethostbyname(
socket.gethostname())), # Probably 127.0.0.1
x509.DNSName("127.0.0.1"),
x509.DNSName(private_ip_address), # 192.168.*.*
x509.DNSName("localhost"),
])
now = datetime.datetime.utcnow()
cert = (x509.CertificateBuilder().subject_name(ray_interal).issuer_name(
ray_interal).add_extension(altnames, critical=False).public_key(
key.public_key()).serial_number(
x509.random_serial_number()).not_valid_before(now)
.not_valid_after(now + datetime.timedelta(days=365)).sign(
key, hashes.SHA256(), default_backend()))

cert_contents = cert.public_bytes(serialization.Encoding.PEM).decode()

return cert_contents, key_contents


def add_port_to_grpc_server(server, address):
if os.environ.get("RAY_USE_TLS", "0") == "1":
server_cert_chain, private_key, ca_cert = load_certs_from_env()
credentials = grpc.ssl_server_credentials(
[(private_key, server_cert_chain)],
root_certificates=ca_cert,
require_client_auth=ca_cert is not None)
return server.add_secure_port(address, credentials)
else:
return server.add_insecure_port(address)


def load_certs_from_env():
if os.environ.get("RAY_USE_TLS", "0") == "1":
with open(os.environ["RAY_TLS_SERVER_CERT"], "rb") as f:
server_cert_chain = f.read()
with open(os.environ["RAY_TLS_SERVER_KEY"], "rb") as f:
private_key = f.read()
if "RAY_TLS_CA_CERT" in os.environ:
with open(os.environ["RAY_TLS_CA_CERT"], "rb") as f:
ca_cert = f.read()
else:
ca_cert = None

return server_cert_chain, private_key, ca_cert
28 changes: 1 addition & 27 deletions python/ray/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import ray
import ray._private.gcs_utils as gcs_utils
import ray.ray_constants as ray_constants
from ray._private.tls_utils import load_certs_from_env

# Import psutil after ray so the packaged version is used.
import psutil
Expand Down Expand Up @@ -1111,21 +1112,6 @@ def validate_namespace(namespace: str):
"Pass None to not specify a namespace.")


def load_certs_from_env():
if os.environ.get("RAY_USE_TLS", "0") == "1":
with open(os.environ["RAY_TLS_SERVER_CERT"], "rb") as f:
server_cert_chain = f.read()
with open(os.environ["RAY_TLS_SERVER_KEY"], "rb") as f:
private_key = f.read()
if "RAY_TLS_CA_CERT" in os.environ:
with open(os.environ["RAY_TLS_CA_CERT"], "rb") as f:
ca_cert = f.read()
else:
ca_cert = None

return server_cert_chain, private_key, ca_cert


def init_grpc_channel(address: str,
options: Optional[Sequence[Tuple[str, Any]]] = None,
asynchronous: bool = False):
Expand All @@ -1142,15 +1128,3 @@ def init_grpc_channel(address: str,
channel = grpc_module.insecure_channel(address, options=options)

return channel


def add_port_to_grpc_server(server, address):
if os.environ.get("RAY_USE_TLS", "0") == "1":
server_cert_chain, private_key, ca_cert = load_certs_from_env()
credentials = grpc.ssl_server_credentials(
[(private_key, server_cert_chain)],
root_certificates=ca_cert,
require_client_auth=ca_cert is not None)
return server.add_secure_port(address, credentials)
else:
return server.add_insecure_port(address)
Loading