Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing of custom pool manager #2335

Closed
wants to merge 2 commits into from

Conversation

rossigee
Copy link

What type of PR is this?

/kind feature

(although from some perspectives it could be considered a bug!)

What this PR does / why we need it:

Summary: Then using the load_kube_config method, the python library is (apparently?!) unable to connect securely to a cluster where the cluster API endpoints are secured with CA certificates that have been signed by an internal/external CA authority (i.e. not self-signed).

Why is this? It seems that only the cluster CA gets stored in the ~/.kube/config file, not the whole certificate chain. Therefore, the library can only resolve the chain if it is self-contained (self-signed). If it depends on additional certificates it will fail an exception something like this...

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='k8s-api.cluster.xyz', port=6443): Max retries exceeded with url: /api/v1/namespaces/vm-nodes/serviceaccounts (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get issuer certificate (_ssl.c:1000)')))

Issue: Currently, there does not seem to be any way to control the way the REST client pool_manager is created, and it's default configuration makes it impossible (AFAICS?!) to correctly/cleanly specify the CA chain to use.

Which issue(s) this PR fixes:

Fixes #2329

Special notes for your reviewer:

N/A

Does this PR introduce a user-facing change?

Adds the ability to specify a custom CA chain for cases where the Kubernetes API is using externally-signed certificates.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

If you are using `load_kube_config` with a cluster that requires a certificate chain, you can supply a custom PoolManager that like this:

\`\`\`
    kubernetes.config.load_kube_config()
    custom_pool_manager = urllib3.PoolManager(
        cert_reqs="CERT_REQUIRED",
        ca_certs="/etc/ssl/certs/ca-certificates.crt"
    )
    api_client = kubernetes.client.ApiClient(pool_manager=custom_pool_manager)
    v1 = kubernetes.client.CoreV1Api(api_client)
\`\`\`

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Jan 26, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rossigee
Once this PR has been reviewed and has the lgtm label, please assign roycaihw for approval. For more information see the Code Review Process.

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

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 26, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @rossigee!

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. 😃

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 26, 2025
@rossigee
Copy link
Author

Pls ignore. It wasn't clear from the docs, but I've (eventually!!) figured out how to do this.

@rossigee rossigee closed this Jan 26, 2025
@rossigee rossigee deleted the rest-pool-manager branch January 26, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
2 participants