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

Adding support for kubectl ExecCredential output #72

Merged
merged 5 commits into from
Apr 12, 2018
Merged

Adding support for kubectl ExecCredential output #72

merged 5 commits into from
Apr 12, 2018

Conversation

christopherhein
Copy link
Member

@christopherhein christopherhein commented Apr 7, 2018

Why:

  • Allows you to use the heptio-authenticator-aws binary in your ~/.kube/config as an external ExecCredential

Usage:

users:
- name: user
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: heptio-authenticator-aws
      args:
        - "token"
        - "--cluster-id"
        - "cluster-id"

This change addresses the need by:

Todos:

  • Documentation for usage on the readme.md
  • Add error handling to the token response (not sure if this is possible or needed)

Questions:

  • Do we need to implement a check for KUBERNETES_EXEC_INFO?
  • Do we need the expirationTimestamp it's optional per the documentation, if so could you provide me a little guidance on where to make or get that from?

https://kubernetes.io/docs/admin/authentication/#client-go-credential-plugins

Signed-off-by: Christopher Hein [email protected]

@christopherhein christopherhein changed the title Adding support for kubectl execcommand output Adding support for kubectl ExecCredential output Apr 7, 2018
@nckturner
Copy link
Contributor

Can you separate vendor into a separate commit to make this more reviewable?

**Why:**

* Allows you to use the `heptio-authenticator-aws` binary in your
`~/.kube/config` as an external authProvider

**Usage:**

```yaml

users:
- name: user
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: heptio-authenticator-aws
      args:
        - "token"
        - "--cluster-id"
        - "cluster-id"
```

**This change addresses the need by:**

* closes #64

Signed-off-by: Christopher Hein <[email protected]>
**Why:**

* Separated this commit to make reviewing easier

Signed-off-by: Christopher Hein <[email protected]>
@christopherhein
Copy link
Member Author

christopherhein commented Apr 9, 2018

@nckturner Updated with commits separated, I should have error handling done soon to review that as well.

Also rebased master so it has the proper build mechanisms.

@christopherhein
Copy link
Member Author

I was mistaken about the flow for the authenticator, I thought it passed a token to the API server that it validated after learning a little more it's passing a signed URL that the server uses to in essence callsts:getCallerIdentity with that being the flow I'm not sure how I can do error handling like defined - https://kubernetes.io/docs/admin/authentication/#input-and-output-formats

Any thoughts or suggestions?

@@ -35,7 +35,7 @@ var tokenCmd = &cobra.Command{
clusterID := viper.GetString("clusterID")

if clusterID == "" {
fmt.Fprintf(os.Stderr, "error: cluster ID not specified\n")
fmt.Fprintf(os.Stderr, "Error: cluster ID not specified\n")
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to be cohesive with the default Cobra error responses. heptio-authenticator-aws token -i for example returns:

Error: flag needs an argument: 'i' in -i

**Why:**

* Documentes how to configured your `kubeconfig` to use `ExecCredential`
  `client-go` mechanisms.
* Changes some of the documented comments to reflex `clientauth` vs 1.10
  release

Signed-off-by: Christopher Hein <[email protected]>
@@ -180,6 +184,21 @@ func (g generator) GetWithRole(clusterID string, roleARN string) (string, error)
return v1Prefix + base64.RawURLEncoding.EncodeToString([]byte(presignedURLString)), nil
}

// FormatJSON formats the json to support 1.10 external authProvider
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in a later commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think this version is slightly more readable. The docs and implementation use different names in different places, so I'll leave it to you, but something like 1.10 client-go exec-based auth provider would be explicit enough.

Copy link
Contributor

@nckturner nckturner left a comment

Choose a reason for hiding this comment

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

Looking pretty good, a few comments. Also, you might need to consume KUBERNETES_EXEC_INFO in order to determine if the caller is interactive, or perhaps we can detect it, and we need to make sure interactive mode works with MFA.

README.md Outdated
@@ -82,13 +82,26 @@ systemctl restart kubelet.service
```

### 4. Set up kubectl to use Heptio Authenticator for AWS tokens

> This requires a 1.10+ `kubectl` binary to work. If you receive `Please enter Username:` when trying to use `kubectl` you need to update to the latest `kubectl`

Finally, once the server is set up you'll want to authenticate!
You will still need a `kubeconfig` that has the public data about your cluster (cluster CA certificate, endpoint address).
The `users` section of your configuration, however, can be mostly blank:
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of:

can be mostly blank:

say:

should include an exec section (refer to the v1.10 docs):

README.md Outdated
To authenticate, run `kubectl --kubeconfig /path/to/kubeconfig --token "$(heptio-authenticator-aws token -i CLUSTER_ID -r ROLE_ARN)" [...]`.
You can simplify this with an alias or shell wrapper.
To authenticate, run `kubectl --kubeconfig /path/to/kubeconfig" [...]`.
kubectl will handle `exec`'ing the `heptio-authenticator-aws` binary with the supplied params in your kubeconfig which will generate a token and pass it to the apiserver.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: kubectl will exec the ...

@@ -180,6 +184,21 @@ func (g generator) GetWithRole(clusterID string, roleARN string) (string, error)
return v1Prefix + base64.RawURLEncoding.EncodeToString([]byte(presignedURLString)), nil
}

// FormatJSON formats the json to support 1.10 external authProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think this version is slightly more readable. The docs and implementation use different names in different places, so I'll leave it to you, but something like 1.10 client-go exec-based auth provider would be explicit enough.

@@ -58,7 +58,9 @@ var tokenCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "could not get token: %v\n", err)
os.Exit(1)
}
fmt.Println(tok)

enc := gen.FormatJSON(tok)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

fmt.Println(gen.FormatJSON(tok))

Signed-off-by: Christopher Hein <[email protected]>
@christopherhein
Copy link
Member Author

@nckturner updated based on your review. For the MFA, assuming we can track that separately through #42 right?

@nckturner
Copy link
Contributor

I'd like to merge this after #42, I've proposed how we do that on that PR.

@nckturner nckturner merged commit 3b5322c into kubernetes-sigs:master Apr 12, 2018
@christopherhein christopherhein deleted the feature/add-kubectl-output branch April 12, 2018 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support kubectl external credential provider
2 participants