Skip to content

Conversation

KLazarov
Copy link
Contributor

Implemented fix proposed at: #859

Problem:

Currently the cert verification works only if there is no multi level CA chain that it needs to verify on. If the chain is too long, it will mark isTrusted as false.

Suggestion

Instead of trying to directly compare the certs, we actually build the cert with the help of the chain and verify that it's correct. If the cert or the chain are broken, then isTrusted will be false. If the chain and cert is correct, then isTrusted will be true.

… respect to the rootChain certs to verify that they are correct.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 20, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 20, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @KLazarov!

It looks like this is your first PR to kubernetes-client/csharp 🎉. 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/csharp 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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 20, 2022
@tg123
Copy link
Member

tg123 commented May 21, 2022

could please sign cla and add testcases?

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 23, 2022
@KLazarov
Copy link
Contributor Author

I have now added the tests for the issue that my code fixes. They are at the bottom of CertificateValidationTests.cs.

I'm still waiting from my company to completly fill out the EasyCLA as we got a bit stuck on it during the weekend.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 23, 2022
@KLazarov
Copy link
Contributor Author

The EasyCLA has now been accepted.

@tg123
Copy link
Member

tg123 commented May 23, 2022

I looked into the code and seems your #859 code

chain.ChainPolicy.CustomTrustStore.Add(ca)

makes more sense

here the code is verifying if each ca cert on the cert's chain
should that be verifying cert's chain on a trusted ca?

what is your idea?

@KLazarov
Copy link
Contributor Author

KLazarov commented May 23, 2022

The issue that I stumbled upon and I'm trying to fix here is if there is a chain that is multiple steps long in a single file provided by the Service Account.

As we are running a managed Kubernetes cluster, we get our Certificates generated by the provider, and in our case there are multiple certificates in the same file, and they describe the full chain. From my understanding running chain.Build(cert) verifies that the cert that it tries to connect with is actually correctly generated from the Chain.

From what I see
chain.ChainPolicy.CustomTrustStore.Add(ca)
will not work, as it still needs to verify that the certificate, and it's easiest to do that using chain.Build(cert).

Do correct me if it's wrong/incorrect.

@tg123
Copy link
Member

tg123 commented May 23, 2022

ok could you please also remove var rootCert = chain.ChainElements[chain.ChainElements.Count - 1].Certificate; since it is no longer used.

then /LTGM

@KLazarov
Copy link
Contributor Author

KLazarov commented May 23, 2022

Done.

@k8s-ci-robot
Copy link
Contributor

@KLazarov: you cannot LGTM your own PR.

In response to this:

/lgtm

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/test-infra repository.

@KLazarov
Copy link
Contributor Author

Btw just read in the guide lines about squashing and commit message length: https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md#squashing

I will squash it into one commit tomorrow.

Copy link
Member

@tg123 tg123 left a comment

Choose a reason for hiding this comment

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

/LTGM

@tg123
Copy link
Member

tg123 commented May 24, 2022

/

Btw just read in the guide lines about squashing and commit message length: https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md#squashing

I will squash it into one commit tomorrow.

you do not have to, it is automatic

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KLazarov, tg123

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 24, 2022
@tg123
Copy link
Member

tg123 commented May 24, 2022

/LGTM

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 24, 2022
@k8s-ci-robot k8s-ci-robot merged commit 877587e into kubernetes-client:master May 24, 2022
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

3 participants