mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Improve behaviour of the insecure option (#2476)
It didn't worked correctly when client certificates are used for REST API requests.
This commit is contained in:
+10
-3
@@ -9,9 +9,9 @@ from .utils import USER_AGENT
|
|||||||
|
|
||||||
class PatroniRequest(object):
|
class PatroniRequest(object):
|
||||||
|
|
||||||
def __init__(self, config, insecure=False):
|
def __init__(self, config, insecure=None):
|
||||||
cert_reqs = 'CERT_NONE' if insecure or config.get('ctl', {}).get('insecure', False) else 'CERT_REQUIRED'
|
self._insecure = insecure
|
||||||
self._pool = urllib3.PoolManager(num_pools=10, maxsize=10, cert_reqs=cert_reqs)
|
self._pool = urllib3.PoolManager(num_pools=10, maxsize=10)
|
||||||
self.reload_config(config)
|
self.reload_config(config)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -32,12 +32,19 @@ class PatroniRequest(object):
|
|||||||
def reload_config(self, config):
|
def reload_config(self, config):
|
||||||
self._pool.headers = urllib3.make_headers(basic_auth=self._get_cfg_value(config, 'auth'), user_agent=USER_AGENT)
|
self._pool.headers = urllib3.make_headers(basic_auth=self._get_cfg_value(config, 'auth'), user_agent=USER_AGENT)
|
||||||
|
|
||||||
|
insecure = self._insecure if isinstance(self._insecure, bool) else config.get('ctl', {}).get('insecure', False)
|
||||||
if self._apply_ssl_file_param(config, 'cert'):
|
if self._apply_ssl_file_param(config, 'cert'):
|
||||||
|
# With client certificate the cert_reqs must be set to CERT_REQUIRED even if insecure option is used
|
||||||
|
self._pool.connection_pool_kw['cert_reqs'] = 'CERT_REQUIRED'
|
||||||
|
# The assert_hostname = False helps to silence warnings
|
||||||
|
self._pool.connection_pool_kw['assert_hostname'] = False if insecure else None
|
||||||
|
|
||||||
self._apply_ssl_file_param(config, 'key')
|
self._apply_ssl_file_param(config, 'key')
|
||||||
|
|
||||||
password = self._get_cfg_value(config, 'keyfile_password')
|
password = self._get_cfg_value(config, 'keyfile_password')
|
||||||
self._apply_pool_param('key_password', password)
|
self._apply_pool_param('key_password', password)
|
||||||
else:
|
else:
|
||||||
|
self._pool.connection_pool_kw['cert_reqs'] = 'CERT_NONE' if insecure else 'CERT_REQUIRED'
|
||||||
self._pool.connection_pool_kw.pop('key_file', None)
|
self._pool.connection_pool_kw.pop('key_file', None)
|
||||||
|
|
||||||
cacert = config.get('ctl', {}).get('cacert') or config.get('restapi', {}).get('cafile')
|
cacert = config.get('ctl', {}).get('cacert') or config.get('restapi', {}).get('cafile')
|
||||||
|
|||||||
+6
-4
@@ -5,16 +5,18 @@ name: postgresql0
|
|||||||
restapi:
|
restapi:
|
||||||
listen: 127.0.0.1:8008
|
listen: 127.0.0.1:8008
|
||||||
connect_address: 127.0.0.1:8008
|
connect_address: 127.0.0.1:8008
|
||||||
|
# cafile: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
||||||
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
||||||
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
||||||
# authentication:
|
# authentication:
|
||||||
# username: username
|
# username: username
|
||||||
# password: password
|
# password: password
|
||||||
|
|
||||||
# ctl:
|
#ctl:
|
||||||
# insecure: false # Allow connections to SSL sites without certs
|
# insecure: false # Allow connections to Patroni REST API without verifying certificates
|
||||||
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
||||||
# cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
||||||
|
# cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
||||||
|
|
||||||
etcd:
|
etcd:
|
||||||
#Provide host to do the initial discovery of the cluster topology:
|
#Provide host to do the initial discovery of the cluster topology:
|
||||||
|
|||||||
+6
-4
@@ -5,16 +5,18 @@ name: postgresql1
|
|||||||
restapi:
|
restapi:
|
||||||
listen: 127.0.0.1:8009
|
listen: 127.0.0.1:8009
|
||||||
connect_address: 127.0.0.1:8009
|
connect_address: 127.0.0.1:8009
|
||||||
|
# cafile: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
||||||
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
||||||
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
||||||
# authentication:
|
# authentication:
|
||||||
# username: username
|
# username: username
|
||||||
# password: password
|
# password: password
|
||||||
|
|
||||||
# ctl:
|
#ctl:
|
||||||
# insecure: false # Allow connections to SSL sites without certs
|
# insecure: false # Allow connections to Patroni REST API without verifying certificates
|
||||||
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
||||||
# cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
||||||
|
# cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
||||||
|
|
||||||
etcd:
|
etcd:
|
||||||
#Provide host to do the initial discovery of the cluster topology:
|
#Provide host to do the initial discovery of the cluster topology:
|
||||||
|
|||||||
+6
-4
@@ -5,16 +5,18 @@ name: postgresql2
|
|||||||
restapi:
|
restapi:
|
||||||
listen: 127.0.0.1:8010
|
listen: 127.0.0.1:8010
|
||||||
connect_address: 127.0.0.1:8010
|
connect_address: 127.0.0.1:8010
|
||||||
|
# cafile: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
||||||
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
||||||
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
||||||
authentication:
|
authentication:
|
||||||
username: username
|
username: username
|
||||||
password: password
|
password: password
|
||||||
|
|
||||||
# ctl:
|
#ctl:
|
||||||
# insecure: false # Allow connections to SSL sites without certs
|
# insecure: false # Allow connections to Patroni REST API without verifying certificates
|
||||||
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
||||||
# cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
|
||||||
|
# cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem
|
||||||
|
|
||||||
etcd:
|
etcd:
|
||||||
#Provide host to do the initial discovery of the cluster topology:
|
#Provide host to do the initial discovery of the cluster topology:
|
||||||
|
|||||||
Reference in New Issue
Block a user