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

Add support of client-go credential plugins in auth #396

Merged
merged 1 commit into from
May 9, 2019

Conversation

dh-harald
Copy link
Contributor

@dh-harald dh-harald commented Apr 12, 2019

Closes #161

@bflad
Copy link
Contributor

bflad commented Apr 24, 2019

This looks like this would close #161 so I have edited the PR description to automatically close it. I cannot provide a full review of this enhancement, but can provide some review of the Go/Terraform Provider SDK code. 👍

Copy link
Member

@alexsomesan alexsomesan left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this issue. Change mostly looks good.
I've one suggestion about the type of structure used to model it. See below.

@bflad Happy to have your eyes on it too and please add any suggestions you might have.

@@ -101,6 +101,33 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("KUBE_LOAD_CONFIG_FILE", true),
Description: "Load local kubeconfig.",
},
"exec": {
Type: schema.TypeSet,
Copy link
Member

Choose a reason for hiding this comment

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

Can you please make this a TypeList instead?
I've found that in Terraform 0.12+ a TypeList works best for modeling a complex block, such as this.

@@ -101,6 +101,33 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("KUBE_LOAD_CONFIG_FILE", true),
Description: "Load local kubeconfig.",
},
"exec": {
Type: schema.TypeSet,
Copy link
Contributor

Choose a reason for hiding this comment

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

With MaxItems: 1 configurations blocks, it is generally preferred to use Type: schema.TypeList to simplify handling. 👍

kubernetes/provider.go Show resolved Hide resolved
@@ -109,4 +109,4 @@ The following arguments are supported:
* `config_context_cluster` - (Optional) Cluster context of the kube config (name of the kubeconfig cluster, `--cluster` flag in `kubectl`). Can be sourced from `KUBE_CTX_CLUSTER`.
* `token` - (Optional) Token of your service account. Can be sourced from `KUBE_TOKEN`.
* `load_config_file` - (Optional) By default the local config (~/.kube/config) is loaded when you use this provider. This option at false disable this behaviour. Can be sourced from `KUBE_LOAD_CONFIG_FILE`.

* `exec` - (Optional) Exec-based client auth provider (https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are adding a new configuration block with nested arguments, we should appropriately document everything here. 👍

Suggested change
* `exec` - (Optional) Exec-based client auth provider (https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins)
* `exec` - (Optional) Configuration block to use an [exec-based credential plugin](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins), e.g. call an external command to receive user credentials.
* `api_version` - (Required) API version to use when decoding the ExecCredentials resource, e.g. `client.authentication.k8s.io/v1beta1`.
* `command` - (Required) Command to execute.
* `args` - (Optional) List of arguments to pass when executing the plugin.
* `env` - (Optional) Map of environment variables to set when executing the plugin.

@@ -181,6 +208,18 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
cfg.BearerToken = v.(string)
}

if v, ok := d.GetOk("exec"); ok {
exec := &clientcmdapi.ExecConfig{}
spec := v.(*schema.Set).List()[0].(map[string]interface{})
Copy link
Member

Choose a reason for hiding this comment

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

Also, would you mind breaking down this line into multiple steps and check for errors and nils on the type assertions. This looks like it has the potential to panic.

Copy link
Contributor Author

@dh-harald dh-harald Apr 25, 2019

Choose a reason for hiding this comment

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

In theory, it should pass by the schema checker, but I've added an extra check to avoid the panic

Copy link
Member

@alexsomesan alexsomesan left a comment

Choose a reason for hiding this comment

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

LGTM

@alexsomesan alexsomesan merged commit 64973a4 into hashicorp:master May 9, 2019
alexsomesan pushed a commit to chanzuckerberg/terraform-provider-kubernetes that referenced this pull request May 10, 2019
@@ -101,6 +101,34 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("KUBE_LOAD_CONFIG_FILE", true),
Description: "Load local kubeconfig.",
},
"exec": {
Type: schema.TypeList,
Copy link

Choose a reason for hiding this comment

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

Why wasn't this done as TypeMap?

@chancez
Copy link

chancez commented Feb 21, 2020

Is this in a release? The code is in available at least in 1.10.0, but I'm getting:

Error: Unsupported argument

  on ../../modules/eks-cluster/main.tf line 70, in provider "kubernetes":
  70:   exec = [{

An argument named "exec" is not expected here. Did you mean to define a block
of type "exec"?

@chancez
Copy link

chancez commented Feb 21, 2020

Ah, it's a block. I see.

  exec {
    api_version = "client.authentication.k8s.io/v1alpha1"
    command     = "aws-iam-authenticator"
    args        = concat(["token", "-i", data.aws_eks_cluster.cluster.name], local.authenticator_additional_args)
    env         = local.authenticator_env_vars
  }

@ballad89
Copy link

@chancez did the block above work for you ? what versions are you using ?

$ terraform version                                                                                         ✔  5506  17:22:08
Terraform v0.12.24
+ provider.aws v2.57.0
+ provider.external v1.2.0
+ provider.helm v1.1.1
+ provider.kubernetes v1.11.1
+ provider.local v1.4.0
+ provider.null v2.1.2
+ provider.random v2.2.1
+ provider.template v2.1.2

@chancez
Copy link

chancez commented Apr 13, 2020

It did.

$ terraform version
Terraform v0.12.24
+ provider.aws v2.54.0
+ provider.kubernetes v1.10.0
+ provider.local v1.4.0
+ provider.null v2.1.2
+ provider.random v2.2.1
+ provider.template v2.1.2

@ghost
Copy link

ghost commented Apr 21, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Support exec Authentication (client-go Credential Plugins)
5 participants