Skip to content

Commit

Permalink
Clean up vendored Docker SDK for Python TLS handling code. (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Dec 9, 2023
1 parent 2677230 commit b3ef5f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/722-tls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "vendored Docker SDK for Python - avoid passing on ``ssl_version`` and ``tls_hostname`` if they were not provided by the user. Remove dead code. (https://github.com/ansible-collections/community.docker/pull/722)."
5 changes: 1 addition & 4 deletions plugins/module_utils/_api/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ class TLSConfig(object):
ssl_version = None

def __init__(self, client_cert=None, ca_cert=None, verify=None,
ssl_version=None, assert_hostname=None,
assert_fingerprint=None):
ssl_version=None, assert_hostname=None):
# Argument compatibility/mapping with
# https://docs.docker.com/engine/articles/https/
# This diverges from the Docker CLI in that users can specify 'tls'
# here, but also disable any public/default CA pool verification by
# leaving verify=False

self.assert_hostname = assert_hostname
self.assert_fingerprint = assert_fingerprint

# If the user provides an SSL version, we should use their preference
if ssl_version:
Expand Down Expand Up @@ -118,5 +116,4 @@ def configure_client(self, client):
client.mount('https://', SSLHTTPAdapter(
ssl_version=self.ssl_version,
assert_hostname=self.assert_hostname,
assert_fingerprint=self.assert_fingerprint,
))
14 changes: 5 additions & 9 deletions plugins/module_utils/_api/transport/ssladapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,21 @@
class SSLHTTPAdapter(BaseHTTPAdapter):
'''An HTTPS Transport Adapter that uses an arbitrary SSL version.'''

__attrs__ = HTTPAdapter.__attrs__ + ['assert_fingerprint',
'assert_hostname',
'ssl_version']
__attrs__ = HTTPAdapter.__attrs__ + ['assert_hostname', 'ssl_version']

def __init__(self, ssl_version=None, assert_hostname=None,
assert_fingerprint=None, **kwargs):
def __init__(self, ssl_version=None, assert_hostname=None, **kwargs):
self.ssl_version = ssl_version
self.assert_hostname = assert_hostname
self.assert_fingerprint = assert_fingerprint
super(SSLHTTPAdapter, self).__init__(**kwargs)

def init_poolmanager(self, connections, maxsize, block=False):
kwargs = {
'num_pools': connections,
'maxsize': maxsize,
'block': block,
'assert_hostname': self.assert_hostname,
'assert_fingerprint': self.assert_fingerprint,
}
if self.assert_hostname is not None:
kwargs['assert_hostname'] = self.assert_hostname
if self.ssl_version and self.can_override_ssl_version():
kwargs['ssl_version'] = self.ssl_version

Expand All @@ -60,7 +56,7 @@ def get_connection(self, *args, **kwargs):
But we still need to take care of when there is a proxy poolmanager
"""
conn = super(SSLHTTPAdapter, self).get_connection(*args, **kwargs)
if conn.assert_hostname != self.assert_hostname:
if self.assert_hostname is not None and conn.assert_hostname != self.assert_hostname:
conn.assert_hostname = self.assert_hostname
return conn

Expand Down

0 comments on commit b3ef5f5

Please sign in to comment.