简体   繁体   English

如何在使用Terraform启动GKE集群时引导RBAC权限

[英]How to bootstrap RBAC privileges when bringing up a GKE cluster with Terraform

I'm bring a GKE cluster up with Terraform, which works nicely. 我带了Terraform的GKE集群,效果很好。 I then want Terraform to perform some Kubernetes-level operations on the cluster (using the k8s provider) - nothing massive, just installing a couple of Deployments etc. 然后我想让Terraform在集群上执行一些Kubernetes级别的操作(使用k8s提供程序) - 没什么大不了的,只需要安装几个部署等。

The problem I'm having is permissions. 我遇到的问题是权限。 I'd like a neat, tidy, declarative way to make a cluster and have a set of credentials in hand that I can use short-term to do "admin" operations on it, including bootstrapping other users. 我想要一个整洁,整洁,声明的方式来创建一个集群并拥有一组凭据,我可以使用短期来对其进行“管理”操作,包括引导其他用户。 I know how to make the google user that's running TF an admin of the cluster (that question comes up a lot), but that doesn't seem very nice . 我知道如何让运行TF的谷歌用户成为群集的管理员(这个问题出现了很多),但这似乎并不是很好 Not least, the k8s TF provider doesn't support clusterolebinding ( Issue , partial PR ) so you have to "shell out" with a local-exec provisioner to first run gcloud container clusters get-credentials and then kubectl create clusterrolebinding ... . 尤其是,k8s TF提供程序不支持集群绑定( 问题部分PR ),因此您必须使用local-exec配置程序“shell out”以首先运行gcloud container clusters get-credentials ,然后kubectl create clusterrolebinding ...

Similarly, I don't want to set a master password, because I don't want to run with HTTP basic auth on. 同样,我不想设置主密码,因为我不想在HTTP基本身份验证上运行。 The nicest option looks to be the key/cert pair that's returned by the TF GKE resource, but that has a CN of "client", and that user has no power. 最好的选项看起来是由TF GKE资源返回的密钥/证书对,但它具有“客户端”的CN,并且该用户没有电源。 So again, the only way to use it is to shell out to kubectl, pass it the gcloud service account credentials, and get it to add a clusterrolebinding for "client", at which point I may as well just do everything as the service account like above. 所以再一次,使用它的唯一方法是向kubectl发送shell,将gcloud服务帐户凭据传递给它,然后让它为“client”添加一个clusterrolebinding,此时我也可以将所有内容作为服务帐户执行像上面一样。

For contrast, on EKS the (AWS IAM) user that creates the cluster has cluster-admin out of the box (I assume the AWS authn provider claim's the user is in "system:masters"). 相比之下,在EKS上,创建集群的(AWS IAM)用户具有开箱即用的集群管理员(我假设AWS authn提供者声明用户在“system:masters”中)。

My actual question here is: is there a neat, fully declarative way in Terraform to bring up a cluster and have available (ideally as output) a potent set of credentials to use and then drop? 我在这里的实际问题是:在Terraform中是否有一个完整的,完全声明的方式来调出一个集群并且可以(理想情况下作为输出)使用一组有效的凭据然后丢弃? (yes I know they'll stay in the tfstate) (是的,我知道他们会留在tfstate)

My options seem to be: 我的选择似乎是:

  • "shell out" to give TF's google ID (ideally a service account) cluster-admin (which is privilege escalation, but which works due to the gcloud authz plugin) “shell out”给TF的谷歌ID(理想情况下是服务帐户)cluster-admin(这是特权升级,但由于gcloud authz插件而有效)
  • Enable HTTP basic auth and give the admin account a password, then have an aliased k8s provisioner use that to do minimal bootstrapping of another service account. 启用HTTP基本身份验证并为管理员帐户提供密码,然后使用别名k8s配置程序来执行另一个服务帐户的最小引导。
  • Enable ABAC so that "client" (the CN of the output key/cert) has infinite power - this is what I'm currently running with, don't judge me! 启用ABAC以便“客户端”(输出密钥/证书的CN)具有无限的功率 - 这是我目前正在运行的,不要评判我!

And I don't like any of them! 我不喜欢他们中的任何一个!

I've been running into a similar problem, which has gotten particularly nasty since a recent Kubernetes issue unexpectedly disabled basic auth by default , which broke my previously-functioning Terraform configuration as soon as I tried to build a new cluster from the same config. 我一直遇到一个类似的问题,因为最近Kubernetes问题出乎意料地默认禁用了基本身份验证,因为我试图从同一个配置构建一个新群集时,它突然破坏了我以前运行的Terraform配置。

Finally found an answer in this SO answer , which recommends a method of using Terraform's Google IAM creds to connect to the cluster without needing the "shell out". 最后在这个SO答案中找到了答案, 该答案建议使用Terraform的Google IAM信用卡连接到集群而不需要“shell out”。 Note that this method allows cluster permissions to be bootstrapped in Terraform with no external tooling/hacks/etc and without needing to have basic auth enabled. 请注意,此方法允许在Terraform中引导群集权限,而无需外部工具/黑客/等,无需启用基本身份验证。

The relevant part of that answer is: 该答案的相关部分是:

data "google_client_config" "default" {}

provider "kubernetes" {
  host     = "${google_container_cluster.default.endpoint}"

  token = "${data.google_client_config.default.access_token}"
  cluster_ca_certificate = "${base64decode(google_container_cluster.default.master_auth.0.cluster_ca_certificate)}"

  load_config_file = false
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM