Skip to content

fix(providers/cncf-kubernetes): apply verify_ssl=False to returned ApiClient in KubernetesHook - #63478

Merged
potiuk merged 3 commits into
apache:mainfrom
antonio-mello-ai:fix/kubernetes-hook-verify-ssl-56432
Mar 14, 2026
Merged

potiuk merged 3 commits into
apache:mainfrom
antonio-mello-ai:fix/kubernetes-hook-verify-ssl-56432

Conversation

@antonio-mello-ai

Copy link
Copy Markdown
Contributor

Summary

  • Fix KubernetesHook so that disable_verify_ssl=True actually disables SSL verification on the returned ApiClient
  • The root cause: load_kube_config() overwrites Configuration.set_default() with a fresh Configuration(verify_ssl=True), so the earlier _disable_verify_ssl() call is lost
  • Fix: re-apply verify_ssl=False after each config load, and pass the configuration explicitly to _TimeoutK8sApiClient

Root Cause

_disable_verify_ssl() calls Configuration.set_default() to register verify_ssl=False globally. However, load_kube_config() (called right after) creates a new Configuration instance with verify_ssl=True by default and overwrites the global default. The _TimeoutK8sApiClient() then gets verify_ssl=True from get_default_copy().

Test Plan

  • New parametrized test covering all 4 config paths (kube_config_path, kube_config, config_dict, default_client)
  • All 138 tests pass
  • All pre-commit hooks pass (prek)

Closes #56432

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

When disable_verify_ssl=True, _disable_verify_ssl() sets the global
Configuration default via Configuration.set_default(). However,
config.load_kube_config() called immediately after with
client_configuration=None creates a fresh Configuration instance,
loads the kubeconfig into it (with verify_ssl=True), and overwrites
the global default via Configuration.set_default() again. The
_TimeoutK8sApiClient() created without arguments then calls
Configuration.get_default_copy() and gets verify_ssl=True.

Fix by ensuring that when disable_verify_ssl=True, self.client_configuration
is initialized from the updated default (with verify_ssl=False) before
calling load_kube_config(), then re-applying verify_ssl=False after the
load (since load_and_set() may overwrite it), and finally passing the
configuration explicitly to _TimeoutK8sApiClient.

Closes apache#56432

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
antonio-mello-ai and others added 2 commits March 12, 2026 18:59
Replace `assert` with conditional check to satisfy both mypy
(union-attr on Optional type) and ruff (S101 no-assert rule).

Fixes apache#56432

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ructor

Move verify_ssl handling into _TimeoutK8sApiClient.__init__ so callers
pass disable_verify_ssl as a flag instead of repeating the config
adjustment at every call site. Reduces risk of future inconsistency.

Addresses review feedback from jscheffl.

Fixes apache#56432

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@potiuk

potiuk commented Mar 13, 2026

Copy link
Copy Markdown
Member

@jscheffl — Could you please check whether your review feedback on this PR has been addressed? @antonio-mello-ai appears to have responded to your comments. @antonio-mello-ai, do you believe the reviewer's concerns have been resolved?

If the concerns are resolved, please resolve the conversation threads. Thank you!

@jscheffl jscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me, tests are all green. As this is a security related change I'd request another pair of eyes from a second maintainer.

@potiuk
potiuk merged commit 63d9d87 into apache:main Mar 14, 2026
108 checks passed
abhijeets25012-tech pushed a commit to abhijeets25012-tech/airflow that referenced this pull request Apr 9, 2026
…iClient in KubernetesHook (apache#63478)

* Fix KubernetesHook verify_ssl flag not applied to returned ApiClient

When disable_verify_ssl=True, _disable_verify_ssl() sets the global
Configuration default via Configuration.set_default(). However,
config.load_kube_config() called immediately after with
client_configuration=None creates a fresh Configuration instance,
loads the kubeconfig into it (with verify_ssl=True), and overwrites
the global default via Configuration.set_default() again. The
_TimeoutK8sApiClient() created without arguments then calls
Configuration.get_default_copy() and gets verify_ssl=True.

Fix by ensuring that when disable_verify_ssl=True, self.client_configuration
is initialized from the updated default (with verify_ssl=False) before
calling load_kube_config(), then re-applying verify_ssl=False after the
load (since load_and_set() may overwrite it), and finally passing the
configuration explicitly to _TimeoutK8sApiClient.

Closes apache#56432

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: narrow client_configuration type for mypy union-attr check

Replace `assert` with conditional check to satisfy both mypy
(union-attr on Optional type) and ruff (S101 no-assert rule).

Fixes apache#56432

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: centralize disable_verify_ssl in _TimeoutK8sApiClient constructor

Move verify_ssl handling into _TimeoutK8sApiClient.__init__ so callers
pass disable_verify_ssl as a flag instead of repeating the config
adjustment at every call site. Reduces risk of future inconsistency.

Addresses review feedback from jscheffl.

Fixes apache#56432

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KubernetesHook: verify_ssl flag does not work

3 participants