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

Out-of-tree client authentication providers (UserCredentials exec option) for asp.net core applications #359

Merged
merged 12 commits into from Mar 5, 2020

Conversation

ghost
Copy link

@ghost ghost commented Feb 20, 2020

after facing the same problem described in: #340
I've tried to create a version that will allow me to receive the token using an external command execution (as kubeconfig supports).

Implemented according to:
https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md
and with inspiration from the kubernetes python implementation (https://github.com/kubernetes-client/python-base/blob/master/config/exec_provider.py)

1. I haven't written tests
2. Token refreshment hasn't been implemented meaning that once the token is expired a new token has to be generated, I am currently using my kubernetes "access layer" from the DI with a scoped life time cycle.
3. I've tested it running on Linux (Amazon Linux 2) only, not sure if it works properly on Windows/any other creature ;)

Would appreciate help finishing and wrapping this up for usage.

@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 Feb 20, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @talboren!

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 Feb 20, 2020
@ghost
Copy link
Author

ghost commented Feb 20, 2020

/assign @krabhishek8260

@ghost
Copy link
Author

ghost commented Feb 20, 2020

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.

Signed the CLA

@ghost
Copy link
Author

ghost commented Feb 20, 2020

Seems like Process and Environment.UserInteractive are not supported by all dependencies.

	new file:   src/KubernetesClient/KubeConfigModels/ExecCredentialResponse.cs
	new file:   src/KubernetesClient/KubeConfigModels/ExternalExecution.cs
	modified:   src/KubernetesClient/KubeConfigModels/UserCredentials.cs
	modified:   src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
…hentication in case it is not a asp.net core app
@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 Feb 20, 2020
@ghost ghost changed the title Out-of-tree client authentication providers (UserCredentials exec option) Out-of-tree client authentication providers (UserCredentials exec option) for asp.net core applications Feb 20, 2020
@brendandburns brendandburns requested review from tg123 and removed request for krabhishek8260 February 21, 2020 03:24
@brendandburns
Copy link
Contributor

Thanks for the PR. This looks great to me, but we need unit tests for this before we merge it.

Thanks!

@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 cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 24, 2020
@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 Feb 24, 2020
@ghost
Copy link
Author

ghost commented Feb 24, 2020

@brendandburns I've added 2 tests, let me know if that's OK.

@ghost
Copy link
Author

ghost commented Feb 25, 2020

@brendandburns I'm having trouble making the tests pass with OSX due to some issues I am experiencing with 'echo' (different behavior than Linux?), any chance you have any idea?

@brendandburns
Copy link
Contributor

I looked at the error, the JSON parse error is:

k8s.Exceptions.KubeConfigException : external exec failed due to uncaught exception: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing number: n. Path '', line 1, position 1.

You might consider using base64 encoding (e.g. base64 -d <response-string> | echo) to work around quoting/escaping issues.

But I'm not sure what bit is having a problem. I have an old Mac at home, I'll try to repro sometime if you still can't figure it out.

/// Environment variables to set when executing the plugin. Optional.
/// </summary>
[YamlMember(Alias = "env")]
public Dictionary<string, string> EnvironmentVariables { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

IDictionary if possible

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.

I did not quite catch about why this is related to asp.net core. did not see anything related to asp.net

/// Arguments to pass when executing the plugin. Optional.
/// </summary>
[YamlMember(Alias = "args")]
public List<string> Arguments { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

IList?

@@ -365,6 +390,83 @@ public static string RenewAzureToken(string tenantId, string clientId, string ap
throw new KubeConfigException("Refresh not supported.");
}

#if NETCOREAPP
Copy link
Member

Choose a reason for hiding this comment

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

why this is specific to netcore, can it be netstandard?

if (string.IsNullOrWhiteSpace(stderr) == false)
throw new KubeConfigException($"external exec failed due to: {stderr}");

process.WaitForExit();
Copy link
Member

Choose a reason for hiding this comment

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

timeout?

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Feb 26, 2020
Changed OSX testing command to printf to try and solve the JSON
parsing errors
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Feb 26, 2020
@tg123
Copy link
Member

tg123 commented Feb 26, 2020

I am working on migrating the codebase to .netstandard2.0

@ghost ghost requested a review from tg123 February 26, 2020 08:52
@ghost
Copy link
Author

ghost commented Feb 29, 2020

@tg123 @brendandburns still waiting for your approval.

@tg123
Copy link
Member

tg123 commented Mar 1, 2020

@talboren any chance to take a look at my comments?

@ghost
Copy link
Author

ghost commented Mar 1, 2020

@tg123 please note my latest commits. I’ve made changes according to your changes. What are you talking about?

@tg123
Copy link
Member

tg123 commented Mar 1, 2020

@talboren sorry forget to click publish :( I forget to do so many times

@ghost ghost requested a review from tg123 March 3, 2020 16:01
@brendandburns
Copy link
Contributor

@tg123 are you ok with merging this? Any other comments need addressing?

Thanks!

@tg123
Copy link
Member

tg123 commented Mar 3, 2020

/LGTM

lets make timeout configurable later if necessary

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 3, 2020
@brendandburns
Copy link
Contributor

/approve

thanks for the PR (and the patience)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, talboren

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 Mar 5, 2020
@k8s-ci-robot k8s-ci-robot merged commit b07e78a into kubernetes-client:master Mar 5, 2020
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.

5 participants