-
Notifications
You must be signed in to change notification settings - Fork 166
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
Adds support for exec credential plugin #363
Conversation
Neat! 👏 Havent reviewed in detail yet. I wonder if this can/should be opt-in (a separate method like |
Close-cycling to re-run tests fixed by #364. |
@cben I believe we should add a warning in README. According to this client-go issue comment, exec credential will eventually replace any Azure, GCP and alike credential providers (which makes sense). I am currently trying to figure out a way to implement token refreshment mechanism. There will be cases in which the client is initialized with a token that expires after an hour and a refreshing mechanism should come into play before the next API call is made. BTW - I think this is also true for GoogleApplicationDefaultCredentials token. Any idea? |
I need this for EKS on AWS which uses the |
Sorry for silence, I'm trying to land some discovery related stuff before fully context-switching to this...
Thanks for the context. Yeah, this is important. Now, about refreshment.That's a bigger effort, may be better to land this first. One idea I have is for |
(sent too soon, edited now ^^) |
end | ||
|
||
raise 'exec plugin didn\'t return a status field' if creds['status'].nil? | ||
raise 'exec plugin didn\'t return a token' if creds['status']['token'].nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These string exceptions should become some exception class.
KubeException
is deprecated because it's in global namespace, we've documented "The gem raises Kubeclient::HttpError or subclasses now." But Kubeclient::HttpError
is inappropriate here.
This is not very important, until we actually try to remove KubeException
.
What's more interesting is understand when this can be raised. If we'll support auto-renewal, then ANY request such as get_pods
would potentially also raise these!
What exceptions does Config
raise presently? I see KeyError
, and one string 'Unknown kubeconfig version'.
You're adding some ArgumentError
and strings.
Perhaps add Kubeclient::ConfigError
for all config problems?
BTW, if we add opt-out, need to choose error for refusing to exec commands too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cben I agree, KubeClient::ConfigError
can be a good candidate for configuration errors.
@cben For refreshing, I was thinking about the following:
def bearer_token(bearer_token)
token = bearer_token.respond_to?(:call) ? bearer_token.call : bearer_token
@headers ||= {}
@headers[:Authorization] = "Bearer #{token}"
end
def handle_exception
retry_count = 0
begin
yield
rescue RestClient::Exception => e
if e.http_code == 403
retry_count += 1
retry if retry_count < (@auth_options[:max_retries] || 1)
end
json_error_msg = begin
JSON.parse(e.response || '') || {}
rescue JSON::ParserError
{}
end
err_message = json_error_msg['message'] || e.message
error_klass = e.http_code == 404 ? ResourceNotFoundError : HttpError
raise error_klass.new(e.http_code, err_message, e.response)
end
end Thoughts? |
Do we need retry, or do we have sufficient info to renew before it expires?https://kubernetes.io/docs/reference/access-authn-authz/authentication/#input-and-output-formats
OK, we'll need ability to retry. Is it always bearer tokens?No, executed plugin might choose to return Does caching belong in
|
Did I mention that it's simpler to first land this without renewal? 😉 |
Hi, I just pulled this PR and rebased up and it works great on all my istio 1.0.4 eks (k8 10) & aks (k8 11.0.4) clusters. Without this PR, kubeclient doesn't work with eks - period. Kindly, take this PR and perfect it later. 👍 |
|
||
raise ArgumentError, 'exec options are required' if opts.nil? | ||
|
||
cmd = opts['command'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for future (not blocker): if command
is relative path, the Go implemetation resolves it relative to the kubeconfig file
https://github.com/kubernetes/kubernetes/pull/59495/files/6463e9efd9ba552e60d2555a3e6526ef90196473#diff-4c107b9e9f7f10a98e5c52f66b952e01R562
Sorry, should have merged before. Though I wanted to make some changes — at least document — before releasing. I'm not converting string exceptions to class(es). The |
Hey!
This PR offers a partial implementation of the Kube Config ExecCredential plugin (#362).
This was Inspired by: https://github.com/kubernetes/client-go/blob/master/plugin/pkg/client/auth/exec/exec.go
Things to consider: