-
-
Notifications
You must be signed in to change notification settings - Fork 266
Remote server tls authentication #1885
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
base: master
Are you sure you want to change the base?
Changes from all commits
b1d507c
474dfb9
85e45c7
a9a4120
c6d1da1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| import asyncio | ||
| import platform | ||
| import subprocess | ||
| import time | ||
| import enum | ||
| import random | ||
| import re | ||
| import string | ||
| import logging | ||
| from argparse import Namespace | ||
| from datetime import datetime | ||
| from fnmatch import fnmatchcase | ||
|
|
||
| from typing import Optional | ||
| import attr | ||
| import grpc | ||
|
|
||
| from .generated import labgrid_coordinator_pb2 | ||
|
|
||
|
|
@@ -58,6 +62,59 @@ def build_dict_from_map(m): | |
| return d | ||
|
|
||
|
|
||
| def _fetch_root_certificates_darwin(): | ||
| try: | ||
| p = subprocess.run( | ||
| ["security", "find-certificate", "-a", "-p"], | ||
| capture_output=True, | ||
| timeout=10, | ||
| ) | ||
| if p.returncode != 0 or not p.stdout: | ||
| return None | ||
| return p.stdout | ||
| except Exception: | ||
| logging.exception("unexpected error when fetching certificates from macOS Keychain") | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def _fetch_root_certificates_linux(): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On why this is needed. the certificate precedence is (src/core/credentials/transport/tls/ssl_utils.cc @ ComputePemRootCerts) the cb is set at src/python/grpcio/grpc/_cython/cygrpc.pyx The only options are indeed GRPC_DEFAULT_SSL_ROOTS_FILE_PATH or as the argument value. the grpc defaults for linux are (https://github.com/grpc/grpc/blob/master/src/core/credentials/transport/tls/load_system_roots_supported.cc#L48-L62) I wouldn't have one of the default here, but just document that it will default to the bundled roots.pem if not explicitly set through the env or as the argument value.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @gastmaier I think the important Python bit here is that grpcio installs a roots override callback which loads its bundled So I think the correct ordering for Labgrid should be:
I'll update the getting_started docs to represent this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hacking |
||
| ca_bundle_path = "/etc/ssl/certs/ca-certificates.crt" | ||
| try: | ||
| # TODO: Current supports Debian/Ubuntu. Extend to support other distributions. | ||
| with open(ca_bundle_path, "rb") as f: | ||
| certs = f.read() | ||
| if certs: | ||
| return certs | ||
| except OSError as e: | ||
| logging.warning("failed to read CA bundle at %s: %s", ca_bundle_path, e) | ||
| except Exception: | ||
| logging.exception("unexpected error while reading ca certificates") | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def _fetch_root_certificates(): | ||
| if platform.system() == "Darwin": | ||
| return _fetch_root_certificates_darwin() | ||
|
|
||
| if platform.system() == "Linux": | ||
| return _fetch_root_certificates_linux() | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def get_client_credentials(args: Namespace) -> Optional[grpc.ChannelCredentials]: | ||
| if not args.tls: | ||
| return None | ||
|
|
||
| if not args.cert: | ||
| return grpc.ssl_channel_credentials(root_certificates=_fetch_root_certificates()) | ||
|
|
||
| with open(args.cert, "rb") as fc: | ||
| return grpc.ssl_channel_credentials(root_certificates=fc.read()) | ||
|
|
||
|
|
||
| @attr.s(eq=False) | ||
| class ResourceEntry: | ||
| data = attr.ib() # cls, params | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain roots.pem and GRPC_DEFAULT_SSL_ROOTS_FILE_PATH precedence here, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated