Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Attempt to implement exec-plugins support in kubeconfig #75

Merged
merged 1 commit into from
Sep 6, 2018

Conversation

dovreshef
Copy link
Contributor

Hi

This is my attempt to implement exec plugin support.
I've only tested this using Python3 with EKS.
I'm also only supporting token authentication for now, since it was not clear to me how to support anything else.
I'm willing to do the necessary changes to get it to merge, but I might need help.

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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. 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 Jul 18, 2018
@codecov-io
Copy link

codecov-io commented Jul 18, 2018

Codecov Report

Merging #75 into master will decrease coverage by 0.21%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #75      +/-   ##
==========================================
- Coverage   91.85%   91.63%   -0.22%     
==========================================
  Files          11       13       +2     
  Lines         994     1124     +130     
==========================================
+ Hits          913     1030     +117     
- Misses         81       94      +13
Impacted Files Coverage Δ
config/kube_config_test.py 93.64% <100%> (+0.13%) ⬆️
config/kube_config.py 83.77% <75%> (-0.5%) ⬇️
config/exec_provider.py 82.6% <82.6%> (ø)
config/exec_provider_test.py 98.36% <98.36%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c9b3113...becae56. Read the comment docs.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 19, 2018
@dovreshef
Copy link
Contributor Author

@roycaihw What is the process to get this reviewed and (hopefully) accepted?

@ltamaster
Copy link
Contributor

I tested this PR and worked, any plan to merge it?
Thanks
Luis

@dovreshef dovreshef force-pushed the master branch 4 times, most recently from 999c199 to d56d8df Compare August 12, 2018 13:16
@cliffpracht
Copy link

cliffpracht commented Aug 14, 2018

This is working for me as well. 👍
@mbohlool @yliaog @roycaihw
Anything we can do to make this better? or merged in?
Thanks!

@roycaihw roycaihw self-assigned this Aug 14, 2018
@anneschuth
Copy link

I'd love to see this merged too.

@yliaog
Copy link
Contributor

yliaog commented Aug 20, 2018

thanks for the pr. has this been tested with python 2.7.12?

@cliffpracht
Copy link

I have tested this with 2.7.15.

@@ -0,0 +1,79 @@
# Copyright 2016 The Kubernetes Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/2016/2018/ for all copyright notices?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

def setUp(self):
self.input_ok = {
'command': 'aws-iam-authenticator token -i dummy',
'apiVersion': 'client.authentication.k8s.io/v1alpha1'
Copy link
Contributor

Choose a reason for hiding this comment

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

s/v1alpha1/v1beta1/ for all the tests? the feature is v1beta1 is 1.11

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

'apiVersion': self.api_version,
'kind': 'ExecCredential',
'spec': {
'interactive': True
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it hard coded to True?

Copy link
Contributor Author

@dovreshef dovreshef Sep 2, 2018

Choose a reason for hiding this comment

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

I have changed it to be the same as the process's stdout (using sys.stdout.isatty()), which is what was done here https://github.com/kubernetes/kubernetes/blob/7b6647a418c660f2c87f183f706b297f1cb573ca/staging/src/k8s.io/client-go/plugin/pkg/client/auth/exec/exec.go#L128 (I think).
But I'm still not clear whether or not I should detect interactive stdin as well. Also, if it is interactive, what else am I supposed to do.


class ExecProvider(object):
def __init__(self, exec_config):
for key in ['command', 'apiVersion']:
Copy link
Contributor

Choose a reason for hiding this comment

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

could you list explicitly what is implemented (v1beta1, right?) as listed in the proposal (https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md), or better, what is left out.

AFAICT, TLS cert, caching are not implemented.

what about refreshing? what to do when token expires?

Copy link
Contributor Author

@dovreshef dovreshef Sep 2, 2018

Choose a reason for hiding this comment

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

TLS cert, caching are indeed not implemented.

TLS cert

I did not implement it.
My reading of the proposal language
TLS client certificate support is orthogonal to bearer tokens, but something that we should consider supporting in the future.
lead me to think it is not implemented in the go client as well.

caching

I can try to add caching by basing it on the way it is implemented for the other auth methods, taking into account the expiry field.
But there is a problem. Right now aws-iam-authenticator does not return anexpiry field, even though the returned token is only valid for a short period (15 minutes IIRC).
The proposal on the other hand specifies:
Plugins can indicate their credentials explicit expiry using the Expiry field on the returned ExecCredentials object, otherwise credentials will be cached throughout the lifetime of a program.

I can check the return value if it is 401 and in that case re-execute the plugin, which is what the proposal also recommends. But I do not understand the code well enough for that.
Can you point me where in the code would it be best to hook up such a mechanism?

what about refreshing? what to do when token expires?

Right now I do not cache the token at all. So since the plugin always executes, the token received is always fresh.

Copy link
Contributor

Choose a reason for hiding this comment

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

since this is a highly desired feature, and it is orthogonal to the other auth methods. I think it is safe to merge with some missing features. people who need those features can implement them on top of this later.

so could you please add some comments about what features are missing, and probably a link
to the design (https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md). then I think we can merge it. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Hope it's ok.

@anneschuth
Copy link

anneschuth commented Aug 23, 2018

How far from getting this merged are we? Is there anything I can do to help this go through faster?

@yliaog
Copy link
Contributor

yliaog commented Aug 23, 2018

I don't think it's far. I put in some comments, as soon as those are addressed, we can merge it.

@macat
Copy link

macat commented Aug 23, 2018

@dovreshef Do you need help fixing @yliaog's comments? Thanks for building this BTW.

@dovreshef
Copy link
Contributor Author

@macat I'd be glad for help. I'll not be able to get to this before Monday.

@gitfool
Copy link

gitfool commented Aug 30, 2018

👍

@dovreshef
Copy link
Contributor Author

dovreshef commented Sep 2, 2018

Hi all. I have updated the PR.

I'm sorry about the delay, real life intervened.

Edit: Also, I don't know what This pull-request has been approved by: dovreshef above means, I did not approve it, merely updated it.

@gitfool
Copy link

gitfool commented Sep 2, 2018

No worries. I’m using a monkey patch with this change to tide me over. 😉

status = ExecProvider(self._user['exec']).run()
if 'token' not in status:
raise ConfigException(
'Missing token field in exec plugin response')
Copy link
Contributor

Choose a reason for hiding this comment

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

i think it's better to catch all the exceptions and return None in case there is any exception, just to give a chance to other auth methods. that is the general pattern used by other load...() methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.
Then there is no reason throw any exception at all in exec_provider.py?
In that case how should I inform the user if the exec process return an error, or missing exec config, etc?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's still good to have exceptions from exec_provider.py, then in kube_config.py, when it catches the exception, it could log it, and proceed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I have used logging.error since it seems to me to be more of an error than a warning. Since it implies an incorrect exec config / result.

@yliaog
Copy link
Contributor

yliaog commented Sep 6, 2018

thanks for the PR.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 6, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dovreshef, yliaog

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 Sep 6, 2018
@k8s-ci-robot k8s-ci-robot merged commit d68e456 into kubernetes-client:master Sep 6, 2018
@anneschuth
Copy link

thanks a lot!

@timoreimann
Copy link

For posterity: this one fixes kubernetes-client/python#514

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 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.

None yet