Skip to content

feat: add proxy_ssl_context to Configuration for a separate proxy TLS context - #2658

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
emmanuel-adu:feat/proxy-ssl-context
Aug 11, 2026
Merged

feat: add proxy_ssl_context to Configuration for a separate proxy TLS context#2658
kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
emmanuel-adu:feat/proxy-ssl-context

Conversation

@emmanuel-adu

@emmanuel-adu emmanuel-adu commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #2387.

Configuration gains proxy_ssl_context: Optional[ssl.SSLContext] = None, passed through to urllib3.ProxyManager in RESTClientObject. This lets the HTTPS proxy's TLS cert be validated independently of the destination (K8s API server) settings - the "HTTPS Proxy + HTTPS Destination" scenario urllib3 already supports natively.

kubernetes/client is generated from kubernetes-client/gen; companion PR kubernetes-client/gen#308 adds the same patch there. This PR applies it to the already-generated files so it's usable now.

Verification: kubernetes/e2e_test/test_issue_2387_proxy_ssl_context.py spins up a mock HTTPS proxy and destination server with independent self-signed CAs (no live cluster needed). Without proxy_ssl_context: fails with CERTIFICATE_VERIFY_FAILED. With it set to trust the proxy's CA: succeeds, destination still validated separately.

test report: both scenarios passing, with captured CERTIFICATE_VERIFY_FAILED log for the without-fix case
Added `proxy_ssl_context` to `Configuration`, letting users provide a separate SSL context for HTTPS proxy TLS verification, independent of the destination TLS settings.

@kubernetes-prow kubernetes-prow Bot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 30, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog July 30, 2026 00:32
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Jul 30, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @emmanuel-adu!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 30, 2026
… context

Adds a proxy_ssl_context parameter to Configuration and threads it through
RESTClientObject to urllib3.ProxyManager, so the HTTPS proxy's own TLS
certificate can be validated independently of the destination (Kubernetes
API server) TLS settings - the "HTTPS Proxy + HTTPS Destination" scenario
urllib3 documents at:
https://urllib3.readthedocs.io/en/stable/advanced-usage.html#https-proxy-https-destination

kubernetes/client is generated from kubernetes-client/gen; this applies
the equivalent of the companion gen-repo patch directly to the
already-generated files, so the feature is usable now rather than
waiting on the next full regeneration.

Added an end-to-end test (kubernetes/e2e_test) using a mock HTTPS proxy
and a mock HTTPS destination server, each with an independent self-signed
CA - it doesn't require a live cluster, only openssl on PATH. Verified:
without proxy_ssl_context, connecting through a proxy with a different CA
than the destination fails with CERTIFICATE_VERIFY_FAILED; with it set to
trust the proxy's CA, the connection succeeds and the destination is
still validated against its own separate CA.
@emmanuel-adu
emmanuel-adu force-pushed the feat/proxy-ssl-context branch from 6985e88 to f526d68 Compare July 30, 2026 00:37
@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 30, 2026
@emmanuel-adu

Copy link
Copy Markdown
Contributor Author

/kind feature

@kubernetes-prow kubernetes-prow Bot added kind/feature Categorizes issue or PR as related to a new feature. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Jul 30, 2026


import copy
import ssl

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file is generated by upstream openapi-generator. Please send a PR to update the upstream generator to properly support this feature.

@emmanuel-adu emmanuel-adu Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Opened kubernetes-client/gen#308 to add proxy_ssl_context for the sync client, following the existing pattern, and this PR applies that generated change now.

Or are you asking for this to be implemented in OpenAPITools/openapi-generator itself instead?

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.

better to add to OpenAPITools/openapi-generator

modules/openapi-generator/src/main/resources/python-pydantic-v1/configuration.mustache

modules/openapi-generator/src/main/resources/python/configuration.mustache

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay we'll look into doing that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Opened and merged OpenAPITools/openapi-generator#24539 - adds proxy_ssl_context to both templates you flagged, gated the same way as tls_server_name/disable_strict_ssl_verification.

Given that, do we want to merge this PR now to ship the fix, or hold off and pick it up later via a full regen (bump the pinned generator commit in gen, rerun autoupdate.sh)? Either way works cleanly - if you go the regen route later, this PR's changes just get superseded by that regen with no conflict.

@yliaog @roycaihw

@yliaog

yliaog commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

sounds good, thanks.

please add the corresponding e2e test for asyncio client.

@yliaog yliaog self-assigned this Aug 1, 2026
@emmanuel-adu

Copy link
Copy Markdown
Contributor Author

How would you like to proceed?

cc: @yliaog @roycaihw

Opened and merged OpenAPITools/openapi-generator#24539 - adds proxy_ssl_context to both templates you flagged, gated the same way as tls_server_name/disable_strict_ssl_verification.

Given that, do we want to merge this PR now to ship the fix, or hold off and pick it up later via a full regen (bump the pinned generator commit in gen, rerun autoupdate.sh)? Either way works cleanly - if you go the regen route later, this PR's changes just get superseded by that regen with no conflict.

also comment from kubernetes-client/gen#308 (comment) @brendandburns

Comment thread kubernetes/aio/client/configuration.py Outdated
connection_pool_maxsize: Optional[int]=None,
proxy: Optional[str]=None,
proxy_headers: Optional[Any]=None,
proxy_ssl_context: Optional[ssl.SSLContext]=None,

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.

does it apply to aio client? the upstream openapi generator PR says it does not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct - OpenAPITools/openapi-generator#24539 only touches the python and python-pydantic-v1 (urllib3/sync) templates, not the aiohttp templates, so a future regen wouldn't produce this for the aio client on its own.

The aio support in this PR (configuration.py field + the TCPConnector override in rest.py) is hand-written, not generator-templated, because aiohttp has no public equivalent to urllib3's proxy_ssl_context - it required overriding a private TCPConnector method to give the proxy leg its own SSL context.

So it's the one piece of this PR not backed by the generator - it'd need to be manually reapplied (or ported to an aiohttp template upstream) after any future regen. Happy to drop it and keep this PR scoped to the sync client if you'd rather not carry hand-maintained code here - your call.

@yliaog

yliaog commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@emmanuel-adu regen does not have the test, right? i think we want to merge this PR, please take a look at the question about aio, if it is needed.

@emmanuel-adu

emmanuel-adu commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@yliaog Correct - regen wouldn't add the e2e test on its own, e2e tests are hand-maintained in this repo, not templated by the generator (same as the rest of the test suite).

Replied inline on the aio question - the upstream generator PR doesn't touch the aiohttp templates, so the aio changes here are hand-written and not backed by regen. Left it to you whether to keep or drop that part.

@emmanuel-adu
emmanuel-adu requested a review from yliaog August 10, 2026 06:20
@yliaog

yliaog commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

/close

@kubernetes-prow kubernetes-prow Bot closed this Aug 10, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

@yliaog: Closed this PR.

Details

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@yliaog

yliaog commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

/reopen

@kubernetes-prow kubernetes-prow Bot reopened this Aug 10, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

@yliaog: Reopened this PR.

Details

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@yliaog

yliaog commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@emmanuel-adu we can merge the first commit, could you please drop the other 3 commits in the PR? so we can focus on the fix for sync client.

@emmanuel-adu
emmanuel-adu force-pushed the feat/proxy-ssl-context branch from b61be45 to f526d68 Compare August 11, 2026 01:34
@emmanuel-adu

emmanuel-adu commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@yliaog Done - dropped the asyncio commits, this PR is now just the sync client fix (kubernetes/client/configuration.py, kubernetes/client/rest.py, and the e2e test).

@yliaog

yliaog commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 11, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: emmanuel-adu, yliaog

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 11, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 6c710e4 into kubernetes-client:master Aug 11, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proxy SSL Context

3 participants