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

#238: support client.authentication.k8s.io/v1beta1 ExecCredential #512

Merged
merged 11 commits into from
Mar 8, 2019

Conversation

jglick
Copy link
Contributor

@jglick jglick commented Feb 20, 2019

Implementation of #238 allowing ~/.kube/config to use the new generic exec credentials rather than a vendor-specific plugin or hard-coded token.

Planning to do before taking out of “draft” status:

  • basic implementation (run a command, get a token)
  • observed working with GKE
  • KubeConfigTest addition
  • relativization to basedir
  • environment variables
  • more robustness against bad inputs, logging, etc.

Other things which I think could be left for follow-ups depending on demand:

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 20, 2019
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 20, 2019
Object exec = currentUser.get("exec");
if (exec != null) {
// TODO extract to helper method for clarity
Map<String, Object> execMap = (Map<String, Object>) exec;
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 probably better to declare an actual Java object that represents the exec field rather than using generic JSON accessors, it makes the code pretty ugly.

Copy link
Contributor

Choose a reason for hiding this comment

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

(I realized I'm being hypocritical given the above, so feel free to ignore this...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hypocritical given the above

You mean the authProviderMap code?

After years of bad experiences I have a general preference for plain old Java code over use of fancy reflection-based (de)serialization libraries, but if you have a strong preference for some particular approach (GSON?) I will follow your guidelines.

Choose a reason for hiding this comment

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

@jglick - is the item "observed working with EKS (I could make a test cluster if necessary)" still open, and if not, could I help out with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is still open. If you are using EKS, please help test this system.

if (r == 0) {
if (root != null) {
// TODO verify .apiVersion and .kind = ExecCredential
JsonObject status = root.getAsJsonObject().get("status").getAsJsonObject();
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create a real Java object for this response value too.

Copy link
Contributor

Choose a reason for hiding this comment

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

As above, feel free to skip if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(ditto)

@brendandburns
Copy link
Contributor

Thanks for starting this! I have a few comments, also this needs unit tests.

jglick added 4 commits March 4, 2019 15:06
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 4, 2019
@jglick jglick marked this pull request as ready for review March 6, 2019 17:07
Process proc = pb.start();
JsonElement root;
try (InputStream is = proc.getInputStream();
Reader r = new InputStreamReader(is, StandardCharsets.UTF_8)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation is weird here, is this really correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What looks incorrect? I do not have a choice about indentation—it is whatever mvn fmt:format picks.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, the 'R' aligned with the '(' looks weird to me, but if mvn:format says so, I guess it's right :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah my preference would be to line up the I and the R.

return null;
}
return root;
} catch (IOException | InterruptedException x) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why swallow the exception here? wouldn't you rather throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not swallowed—it is sent to the log.

As to whether it is appropriate to throw exceptions out of getAccessToken (presumably wrapped in RuntimeException?) as opposed to logging and proceeding with other authentication modes and ultimately returning null (unauthenticated), I have no strong opinion. I was following the example of existing code which proceeds despite errors (Failed to read token file for example).

On the other hand AzureActiveDirectoryAuthenticator.refresh appears to throw an undeclared exception out of getAccessToken. KubeconfigAuthentication.<init> is permitted to throw IOException so perhaps getAccessToken should as well? That would mean reworking some existing code which catches and logs exceptions, and adding IOException to the signature of Authenticator.refresh.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, sounds like it's messy, let's take it as a follow-on cleanup exercise...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted in PR description.

@brendandburns
Copy link
Contributor

Looks pretty good, some minor nits.

@brendandburns
Copy link
Contributor

/lgtm
/approve

Thanks!

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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 7, 2019
@brendandburns brendandburns removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 8, 2019
@k8s-ci-robot k8s-ci-robot merged commit 0abbd01 into kubernetes-client:master Mar 8, 2019
@jglick jglick deleted the ExecCredential branch March 8, 2019 19:35
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