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

Add TLS config #6035

Merged
merged 4 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 7 additions & 1 deletion aerospike/datadog_checks/aerospike/aerospike.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def __init__(self, name, init_config, instances):
port = int(self.instance.get('port', 3000))
tls_name = self.instance.get('tls_name')
self._host = (host, port, tls_name) if tls_name else (host, port)
self._tls_config = self.instance.get('tls_config', None)
hithwen marked this conversation as resolved.
Show resolved Hide resolved
if self._tls_config:
self._tls_config['enable'] = True

# https://www.aerospike.com/apidocs/python/client.html#aerospike.Client.connect
self._username = self.instance.get('username')
Expand Down Expand Up @@ -198,8 +201,11 @@ def get_datacenters(self):
return datacenters

def get_client(self):
client_config = {'hosts': [self._host]}
if self._tls_config:
client_config['tls'] = self._tls_config
AlexandreYang marked this conversation as resolved.
Show resolved Hide resolved
try:
client = aerospike.client({'hosts': [self._host]}).connect(self._username, self._password)
client = aerospike.client(client_config).connect(self._username, self._password)
except Exception as e:
self.log.error('Unable to connect to database: %s', e)
self.service_check(SERVICE_CHECK_CONNECT, self.CRITICAL, tags=self._tags)
Expand Down
24 changes: 24 additions & 0 deletions aerospike/datadog_checks/aerospike/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,33 @@ instances:
## @param tls_name - string - optional
## This must match the tls-name specified in the node’s server
## configuration file and match the server’s CA certificate.
##
## Note: TLS usage requires Aerospike Enterprise Edition
#
# tls_name: <TLS_NAME>

tls a dict of optional TLS configuration parameters.
AlexandreYang marked this conversation as resolved.
Show resolved Hide resolved

## @param tls_config - list of key:value elements - optional
## Note TLS usage requires Aerospike Enterprise Edition
## Key value pairs with a choice of the following elements:
##
## cafile: Path to a trusted CA certificate file. By default TLS will use system standard trusted CA certificates
## capath: Path to a directory of trusted certificates.
## protocols: Specifies enabled protocols. If not specified the client will use “-all +TLSv1.2”.
## cipher_suite: Specifies enabled cipher suites. Defaults to the OpenSSL default cipher suite.
## keyfile: Path to the client’s key for mutual authentication. By default mutual authentication is disabled.
## keyfile_pw: Decryption password for the client’s key for mutual authentication. By default the key is assumed not to be encrypted.
## cert_blacklist: Path to a certificate blacklist file.
## certfile: Path to the client’s certificate chain file for mutual authentication. By default mutual authentication is disabled.
## crl_check: (True, False) Enable CRL checking for the certificate chain leaf certificate. An error occurs if a suitable CRL cannot be found. By default CRL checking is disabled.
## crl_check_all: (True, False): Enable CRL checking for the entire certificate chain. An error occurs if a suitable CRL cannot be found. By default CRL checking is disabled.
#
# tls_config:
# cafile: <CA_FILE>
# certfile: <CERT_FILE>
# keyfile: <KEY_FILE>

## @param timeout - integer - optional - default: 10
## The read timeout in seconds.
#
Expand Down
17 changes: 17 additions & 0 deletions aerospike/tests/test_unit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import copy

import mock
import pytest

Expand Down Expand Up @@ -46,3 +48,18 @@ def mock_get_info(command, separator=";"):
check.check(common.INSTANCE)
for metric in METRICS:
aggregator.assert_metric(metric)


def connection_uses_tls():
instance = copy.deepcopy(common.INSTANCE)
tls_config = {'cafile': 'my-ca-file', 'certfile': 'my-certfile', 'keyfile': 'my-keyfile'}
instance['tls_config'] = copy.deepcopy(tls_config)

check = aerospike.AerospikeCheck('aerospike', {}, [common.INSTANCE])
tls_config['enable'] = True

assert check._tls_config == tls_config

with mock.patch('aerospike.client') as client:
check.get_client()
assert client.called_with({'host': check._host, 'tls': tls_config})