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

OIDC support #544

Merged

Conversation

arbielsk
Copy link
Contributor

@arbielsk arbielsk commented Jan 7, 2021

Feature
Add support for OpenID Connect. This includes a new OidcTokenProvider which is able to refresh tokens. A new dependency is introduced in the form of IdentityModel.OidcClient.
While at it, I fixed a few typos in comments in src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs

Motivation
At my company we are avid users of Bridge-To-Kubernetes which uses the C# K8S Client under the hood. We currently have multiple teams that are blocked from using Bridge-To-Kubernetes since the C# K8S client currently does not support OIDC. I therefore created this PR with the intent of adding OIDC support to C# K8S client so it can be integrated into Bridge-To-Kubernetes.

Disclaimer
I am not a C# developer. In fact this is the first C# code I have ever written. I therefore would like to ask for a thorough review; I am more than happy to update the PR to conform with any best practices, style guides and testing coverage as you see fit. I would be very grateful for any feedback!

I am also currently seeing the following warning and due to my unfamiliarity with C# I am unsure how to solve it optimally:

csharp/src/KubernetesClient/Extensions.cs(8,25): warning CA1724: The type name Extensions conflicts in whole or in part with the namespace name 'Microsoft.Extensions'. Change either name to eliminate the conflict.

Thank you for taking the time to review and consider this PR!
My team is very much looking forward to seeing this feature downstream in Bridge-To-Kubernetes as soon as possible, as this will significantly reduce our development efforts on multiple projects.

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

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

Welcome @arbielsk!

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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 7, 2021
@arbielsk
Copy link
Contributor Author

arbielsk commented Jan 7, 2021

CNCF ICLA accepted.

@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 Jan 7, 2021
@arbielsk
Copy link
Contributor Author

arbielsk commented Jan 7, 2021

There seem to be non-deterministic tests in LeaderElectionTests.cs

Example
Run: https://github.com/kubernetes-client/csharp/actions/runs/468548275

Tests finish successfully for Ubuntu, but fail for MacOS with same code. On my local machine (MacOS) the tests run successfully (3/3 runs, no test failures).

Also without any code changes, the result for tests on the Ubuntu build differ between these two runs (I added an empty commit to re-trigger Github Actions):
https://github.com/kubernetes-client/csharp/actions/runs/468492411
https://github.com/kubernetes-client/csharp/actions/runs/468548275

I don't believe this is in the scope of this PR as it should be independent of the LeaderElection feature if I am interpreting the code correctly.

@tg123
Copy link
Member

tg123 commented Jan 7, 2021

seems Microsoft.Extensions was introduce by new dependency

@arbielsk
Copy link
Contributor Author

arbielsk commented Jan 8, 2021

seems Microsoft.Extensions was introduce by new dependency

Yes it definitely was. However I am unsure what the correct resolution would be:

  • Rename Extensions in K8S Client?
  • Try to find a OIDC client that doesn't rely on Microsoft.Extensions (and is possibly lower quality)?
  • Something I am not aware of?

Due to my unfamiliarity with C# I am also unsure on the possible implications of this conflict and the gravity of the warning.

@brendandburns
Copy link
Contributor

Can you just use explicit full package names (e.g. k8s.Extensions) to eliminate the abiguity?

@tg123
Copy link
Member

tg123 commented Jan 8, 2021

you may want rebase master to get rid of flaky testcases

i am fine with allow CA1723 in our repo, see kubernetes-client.ruleset in our repo.

@arbielsk
Copy link
Contributor Author

arbielsk commented Jan 9, 2021

Can you just use explicit full package names (e.g. k8s.Extensions) to eliminate the abiguity?

@brendandburns I've spent a little more time educating myself on the issue. As far as I understand the issue, the warning is produced because the type name Extensions in namespace k8s that has a partial conflict with the namespace name Microsoft.Extensions which is introduced by the OidcClient dependency. I therefore believe (with my limited knowledge of C#) that your suggestion is not applicable in this context as this is not about two type names being in conflict. If I am misunderstanding, I apologize.

I therefore understand that there are the following possible resolutions:

  • accept the warning as suggested by @tg123
  • rename the Extensions type to something different that seems appropriate. Maybe MetadataExtensions as the code seems to be related to that? I've tried renaming the class and file and the tests are still passing, including the VersionConverter Tests that are relying on this functionality.

@tg123 @brendanburns Please let me know what your preferred way of solving this would be. I have a commit prepared to rename the type name to MetadataExtensions but have not pushed it (yet), as I believe the strategy for handling this warning should be your call.

Thank you again for taking the time to review my PR!

@brendandburns
Copy link
Contributor

Accepting the warning for now is fine with me.

If we want to make the change, we need to make it across a major version since it is a breaking change.

@tg123
Copy link
Member

tg123 commented Jan 13, 2021

please add CA1723 to kubernetes-client.ruleset to disable warning
then LGTM

@arbielsk
Copy link
Contributor Author

Thanks again, @brendanburns @tg123 for getting back to me so quickly. I've added CA1724 to the exceptions and added a comment explaining the situation.
Looking forward to seeing this merged :)

Thanks again and have a great night!

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.

/LGTM

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 13, 2021
@arbielsk
Copy link
Contributor Author

/assign @brendandburns

@brendandburns
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arbielsk, brendandburns, 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 Jan 19, 2021
@k8s-ci-robot k8s-ci-robot merged commit 143db15 into kubernetes-client:master Jan 19, 2021
@arbielsk
Copy link
Contributor Author

Thank you, @tg123, @brendandburns!

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.

4 participants