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

Better way to authenticate kubernetes provider to use this module #909

Closed
yashbhutwala opened this issue May 25, 2021 · 5 comments
Closed
Labels

Comments

@yashbhutwala
Copy link
Contributor

yashbhutwala commented May 25, 2021

The current recommended way to authenticate kubernetes provider in order to use this module is with "google_client_config" data resource. However, using this data resource means that the token generated by this resource is stored in Terraform state in plain text. I'm looking for recommendations or suggestions for alternative ways to authenticate the kubernetes provider that does not rely on storing sensitive auth information in TF state. Any ideas welcome, thanks!

# google_client_config and kubernetes provider must be explicitly specified like the following.
data "google_client_config" "default" {}

provider "kubernetes" {
  host                   = "https://${module.gke.endpoint}"
  token                  = data.google_client_config.default.access_token
  cluster_ca_certificate = base64decode(module.gke.ca_certificate)
}

Relevant Resources:

@morgante
Copy link
Contributor

The token should be short-lived, so the exposure is somewhat limited.

That being said, you should generally assume that Terraform state is sensitive and needs to be locked down.

@yashbhutwala
Copy link
Contributor Author

yashbhutwala commented May 25, 2021

@morgante you're right, and I knew that, I was hoping for some alternatives to not storing it in the state 😃.

At the very least, I think maybe the documentation can be improved with respect to:

  1. token will be stored in TF state (maybe both in provider and this module docs)
  2. how long will the token be valid for? (I think 1 hour, but I didn't see anything in either GKE or terraform docs) Also, is there way to configure the duration? (i.e.: something similar to https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/service_account_access_token#lifetime)

Thoughts? I can send up PRs if needed.

@morgante
Copy link
Contributor

Yes, 1 hour. A PR to explain this more would be appreciated.

@bharathkkb
Copy link
Member

@yashbhutwala just an idea but IIRC google_client_config just exposes the token generated by the provider. Instead you could use service_account_access_token to generate another access_token that is time boxed and is only used to auth the kubernetes provider. Assuming the original SA that TF is using has tokenCreator permissions on this new SA, the token gets created, valid for a specific lifetime as defined in your config.

data "google_service_account_access_token" "default" {
  target_service_account = "foo-cluster-admin@project.iam.gserviceaccount.com"
  scopes                 = ["cloud-platform"]
  lifetime               = "10s"
}
provider "kubernetes" {
  host                   = "https://${module.gke.endpoint}"
  token                  = data.google_service_account_access_token.default.access_token
  cluster_ca_certificate = base64decode(module.gke.ca_certificate)
}

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants