pg.ddx.io patroni/patroni GitHub issues and pull requests
help / color / mirror / Atom feed[patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
42+ messages / 4 participants
[nested] [flat]
* [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 03:25 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
0 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-05-08 03:25 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
## Summary
Patroni currently exposes `ctl.insecure: true` and `restapi.verify_client: none` for relaxing TLS verification on the REST API and control tool, but provides no equivalent for the DCS (etcd / etcd3) backend. Users with internal PKI, legacy SAN-less certificates, or etcd `--auto-tls` deployments have no in-config way to relax TLS verification short of patching site-packages directly.
This PR adds three opt-in flags under the `etcd:` and `etcd3:` config sections, mirroring the existing pattern for `restapi`/`ctl`:
- `verify` — disable CA chain validation (last resort, e.g. for `--auto-tls`)
- `verify_hostname` — keep CA validation, skip hostname/SAN check
- `hostname_checks_common_name` — accept CN-only certs (legacy PKI)
All flags default to the secure value; existing configs are unaffected. A `WARNING` is logged at startup whenever a flag is relaxed, so the security state is visible in operational logs.
## Why
Many production Patroni deployments connect to etcd over HTTPS using one of these configurations:
etcd --auto-tls — etcd generates a fresh self-signed certificate at every startup. There is no CA file to provide, so Patroni's cacert: parameter cannot help. The TLS handshake always fails certificate validation.
Internal PKI with legacy certificates — certificates issued by an internal CA but without Subject Alternative Name (SAN) entries. Modern Python (urllib3 v2+) dropped the CN fallback and only checks SAN, so these certificates fail hostname validation even when the CA is trusted.
Internal PKI with hostname/IP mismatch — certificates with valid SANs, but the SANs contain DNS names while Patroni connects via IP (or vice versa). Verification fails on identity, not on trust.
In all three cases, Patroni cannot connect to etcd. The DCS backend is unavailable, leader election cannot run, and the cluster cannot form. Because there is no configuration flag to relax verification for the DCS layer specifically, the only working option today is to modify Patroni's installed source files directly — a change that is invisible to configuration management, is silently lost on every upgrade, and affects urllib3 globally across the entire process.
## Design
The change is intentionally minimal:
1. **One new file:** `patroni/dcs/etcd_tls.py` (helper)
2. **Two added lines** in `patroni/dcs/etcd.py` (import + hook call)
3. **No changes** to `patroni/dcs/etcd3.py` — `Etcd3Client` inherits
from `AbstractEtcdClientWithFailover` and the fix flows down via
`super().__init__()`.
Scoping principles:
- No global urllib3 mutation. The helper modifies the etcd client's
`PoolManager` in place via `connection_pool_kw`.
- No silenced warnings. urllib3's `InsecureRequestWarning` is left
alone. The helper logs one WARNING at startup describing the
relaxation.
- No retry-semantics changes. TLS configuration only.
- Backward-compatible: zero behavior change for users who don't
set any new flag.
## FIPS compatibility
The helper uses only stdlib `ssl` module functions
(`create_default_context`, `_create_unverified_context`). It does not
override cipher selection or TLS minimum versions, and it does not
bypass OpenSSL's FIPS provider.
On FIPS-validated OpenSSL builds where
`SSLContext.hostname_checks_common_name` is read-only, the helper
detects this via a probe and raises `RuntimeError` at startup with a
clear message directing the user to `verify_hostname=false` instead.
This degraded behavior is tested.
## Related
Multiple long-standing issues document this gap:
- #384 (2017) — self-signed certs, closed by pointing to `cacert:` workaround
- #2036 (2021) — etcd v3 + TLS Common Name, marked unsupported
- #2433 (2022) — `CERTIFICATE_VERIFY_FAILED` from `patronictl`, fixed
for ctl/restapi but not DCS
- etcd-io/etcd#15945 (2023) — Patroni connecting to etcd with TLS
inline patch 1: docs/ENVIRONMENT.rst, docs/yaml_configuration.rst, patroni/config.py and 7 more (+299/-6 lines) download inline-1.patch
diff --git a/docs/ENVIRONMENT.rst b/docs/ENVIRONMENT.rst
index 7dccd9fdfa..7ffcaab8c5 100644
--- a/docs/ENVIRONMENT.rst
+++ b/docs/ENVIRONMENT.rst
@@ -83,6 +83,9 @@ Etcd
- **PATRONI\_ETCD\_CACERT**: The ca certificate. If present it will enable validation.
- **PATRONI\_ETCD\_CERT**: File with the client certificate.
- **PATRONI\_ETCD\_KEY**: File with the client key. Can be empty if the key is part of certificate.
+- **PATRONI\_ETCD\_VERIFY**: whether to verify the etcd server's TLS certificate. Defaults to ``true``. Set to ``false`` to disable certificate and hostname verification entirely.
+- **PATRONI\_ETCD\_VERIFY\_HOSTNAME**: whether to verify that the certificate matches the host/IP being connected to. Defaults to ``true``. Set to ``false`` to keep CA-chain validation but skip the hostname check.
+- **PATRONI\_ETCD\_HOSTNAME\_CHECKS\_COMMON\_NAME**: whether to allow matching the certificate Common Name when it has no Subject Alternative Name. Set to ``true`` to enable Common Name fallback where supported, or ``false`` to enforce SAN-only.
Etcdv3
------
diff --git a/docs/yaml_configuration.rst b/docs/yaml_configuration.rst
index ad3ec63028..acf76d3012 100644
--- a/docs/yaml_configuration.rst
+++ b/docs/yaml_configuration.rst
@@ -146,6 +146,9 @@ Most of the parameters are optional, but you have to specify one of the **host**
- **cacert**: (optional) The ca certificate. If present it will enable validation.
- **cert**: (optional) file with the client certificate.
- **key**: (optional) file with the client key. Can be empty if the key is part of **cert**.
+- **verify**: (optional) whether to verify the etcd server's TLS certificate. Defaults to ``true``. Set to ``false`` to disable certificate and hostname verification entirely (insecure; intended only as a temporary measure, e.g. for etcd running with ``--auto-tls``).
+- **verify_hostname**: (optional) whether to verify that the certificate matches the host/IP being connected to. Defaults to ``true``. Set to ``false`` to keep CA-chain validation but skip the hostname/SAN identity check.
+- **hostname_checks_common_name**: (optional) whether to allow matching the certificate Common Name when it has no Subject Alternative Name. If unset, the installed urllib3's default behavior is preserved. Set to ``true`` to enable Common Name fallback where the TLS backend supports it, or ``false`` to enforce SAN-only verification.
Etcdv3
------
diff --git a/patroni/config.py b/patroni/config.py
index 1b8df5811b..067d51f91f 100644
--- a/patroni/config.py
+++ b/patroni/config.py
@@ -681,7 +681,8 @@ def _get_auth(name: str, params: Collection[str] = _AUTH_ALLOWED_PARAMETERS[:2])
# PATRONI_(ETCD|CONSUL|ZOOKEEPER|EXHIBITOR|...)_(HOSTS?|PORT|..)
name, suffix = (param[len(PATRONI_ENV_PREFIX):].split('_', 1) + [''])[:2]
if suffix in ('HOST', 'HOSTS', 'PORT', 'USE_PROXIES', 'PROTOCOL', 'SRV', 'SRV_SUFFIX', 'URL', 'PROXY',
- 'CACERT', 'CERT', 'KEY', 'VERIFY', 'TOKEN', 'CHECKS', 'DC', 'CONSISTENCY',
+ 'CACERT', 'CERT', 'KEY', 'VERIFY', 'VERIFY_HOSTNAME',
+ 'HOSTNAME_CHECKS_COMMON_NAME', 'TOKEN', 'CHECKS', 'DC', 'CONSISTENCY',
'REGISTER_SERVICE', 'SERVICE_CHECK_INTERVAL', 'SERVICE_CHECK_TLS_SERVER_NAME',
'SERVICE_TAGS', 'NAMESPACE', 'CONTEXT', 'USE_ENDPOINTS', 'SCOPE_LABEL', 'ROLE_LABEL',
'POD_IP', 'PORTS', 'LABELS', 'BYPASS_API_SERVICE', 'RETRIABLE_HTTP_CODES', 'KEY_PASSWORD',
@@ -699,7 +700,8 @@ def _get_auth(name: str, params: Collection[str] = _AUTH_ALLOWED_PARAMETERS[:2])
value = value and _parse_list(value)
elif suffix in ('LABELS', 'SET_ACLS', 'AUTH_DATA', 'BOOTSTRAP_LABELS'):
value = _parse_dict(value)
- elif suffix in ('USE_PROXIES', 'REGISTER_SERVICE', 'USE_ENDPOINTS', 'BYPASS_API_SERVICE', 'VERIFY'):
+ elif suffix in ('USE_PROXIES', 'REGISTER_SERVICE', 'USE_ENDPOINTS', 'BYPASS_API_SERVICE',
+ 'VERIFY', 'VERIFY_HOSTNAME', 'HOSTNAME_CHECKS_COMMON_NAME'):
value = parse_bool(value)
if value is not None:
ret[name.lower()][suffix.lower()] = value
diff --git a/patroni/dcs/etcd.py b/patroni/dcs/etcd.py
index d13f031a68..2dcf07e13e 100644
--- a/patroni/dcs/etcd.py
+++ b/patroni/dcs/etcd.py
@@ -20,7 +20,8 @@
from dns import resolver
from dns.exception import DNSException
from urllib3 import Timeout
-from urllib3.exceptions import HTTPError, ProtocolError, ReadTimeoutError
+from urllib3.connection import HTTPSConnection
+from urllib3.exceptions import HTTPError, ProtocolError, ReadTimeoutError, SSLError
from ..exceptions import DCSError
from ..postgresql.mpp import AbstractMPP
@@ -138,6 +139,19 @@ def _check_cluster_raft_term(self, cluster_id: Optional[str], value: Union[None,
self._raft_term = raft_term
+class EtcdHTTPSConnectionPool(urllib3.HTTPSConnectionPool):
+ """Enforce SAN-only verification with urllib3's legacy hostname matcher."""
+
+ def _validate_conn(self, conn: HTTPSConnection) -> None:
+ super()._validate_conn(conn)
+ cert = conn.sock.getpeercert() if conn.sock is not None else None
+ # The legacy matcher only falls back to CN when there are no DNS/IP SAN entries.
+ if not cert or not any(key in ('DNS', 'IP Address') for key, _ in cert.get('subjectAltName', ())):
+ conn.close()
+ raise SSLError('Etcd TLS certificate has no DNS or IP Subject Alternative Name; '
+ 'Common Name fallback is disabled')
+
+
class AbstractEtcdClientWithFailover(abc.ABC, etcd.Client, StaleEtcdNodeGuard):
ERROR_CLS: Type[Exception]
@@ -154,6 +168,7 @@ def __init__(self, config: Dict[str, Any], dns_resolver: DnsCachingResolver, cac
# Workaround for the case when https://github.com/jplana/python-etcd/pull/196 is not applied
self.http.connection_pool_kw.pop('ssl_version', None)
self._config = config
+ self._tls_configured = False
self._load_machines_cache()
self._allow_reconnect = True
# allow passing retry argument to api_execute in params
@@ -161,6 +176,88 @@ def __init__(self, config: Dict[str, Any], dns_resolver: DnsCachingResolver, cac
self._read_options.add('retry')
self._del_conditions.add('retry')
+ def _configure_tls(self) -> None:
+ """Apply opt-in TLS verification settings for discovered HTTPS client endpoints.
+
+ With no overrides, preserve the installed urllib3's behavior.
+ If Common Name fallback cannot be enabled, log a warning and retain SAN-only verification.
+
+ Behavior matrix (verify / verify_hostname / hostname_checks_common_name)::
+
+ false / any / any -> no CA-chain or hostname verification
+ true / false / any -> CA-chain validation only; hostname check off
+ true / true / unset -> preserve python-etcd / urllib3 defaults
+ true / true / false -> CA-chain + SAN validation; no CN fallback
+ true / true / true -> CA-chain + hostname validation, allowing CN fallback
+ if supported by the TLS backend; otherwise warn and retain SAN-only
+ """
+ config = self._config
+ verify = config.get('verify', True)
+ verify_hostname = config.get('verify_hostname', True)
+ cn_fallback = config.get('hostname_checks_common_name')
+
+ # Nothing to do when everything is at its secure default: leave the
+ # stock python-etcd / urllib3 TLS setup unchanged. This also avoids
+ # building an SSLContext (and loading the platform trust store) for
+ # existing configurations that set none of these flags.
+ if verify and verify_hostname and cn_fallback is None:
+ return
+
+ pool_kw = self.http.connection_pool_kw
+
+ if not verify:
+ pool_kw['cert_reqs'] = 'CERT_NONE'
+ pool_kw['assert_hostname'] = False
+ pool_kw.pop('ca_certs', None)
+ return logger.warning('Etcd TLS certificate verification is disabled')
+
+ pool_kw['cert_reqs'] = 'CERT_REQUIRED'
+ if not verify_hostname:
+ pool_kw['assert_hostname'] = False
+ return logger.warning('Etcd TLS hostname verification is disabled')
+
+ if int(urllib3.__version__.split('.')[0]) < 2:
+ if cn_fallback:
+ return logger.warning('Etcd TLS Common Name fallback is enabled')
+ self.http.pool_classes_by_scheme = dict(self.http.pool_classes_by_scheme,
+ https=EtcdHTTPSConnectionPool)
+ return
+
+ # urllib3 2.x already enforces SAN-only verification by default.
+ # A custom context is needed only to enable CN fallback.
+ if not cn_fallback:
+ return
+
+ import ssl
+
+ from urllib3.connection import create_urllib3_context
+
+ ctx = create_urllib3_context(cert_reqs=ssl.CERT_REQUIRED)
+ # Delegate identity verification to urllib3's matcher, which honors
+ # hostname_checks_common_name on this context.
+ ctx.check_hostname = False
+ try:
+ ctx.hostname_checks_common_name = True
+ cn_fallback_enabled = ctx.hostname_checks_common_name
+ except AttributeError:
+ cn_fallback_enabled = False
+
+ if not cn_fallback_enabled:
+ return logger.warning('This TLS backend cannot enable Common Name fallback; '
+ 'retaining SAN-only verification')
+
+ # urllib3 loads explicit CA/client files from pool options.
+ # For a supplied context, load system trust ourselves.
+ if not any(pool_kw.get(key) for key in ('ca_certs', 'ca_cert_dir', 'ca_cert_data')):
+ load_default_certs = getattr(ctx, 'load_default_certs', None)
+ if not callable(load_default_certs):
+ return logger.warning('This TLS backend requires an explicit cacert '
+ 'when enabling Common Name fallback; retaining SAN-only verification')
+ load_default_certs()
+
+ pool_kw['ssl_context'] = ctx
+ logger.warning('Etcd TLS Common Name fallback is enabled')
+
def _calculate_timeouts(self, etcd_nodes: int, timeout: Optional[float] = None) -> Tuple[int, float, int]:
"""Calculate a request timeout and number of retries per single etcd node.
In case if the timeout per node is too small (less than one second) we will reduce the number of nodes.
@@ -443,6 +540,12 @@ def _load_machines_cache(self) -> bool:
if not machines_cache:
raise etcd.EtcdException
+ # Config/SRV endpoints may already be HTTPS; configure TLS before the
+ # first request so the initial contact uses the right settings.
+ if not self._tls_configured and any(urlparse(url).scheme == 'https' for url in machines_cache):
+ self._configure_tls()
+ self._tls_configured = True
+
# enforce resolving dns name,they might get new ips
self._update_dns_cache(self._dns_resolver.remove, machines_cache)
@@ -475,6 +578,13 @@ def _refresh_machines_cache(self, machines_cache: Optional[List[str]] = None) ->
if value:
ret = set(self._machines_cache) != set(value)
self._machines_cache = value
+ # Endpoints learned through member discovery may use a different
+ # protocol than the seed (e.g. an HTTP seed advertising HTTPS
+ # client URLs), so (re)configure TLS whenever an HTTPS endpoint
+ # appears and it has not been configured yet.
+ if not self._tls_configured and any(urlparse(url).scheme == 'https' for url in value):
+ self._configure_tls()
+ self._tls_configured = True
elif machines_cache: # we are just starting or all nodes were not available at some point
raise etcd.EtcdException("Could not get the list of servers, "
"maybe you provided the wrong "
diff --git a/patroni/validator.py b/patroni/validator.py
index bdaffac07a..18117c3e2d 100644
--- a/patroni/validator.py
+++ b/patroni/validator.py
@@ -1073,7 +1073,10 @@ def __call__(self, value: Any) -> bool:
Optional("password"): str,
Optional("cacert"): str,
Optional("cert"): str,
- Optional("key"): str
+ Optional("key"): str,
+ Optional("verify"): bool,
+ Optional("verify_hostname"): bool,
+ Optional("hostname_checks_common_name"): bool
}
schema = Schema({
diff --git a/tests/test_etcd.py b/tests/test_etcd.py
index 399e506e88..ada57d29ee 100644
--- a/tests/test_etcd.py
+++ b/tests/test_etcd.py
@@ -1,7 +1,7 @@
import socket
import unittest
-from unittest.mock import Mock, patch, PropertyMock
+from unittest.mock import MagicMock, Mock, patch, PropertyMock
import etcd
import urllib3.util.connection
@@ -236,12 +236,36 @@ def test__refresh_machines_cache(self):
self.assertFalse(self.client._refresh_machines_cache())
self.assertRaises(etcd.EtcdException, self.client._refresh_machines_cache, ['http://localhost:2379';])
+ @patch.object(EtcdClient, '_get_machines_list',
+ Mock(return_value=['https://localhost:2379';, 'https://localhost:4001';]))
+ def test__refresh_machines_cache_configures_tls_for_https_members(self):
+ # An HTTP seed can advertise HTTPS client URLs via member discovery;
+ # TLS must be (re)configured when such endpoints appear even though the
+ # seed itself was HTTP.
+ self.client._tls_configured = False
+ with patch.object(EtcdClient, '_configure_tls') as configure_tls:
+ self.client._refresh_machines_cache(['http://localhost:2379';])
+ configure_tls.assert_called_once()
+ self.assertTrue(self.client._tls_configured)
+
def test__load_machines_cache(self):
self.client._config = {}
self.assertRaises(Exception, self.client._load_machines_cache)
self.client._config = {'srv': 'blabla'}
self.assertRaises(etcd.EtcdException, self.client._load_machines_cache)
+ @patch.object(EtcdClient, '_get_machines_cache_from_config',
+ Mock(return_value=['https://localhost:2379';, 'https://localhost:4001';]))
+ def test__load_machines_cache_configures_tls_for_https_config(self):
+ # Config/SRV endpoints that are already HTTPS must trigger TLS
+ # configuration before the first request.
+ self.client._tls_configured = False
+ with patch.object(EtcdClient, '_refresh_machines_cache', Mock(return_value=True)), \
+ patch.object(EtcdClient, '_configure_tls') as configure_tls:
+ self.client._load_machines_cache()
+ configure_tls.assert_called_once()
+ self.assertTrue(self.client._tls_configured)
+
@patch.object(socket.socket, 'connect')
def test_create_connection_patched(self, mock_connect):
self.assertRaises(socket.error, urllib3.util.connection.create_connection, ('fail', 2379))
@@ -382,3 +406,129 @@ def test_set_history_value(self):
def test_last_seen(self):
self.assertIsNotNone(self.etcd.last_seen)
+
+
+class TestConfigureTLS(unittest.TestCase):
+
+ def _run(self, config, pool_kw=None):
+ from patroni.dcs.etcd import AbstractEtcdClientWithFailover
+
+ class _FakeHTTP:
+ def __init__(self):
+ self.connection_pool_kw = dict(pool_kw or {})
+ self.pool_classes_by_scheme = {'https': object}
+
+ class _FakeClient:
+ _config = config
+ http = _FakeHTTP()
+
+ client = _FakeClient()
+ AbstractEtcdClientWithFailover._configure_tls(client)
+ return client
+
+ def test_secure_defaults_are_noop(self):
+ # All defaults -> early return, pool untouched.
+ client = self._run({})
+ self.assertEqual(client.http.connection_pool_kw, {})
+
+ def test_verify_false_sets_cert_none(self):
+ client = self._run({'verify': False})
+ kw = client.http.connection_pool_kw
+ self.assertEqual(kw['cert_reqs'], 'CERT_NONE')
+ self.assertFalse(kw['assert_hostname'])
+ self.assertNotIn('ssl_context', kw)
+
+ def test_verify_hostname_false(self):
+ client = self._run({'verify_hostname': False})
+ kw = client.http.connection_pool_kw
+ self.assertEqual(kw['cert_reqs'], 'CERT_REQUIRED')
+ self.assertFalse(kw['assert_hostname'])
+
+ def test_cn_fallback_true_on_urllib3_1x(self):
+ # urllib3 1.x + cn_fallback=True -> warns, does not swap pool class.
+ with patch('patroni.dcs.etcd.urllib3.__version__', '1.26.20'):
+ client = self._run({'hostname_checks_common_name': True})
+ self.assertNotIn('ssl_context', client.http.connection_pool_kw)
+
+ def test_cn_fallback_false_on_urllib3_1x_installs_pool(self):
+ # urllib3 1.x + cn_fallback=False -> installs EtcdHTTPSConnectionPool.
+ from patroni.dcs.etcd import EtcdHTTPSConnectionPool
+ with patch('patroni.dcs.etcd.urllib3.__version__', '1.26.20'):
+ client = self._run({'hostname_checks_common_name': False})
+ self.assertIs(client.http.pool_classes_by_scheme['https'],
+ EtcdHTTPSConnectionPool)
+
+ def test_cn_fallback_true_on_urllib3_2x(self):
+ # urllib3 2.x + cn_fallback=True -> builds a custom ssl_context.
+ fake_ctx = MagicMock()
+ fake_ctx.hostname_checks_common_name = True
+ with patch('patroni.dcs.etcd.urllib3.__version__', '2.0.7'), \
+ patch('urllib3.connection.create_urllib3_context',
+ return_value=fake_ctx):
+ client = self._run({'hostname_checks_common_name': True},
+ pool_kw={'ca_certs': '/tmp/ca.pem'})
+ self.assertIs(client.http.connection_pool_kw['ssl_context'], fake_ctx)
+
+ def test_cn_fallback_false_on_urllib3_2x_is_noop(self):
+ # urllib3 2.x + cn_fallback=False -> SAN-only is already the default.
+ with patch('patroni.dcs.etcd.urllib3.__version__', '2.0.7'):
+ client = self._run({'hostname_checks_common_name': False})
+ self.assertNotIn('ssl_context', client.http.connection_pool_kw)
+
+ def test_cn_fallback_2x_setter_unsupported_warns(self):
+ # urllib3 2.x but the backend can't enable CN fallback (setter raises):
+ # warn and retain SAN-only (no ssl_context set).
+ fake_ctx = MagicMock()
+ type(fake_ctx).hostname_checks_common_name = PropertyMock(
+ side_effect=AttributeError)
+ with patch('patroni.dcs.etcd.urllib3.__version__', '2.0.7'), \
+ patch('urllib3.connection.create_urllib3_context',
+ return_value=fake_ctx):
+ client = self._run({'hostname_checks_common_name': True})
+ self.assertNotIn('ssl_context', client.http.connection_pool_kw)
+
+ def test_cn_fallback_2x_loads_default_certs_when_no_ca(self):
+ # urllib3 2.x + cn_fallback=True + no CA configured -> load system trust.
+ fake_ctx = MagicMock()
+ fake_ctx.hostname_checks_common_name = True
+ with patch('patroni.dcs.etcd.urllib3.__version__', '2.0.7'), \
+ patch('urllib3.connection.create_urllib3_context',
+ return_value=fake_ctx):
+ client = self._run({'hostname_checks_common_name': True})
+ # No ca_certs in pool -> load_default_certs() was invoked, context set.
+ fake_ctx.load_default_certs.assert_called_once()
+ self.assertIs(client.http.connection_pool_kw['ssl_context'], fake_ctx)
+
+ def test_cn_fallback_2x_no_load_default_certs_warns(self):
+ # urllib3 2.x + cn_fallback=True + no CA + backend without a callable
+ # load_default_certs -> warn and retain SAN-only (no ssl_context set).
+ fake_ctx = MagicMock()
+ fake_ctx.hostname_checks_common_name = True
+ fake_ctx.load_default_certs = None # not callable
+ with patch('patroni.dcs.etcd.urllib3.__version__', '2.0.7'), \
+ patch('urllib3.connection.create_urllib3_context',
+ return_value=fake_ctx):
+ client = self._run({'hostname_checks_common_name': True})
+ self.assertNotIn('ssl_context', client.http.connection_pool_kw)
+
+
+class TestEtcdHTTPSConnectionPool(unittest.TestCase):
+
+ def _validate(self, cert):
+ import urllib3
+
+ from patroni.dcs.etcd import EtcdHTTPSConnectionPool
+ pool = EtcdHTTPSConnectionPool.__new__(EtcdHTTPSConnectionPool)
+ conn = MagicMock()
+ conn.sock.getpeercert.return_value = cert
+ with patch.object(urllib3.HTTPSConnectionPool, '_validate_conn'):
+ pool._validate_conn(conn)
+
+ def test_san_present_passes(self):
+ # Cert with a DNS SAN passes.
+ self._validate({'subjectAltName': (('DNS', 'etcd'),)})
+
+ def test_no_san_raises(self):
+ from patroni.dcs.etcd import SSLError
+ with self.assertRaises(SSLError):
+ self._validate({'subject': ((('commonName', 'etcd'),),)})
diff --git a/typings/urllib3/__init__.pyi b/typings/urllib3/__init__.pyi
index 61b5b66c32..ea2687d4c7 100644
--- a/typings/urllib3/__init__.pyi
+++ b/typings/urllib3/__init__.pyi
@@ -4,4 +4,6 @@ from .response import HTTPResponse
from .util.request import make_headers
from .util.timeout import Timeout
+__version__: str
+
__all__ = ['HTTPResponse', 'HTTPConnectionPool', 'HTTPSConnectionPool', 'PoolManager', 'Timeout', 'make_headers']
diff --git a/typings/urllib3/connection.pyi b/typings/urllib3/connection.pyi
index 06b265db8f..df319f15ab 100644
--- a/typings/urllib3/connection.pyi
+++ b/typings/urllib3/connection.pyi
@@ -1,2 +1,15 @@
+import ssl
from http.client import HTTPConnection as _HTTPConnection
+from typing import Any, Optional
+
+
class HTTPConnection(_HTTPConnection): ...
+
+
+class HTTPSConnection(HTTPConnection):
+ sock: Optional[ssl.SSLSocket]
+
+
+def create_urllib3_context(ssl_version: Optional[int] = None, cert_reqs: Optional[int] = None,
+ options: Optional[int] = None, ciphers: Optional[str] = None,
+ **kwargs: Any) -> ssl.SSLContext: ...
diff --git a/typings/urllib3/connectionpool.pyi b/typings/urllib3/connectionpool.pyi
index b2e8d3db2f..1779078d0d 100644
--- a/typings/urllib3/connectionpool.pyi
+++ b/typings/urllib3/connectionpool.pyi
@@ -1,2 +1,8 @@
+from .connection import HTTPSConnection
+
+
class HTTPConnectionPool: ...
-class HTTPSConnectionPool(HTTPConnectionPool): ...
+
+
+class HTTPSConnectionPool(HTTPConnectionPool):
+ def _validate_conn(self, conn: HTTPSConnection) -> None: ...
diff --git a/typings/urllib3/poolmanager.pyi b/typings/urllib3/poolmanager.pyi
index 5ea41a68a5..978debb92e 100644
--- a/typings/urllib3/poolmanager.pyi
+++ b/typings/urllib3/poolmanager.pyi
@@ -3,6 +3,7 @@ from .response import HTTPResponse
class PoolManager:
headers: Dict[str, str]
connection_pool_kw: Dict[str, Any]
+ pool_classes_by_scheme: Dict[str, Any]
def __init__(self, num_pools: int = 10, headers: Optional[Dict[str, str]] = None, **connection_pool_kw: Any) -> None: ...
def urlopen(self, method: str, url: str, body: Optional[Any] = None, headers: Optional[Dict[str,str]] = None, encode_multipart: bool = True, multipart_boundary: Optional[str] = None, **kw: Any) -> HTTPResponse: ...
def request(self, method: str, url: str, fields: Optional[Any] = None, headers: Optional[Dict[str, str]] = None, **urlopen_kw: Any) -> HTTPResponse: ...
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 03:25 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-05-08 03:25 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@chaitanyabodlapati requested a review.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 03:25 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-05-08 03:25 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@chaitanyabodlapati requested a review.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 13:03 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-05-08 13:03 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
Does it make sense to do it if verify_hostname is False?
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 13:07 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-05-08 13:07 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
1. By default `hostname_checks_common_name` is true: https://docs.python.org/3/library/ssl.html#ssl.SSLContext.hostname_checks_common_name
2. I don't really like raising RuntimeError.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 13:08 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-05-08 13:08 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
Why do we even need to create SSLContext in this case?
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 13:17 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-05-08 13:17 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
Have you thought about etcd running in private network without TLS?
This warning doesn't make any sense this case.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 13:21 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-05-08 13:21 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
I left a few comments.
Besides that, would like to avoid adding additional files to patroni/dcs in case if they don't implement DCS support
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-05-08 14:03 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-05-08 14:03 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
If python is compiled without ssl everything will fail.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-07-09 16:40 "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: hughcapet (@hughcapet) @ 2026-07-09 16:40 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@chaitanyabodlapati ping. Are you planning to follow up on this PR?
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-07-09 19:42 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-07-09 19:42 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
> @chaitanyabodlapati ping. Are you planning to follow up on this PR?
@hughcapet Thanks for the review, and apologies for the delay — I got pulled into other work before I could follow up on the comments.
I agree with the direction of keeping this change as small and consistent with the existing Patroni structure as possible. I'll revisit the implementation and address your comments, especially:
1. avoiding a separate patroni/dcs/etcd_tls.py helper, since that directory is for DCS implementations;
2. simplifying the verify=false path and dropping the unnecessary SSLContext if urllib3 pool options are enough;
3. only emitting warnings for actual TLS verification relaxations, not for plain/private non-TLS etcd usage;
4. only building the CA-validation context where it's actually needed, rather than in paths where identity checking is already relaxed.
5. aligning hostname_checks_common_name with the Python/OpenSSL default (which is already True) and dropping the RuntimeError.
I'll rework the patch with these points in mind and push an updated version within the next couple of weeks.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-06 22:08 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-06 22:08 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
> I left a few comments. Besides that, would like to avoid adding additional files to patroni/dcs in case if they don't implement DCS support
Done — moved the helper into patroni/dcs/etcd.py as a private function and removed the separate file. The tests moved into tests/test_etcd.py as well.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-06 22:09 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-06 22:09 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
Good point — hostname_checks_common_name is now only applied when hostname verification is enabled, since it has no effect otherwise.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-06 22:09 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-06 22:09 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
Agreed on both. Removed the RuntimeError. Since the attribute already defaults to True, on builds where the setter isn't available the desired behavior is already in effect, so setting it is now a best-effort try/except.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-06 22:10 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-06 22:10 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
You're right, it wasn't needed. The verify=false path now just sets cert_reqs='CERT_NONE' and assert_hostname=False on the pool and lets urllib3 build its own context.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-06 22:11 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-06 22:11 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
Added an early return when protocol is not https, so etcd on a private network without TLS is unaffected and no misleading warning is logged.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-06 22:11 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-06 22:11 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd_tls.py)
Moved import ssl inside the function, after the non-https and default-flag guards, so a Python built without ssl still works for plain-HTTP etcd.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-06 22:17 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-06 22:17 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
Thanks for the review, @CyberDem0n. I've addressed all the comments:
1. Helper moved into etcd.py as a private function (no separate file); tests moved into tests/test_etcd.py.
2. verify=false no longer builds an SSLContext — it just sets cert_reqs='CERT_NONE' and assert_hostname=False on the pool and lets urllib3 build its own context.
3. Early return for non-https protocol, so etcd on a private network without TLS is unaffected and logs no misleading warning.
4. import ssl moved inside the function, after the non-https and default-flag guards, so a Python built without ssl still works for plain HTTP etcd.
5. hostname_checks_common_name only applied when hostname checking is on, and no longer raises RuntimeError — since it already defaults to True, setting it is now a best-effort try/except.
Would you mind taking another look when you get a chance? Thanks!
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-12 15:53 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-08-12 15:53 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
Default value of `SSLContext.hostname_checks_common_name` is True.
It goes against how cn_fallback is set.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-12 15:58 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-08-12 15:58 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py:153)
Something is wrong.
Here is the table describing possible states:
| `verify` | `verify_hostname` | `hostname_checks_common_name` | Expected behavior |
|---:|---:|---:|---|
| `false` | any | any | No CA-chain or hostname verification |
| `true` | `false` | any | CA-chain validation only; hostname verification disabled |
| `true` | `true` | `false` | CA-chain validation plus SAN hostname validation; no CN fallback |
| `true` | `true` | `true` | CA-chain validation plus SAN hostname validation, with DNS CN fallback |
The implementation should explicitly set `ctx.hostname_checks_common_name` to the configured boolean whenever `verify_hostname` is true. If the platform cannot enforce `false`, silently continuing is unsafe; the code should either fail clearly or document that the platform cannot provide SAN-only verification.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-12 16:00 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-08-12 16:00 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
Please make it a method of AbstractEtcdClientWithFailover class.
This way you will not need to pass neither http_pool, nor config.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-14 20:11 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-14 20:11 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
Fixed — removed the fast-path that caused the default mismatch. When `verify_hostname` is enabled, `hostname_checks_common_name` is now explicitly set from the configured value.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-14 20:11 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-14 20:11 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py:153)
Thanks for the behavior table — updated the implementation to match it. When `verify_hostname` is enabled, `ctx.hostname_checks_common_name` is now explicitly set to the configured value:
`true` = DNS CN fallback allowed
`false` = SAN-only (no CN fallback)
If the platform cannot enforce `false`, it no longer silently continues — it logs a clear warning that SAN-only verification cannot be enforced.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-14 20:11 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-08-14 20:11 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
Done — converted it `to _configure_tls(self) `on `AbstractEtcdClientWithFailover`. It now uses `self._config` and `self.http `directly, so there's no need to pass http_pool or config.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-27 13:02 "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: hughcapet (@hughcapet) @ 2026-08-27 13:02 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@hughcapet requested a review.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-08-27 14:31 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-08-27 14:31 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
`hostname_checks_common_name` defaults to `False`, so the new default HTTPS path explicitly disables CN fallback for every existing configuration. **This is a behavior change despite the PR stating that existing configurations are unaffected**.
Python’s `SSLContext.hostname_checks_common_name` defaults to `True`; therefore, the default should preserve that behavior and only disable CN fallback when the user explicitly sets `hostname_checks_common_name: false`
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-09-11 21:31 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-09-11 21:31 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
Good catch — you're right, defaulting it to False and always setting it changed behavior for existing configs. I Fixed it : the flag now defaults to unset, and `ctx.hostname_checks_common_name` is only assigned when the user explicitly configures it. When it's not set, the `SSLContext default (True)` is preserved, so existing configurations behave exactly as before. Explicit true/false still work per the table.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-09-22 10:06 "codecov[bot] (bot) (@codecov[bot])" <noreply+codecov[bot]@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: codecov[bot] (bot) (@codecov[bot]) @ 2026-09-22 10:06 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
## [Codecov](https://app.codecov.io/gh/patroni/patroni/pull/3608?dropdown=coverage&src=pr&el=h1&utm_m...) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:loudspeaker: Thoughts on this report? [Let us know!](https://github.com/codecov/feedback/issues/255)
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-09-25 14:30 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-09-25 14:30 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
Simply using `ssl.create_default_context()` is not enough because urllib3 handles hostname checks differently across versions:
- urllib3 1.x normally checks hostnames itself and allows CN fallback
- urllib3 2.x disables CN fallback by default.
Changing the SSL context’s settings does not always change what urllib3 actually checks.
It can also break valid connections: urllib3 1.26 does not pass `server_hostname` for IP addresses, but `ssl.create_default_context()` requires it when hostname checking is enabled. This can make a connection fail even when the certificate has a valid IP SAN.
We need to account for these differences across our supported urllib3 versions (`>=1.19.1), rather than rely only on the SSL context’s settings.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-09-25 14:39 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-09-25 14:39 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
`_configure_tls()` is called before `_load_machines_cache()` and returns immediately unless the current protocol is HTTPS. With `srv` configured and no explicit `protocol`, discovery can subsequently select HTTPS, but the TLS options have already been skipped.
Configuration needs to happen after endpoint discovery and before the first client request. For peer-based discovery, the advertised **client URL scheme**, not necessarily the peer scheme, is what matters.
Here we need to do:
```suggestion
self._tls_configured = False
```
And call self._configure_tls() from _load_machines_cache():
```diff
@@ -443,6 +537,11 @@ class AbstractEtcdClientWithFailover(abc.ABC, etcd.Client, StaleEtcdNodeGuard):
if not machines_cache:
raise etcd.EtcdException
+ # Peer discovery and client endpoints may use different protocols.
+ if not self._tls_configured and any(urlparse(url).scheme == 'https' for url in machines_cache):
+ self._configure_tls()
+ self._tls_configured = True
+
# enforce resolving dns name,they might get new ips
self._update_dns_cache(self._dns_resolver.remove, machines_cache)
```
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-09-25 14:48 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-09-25 14:48 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
Here is how _configure_tls() method can look like if it takes into account some urllib3 quirks:
```python
class EtcdHTTPSConnectionPool(urllib3.HTTPSConnectionPool):
"""Enforce SAN-only verification with urllib3's legacy hostname matcher."""
def _validate_conn(self, conn: HTTPSConnection) -> None:
super()._validate_conn(conn)
cert = conn.sock.getpeercert() if conn.sock is not None else None
# The legacy matcher only falls back to CN when there are no DNS/IP SAN entries.
if not cert or not any(key in ('DNS', 'IP Address') for key, _ in cert.get('subjectAltName', ())):
conn.close()
raise SSLError('Etcd TLS certificate has no DNS or IP Subject Alternative Name; '
'Common Name fallback is disabled')
[...]
def _configure_tls(self) -> None:
"""Apply opt-in TLS verification settings for discovered HTTPS client endpoints.
With no overrides, preserve the installed urllib3's behavior.
If Common Name fallback cannot be enabled, log a warning and retain SAN-only verification.
Behavior matrix (verify / verify_hostname / hostname_checks_common_name):
false / any / any -> no CA-chain or hostname verification
true / false / any -> CA-chain validation only; hostname check off
true / true / unset -> preserve python-etcd / urllib3 defaults
true / true / false -> CA-chain + SAN validation; no CN fallback
true / true / true -> CA-chain + hostname validation, allowing CN fallback
if supported by the TLS backend; otherwise warn and retain SAN-only
"""
config = self._config
verify = config.get('verify', True)
verify_hostname = config.get('verify_hostname', True)
cn_fallback = config.get('hostname_checks_common_name')
# Nothing to do when everything is at its secure default: leave the
# stock python-etcd / urllib3 TLS setup unchanged. This also avoids
# building an SSLContext (and loading the platform trust store) for
# existing configurations that set none of these flags.
if verify and verify_hostname and cn_fallback is None:
return
pool_kw = self.http.connection_pool_kw
if not verify:
pool_kw['cert_reqs'] = 'CERT_NONE'
pool_kw['assert_hostname'] = False
pool_kw.pop('ca_certs', None)
return logger.warning('Etcd TLS certificate verification is disabled')
pool_kw['cert_reqs'] = 'CERT_REQUIRED'
if not verify_hostname:
pool_kw['assert_hostname'] = False
return logger.warning('Etcd TLS hostname verification is disabled')
if int(urllib3.__version__.split('.')[0]) < 2:
if cn_fallback:
return logger.warning('Etcd TLS Common Name fallback is enabled')
self.http.pool_classes_by_scheme = dict(self.http.pool_classes_by_scheme, https=EtcdHTTPSConnectionPool)
return
# urllib3 2.x already enforces SAN-only verification by default.
# A custom context is needed only to enable CN fallback.
if not cn_fallback:
return
import ssl
from urllib3.connection import create_urllib3_context
ctx = create_urllib3_context(cert_reqs=ssl.CERT_REQUIRED)
# Delegate identity verification to urllib3's matcher, which honors hostname_checks_common_name on this context.
ctx.check_hostname = False
try:
ctx.hostname_checks_common_name = True
cn_fallback_enabled = ctx.hostname_checks_common_name
except AttributeError:
cn_fallback_enabled = False
if not cn_fallback_enabled:
return logger.warning('This TLS backend cannot enable Common Name fallback; '
'retaining SAN-only verification')
# urllib3 loads explicit CA/client files from pool options.
# For a supplied context, load system trust ourselves.
if not any(pool_kw.get(key) for key in ('ca_certs', 'ca_cert_dir', 'ca_cert_data')):
load_default_certs = getattr(ctx, 'load_default_certs', None)
if not callable(load_default_certs):
return logger.warning('This TLS backend requires an explicit cacert '
'when enabling Common Name fallback; retaining SAN-only verification')
load_default_certs()
pool_kw['ssl_context'] = ctx
logger.warning('Etcd TLS Common Name fallback is enabled')
```
After applying these changes you may also have to please `pyright` by modifying some files in `typings/urllib3`.
Besides that, you need to update:
1. patroni/validator.py: https://github.com/patroni/patroni/blob/eec38cd0b8f51d23c8a965515bd0df6dd05a5df1/patroni/validator.p...
2. patroni/config.py: https://github.com/patroni/patroni/blob/eec38cd0b8f51d23c8a965515bd0df6dd05a5df1/patroni/config.py#L...
And of course, document new parameters in [ENVIRONMENT.rst](https://github.com/patroni/patroni/blob/master/docs/ENVIRONMENT.rst) and [yaml_configuration.rst](https://github.com/patroni/patroni/blob/master/docs/yaml_configuration.rst)
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-09-29 21:55 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-09-29 21:55 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
Thanks for the detailed guidance and the reference implementation — I've applied it.
1. `_configure_tls` reworked per your version-aware approach: on urllib3 1.x it installs the `EtcdHTTPSConnectionPool` (SAN-only via the legacy matcher, CN fallback left to urllib3); on 2.x it builds a custom context only to enable CN fallback, loading system trust when no CA is configured.
2. TLS is now configured from `_load_machines_cache` after endpoint discovery instead of in `__init__`, so SRV-discovered HTTPS endpoints are handled via the advertised client URL scheme.
3. Added the three options to the etcd/etcd3 validators and environment parsing, documented them in both `yaml_configuration.rst` and `ENVIRONMENT.rst`, and extended the `typings/urllib3` stubs so pyright passes.
4. Tests cover both the urllib3 1.x and 2.x code paths.
Please take another look when you have a chance.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-10-06 13:12 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-10-06 13:12 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/config.py:684)
You also have to cast added values to boolean by adding names to the list on line 730:
```python
- elif suffix in ('USE_PROXIES', 'REGISTER_SERVICE', 'USE_ENDPOINTS', 'BYPASS_API_SERVICE', 'VERIFY'):
+ elif suffix in ('USE_PROXIES', 'REGISTER_SERVICE', 'USE_ENDPOINTS', 'BYPASS_API_SERVICE',
+ 'VERIFY', 'VERIFY_HOSTNAME', 'HOSTNAME_CHECKS_COMMON_NAME'):
value = parse_bool(value)
```
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-10-06 13:15 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-10-06 13:15 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py)
The new guard checks only the initial endpoints returned by `_get_machines_cache_from_config()`. However, `_refresh_machines_cache()` subsequently replaces them with advertised client URLs without checking whether TLS needs configuring.
For example, an HTTP seed can return HTTPS client URLs from `/machines` or `/cluster/member/list`. `_tls_configured` remains `false`, but requests proceed against those HTTPS members with the original pool settings. `verify: false` or `verify_hostname: false` therefore does not resolve the certificate failures it was configured for. Retrying bootstrap through that same HTTP seed repeats the problem.
Ensure configuration also happens before using HTTPS endpoints learned through member discovery, not only those obtained from configuration/SRV discovery. Add a regression test covering an HTTP seed that advertises HTTPS members.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-10-12 20:12 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-10-12 20:12 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
Both addressed:
1. Added verify_hostname and hostname_checks_common_name to the boolean env-var cast list in config.py.
2. Moved the TLS-configuration guard from _load_machines_cache into _refresh_machines_cache, right after the discovered member list is stored, so HTTPS client URLs learned through member discovery — even from an HTTP seed — trigger TLS configuration. Added a regression test (test__refresh_machines_cache_configures_tls_for_https_members) covering exactly that: an HTTP seed advertising HTTPS members.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-10-13 09:25 "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-10-13 09:25 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py:542)
```suggestion
if not self._tls_configured and any(urlparse(url).scheme == 'https' for url in machines_cache):
self._configure_tls()
self._tls_configured = True
```
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-10-15 22:34 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-10-15 22:34 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/dcs/etcd.py:542)
Added the guard in _load_machines_cache as suggested. Config/SRV endpoints that are already HTTPS now get TLS configured before the first request, alongside the existing _refresh_machines_cache guard that handles HTTPS members learned through discovery.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-11-09 20:15 "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: chaitanyabodlapati (@chaitanyabodlapati) @ 2026-11-09 20:15 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
Hi @CyberDem0n — this has been green for a few weeks now. I’ve addressed all the review feedback . Would you be able to take another look when you have a chance? Happy to adjust anything further if needed. Thanks!
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608 (approved): Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-11-19 19:28 "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: hughcapet (@hughcapet) @ 2026-11-19 19:28 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-11-19 19:29 "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: hughcapet (@hughcapet) @ 2026-11-19 19:29 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@hughcapet applied label "enhancement".
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-11-19 19:31 "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: hughcapet (@hughcapet) @ 2026-11-19 19:31 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@hughcapet closed this.
^ permalink raw [nested|flat] 42+ messages in thread
* Re: [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends
@ 2026-11-19 19:31 "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
40 siblings, 0 replies; 42+ messages in thread
From: hughcapet (@hughcapet) @ 2026-11-19 19:31 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@hughcapet merged this (commit ea3720409366).
^ permalink raw [nested|flat] 42+ messages in thread
end of thread, other threads:[~2026-11-19 19:31 UTC | newest]
Thread overview: 42+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-05-08 03:25 [patroni/patroni] PR #3608: Add opt-in TLS verification flags for etcd/etcd3 DCS backends "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-05-08 03:25 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-05-08 03:25 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-05-08 13:03 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-05-08 13:07 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-05-08 13:08 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-05-08 13:17 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-05-08 13:21 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-05-08 14:03 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-07-09 16:40 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
2026-07-09 19:42 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-06 22:08 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-06 22:09 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-06 22:09 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-06 22:10 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-06 22:11 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-06 22:11 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-06 22:17 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-12 15:53 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-08-12 15:58 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-08-12 16:00 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-08-14 20:11 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-14 20:11 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-14 20:11 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-08-27 13:02 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
2026-08-27 14:31 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-09-11 21:31 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-09-22 10:06 ` "codecov[bot] (bot) (@codecov[bot])" <noreply+codecov[bot]@github.com>
2026-09-25 14:30 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-09-25 14:39 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-09-25 14:48 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-09-29 21:55 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-10-06 13:12 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-10-06 13:15 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-10-12 20:12 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-10-13 09:25 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-10-15 22:34 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-11-09 20:15 ` "chaitanyabodlapati (@chaitanyabodlapati)" <noreply+chaitanyabodlapati@github.com>
2026-11-19 19:28 ` Re: [patroni/patroni] PR #3608 (approved): Add opt-in TLS verification flags for etcd/etcd3 DCS backends "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
2026-11-19 19:29 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
2026-11-19 19:31 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
2026-11-19 19:31 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox