From dcfdf431319a6cdc29ebfbebbed84d749e764bb9 Mon Sep 17 00:00:00 2001 From: Yohan Senadheera Date: Wed, 18 Nov 2026 08:04:58 +0530 Subject: [PATCH] Honor assert_hostname in the asyncio client assert_hostname=False turned off hostname checks in the sync client but had no effect in the asyncio client. Set check_hostname on the SSL context from it when verify_ssl is on. Signed-off-by: Yohan Senadheera --- kubernetes/aio/client/rest.py | 4 ++++ kubernetes/aio/test/test_generated_api.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/kubernetes/aio/client/rest.py b/kubernetes/aio/client/rest.py index 4c07faa125..70d111e968 100644 --- a/kubernetes/aio/client/rest.py +++ b/kubernetes/aio/client/rest.py @@ -86,6 +86,10 @@ def __init__(self, configuration) -> None: if configuration.disable_strict_ssl_verification: self.ssl_context.verify_flags &= ~ssl.VERIFY_X509_STRICT + if (configuration.verify_ssl + and configuration.assert_hostname is not None): + self.ssl_context.check_hostname = bool(configuration.assert_hostname) + self.proxy = configuration.proxy self.proxy_headers = configuration.proxy_headers diff --git a/kubernetes/aio/test/test_generated_api.py b/kubernetes/aio/test/test_generated_api.py index 374267b208..f349b63134 100644 --- a/kubernetes/aio/test/test_generated_api.py +++ b/kubernetes/aio/test/test_generated_api.py @@ -362,6 +362,23 @@ async def test_strict_tls_verification_can_be_disabled(self): rest_client.ssl_context.verify_flags & ssl.VERIFY_X509_STRICT, ) + async def test_assert_hostname_false_disables_hostname_check(self): + self.configuration.assert_hostname = False + + rest_client = RESTClientObject(self.configuration) + + self.assertFalse(rest_client.ssl_context.check_hostname) + self.assertEqual(ssl.CERT_REQUIRED, rest_client.ssl_context.verify_mode) + + async def test_assert_hostname_does_not_reenable_verification(self): + self.configuration.verify_ssl = False + self.configuration.assert_hostname = True + + rest_client = RESTClientObject(self.configuration) + + self.assertFalse(rest_client.ssl_context.check_hostname) + self.assertEqual(ssl.CERT_NONE, rest_client.ssl_context.verify_mode) + async def test_models_preserve_int_or_string_and_python_field_names(self): port = V1ServicePort(port=80, target_port='https')