Skip to content

Commit

Permalink
#389 - Have PikaClient use client certs if present (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-taubman authored Apr 11, 2022
1 parent 675b521 commit 505b7e7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '2.7', '3.6', '3.7', '3.8', '3.9']
python-version: [ '3.7', '3.8', '3.9' ]
# Can't use ubuntu-latest until Python 3.4 has Ubuntu 20.X install options in setup-python@v2
os: ['ubuntu-18.04']
name: PyTests OS ${{ matrix.os }} - Python ${{ matrix.python-version }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ target/
# Jupyter
.ipydb_checkpoints/
*.ipynb

# Vim
*.swp
5 changes: 5 additions & 0 deletions brewtils/pika.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(
ssl = ssl or {}
self._ssl_options = None
self._ssl_enabled = ssl.get("enabled", False)
self._ssl_client_cert = ssl.get("client_cert")

if self._ssl_enabled:
ssl_context = pyssl.create_default_context(cafile=ssl.get("ca_cert", None))
Expand All @@ -80,6 +81,10 @@ def __init__(
else:
ssl_context.check_hostname = False
ssl_context.verify_mode = pyssl.CERT_NONE

if self._ssl_client_cert:
ssl_context.load_cert_chain(self._ssl_client_cert)

self._ssl_options = SSLOptions(ssl_context, server_hostname=self._host)

# Save the 'normal' params so they don't need to be reconstructed
Expand Down
19 changes: 11 additions & 8 deletions brewtils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ class Plugin(object):
authority that issued the Beer-garden server certificate
ca_verify (bool): Whether to verify Beer-garden server certificate
client_cert (str): Path to client certificate to use when communicating with
Beer-garden
Beer-garden. NOTE: This is required to be a cert / key bundle if SSL/TLS is
enabled for rabbitmq in your environment.
client_key (str): Path to client key. Not necessary if client_cert is a bundle.
api_version (int): Beer-garden API version to use
client_timeout (int): Max time to wait for Beer-garden server response
username (str): Username for Beer-garden authentication
Expand Down Expand Up @@ -531,13 +533,14 @@ def _initialize_processors(self):
# values specified at plugin creation
connection_info = self._instance.queue_info["connection"]
if "ssl" in connection_info:
connection_info["ssl"].update(
{
"ca_cert": self._config.ca_cert,
"ca_verify": self._config.ca_verify,
"client_cert": self._config.client_cert,
}
)
if self._config.ca_verify:
connection_info["ssl"]["ca_verify"] = self._config.ca_verify

if self._config.ca_cert:
connection_info["ssl"]["ca_cert"] = self._config.ca_cert

if self._config.client_cert:
connection_info["ssl"]["client_cert"] = self._config.client_cert

# Each RequestProcessor needs a RequestConsumer, so start with those
common_args = {
Expand Down
8 changes: 7 additions & 1 deletion brewtils/test/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
import pytz

from brewtils.models import (
Choices,
Command,
Expand Down Expand Up @@ -215,7 +216,12 @@ def instance_dict(ts_epoch):
"user": "guest",
"password": "guest",
"virtual_host": "/",
"ssl": {"enabled": False},
"ssl": {
"enabled": False,
"ca_verify": False,
"client_cert": "/path/to/cert",
"ca_cert": "/path/to/cacert",
},
},
"url": "amqp://guest:guest@localhost:5672",
},
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ universal = 1
[flake8]
max-line-length = 100
ignore = E203,W503

[isort]
profile = black
known_first_party = brewtils

0 comments on commit 505b7e7

Please sign in to comment.