【问题标题】:Unable to Bind Google Service Account to Kubernetes Service Account无法将 Google 服务帐户绑定到 Kubernetes 服务帐户
【发布时间】:2021-05-02 23:57:56
【问题描述】:

我正在尝试将我的 Google 服务帐户 (GSA) 绑定到我的 Kubernetes 服务帐户 (KSA),以便我可以从 Google Kubernetes Engine (GKE) 连接到我的 Cloud SQL 数据库。我目前正在使用 Google 文档 (https://cloud.google.com/sql/docs/sqlserver/connect-kubernetes-engine) 中提供的以下指南。

目前,我有一个在 GKE 上运行的集群,名为 MY_CLUSTER,一个具有正确 Cloud SQL 权限的 GSA,名为 MY_GCP_SERVICE_ACCOUNT@PROJECT_ID.iam.gserviceaccount.com,还有一个名为 MY_K8S_SERVICE_ACCOUNT 的 KSA。我正在尝试使用以下命令绑定两个帐户。

gcloud iam service-accounts add-iam-policy-binding \
  --member "serviceAccount:PROJECT_ID.svc.id.goog[K8S_NAMESPACE/MY_K8S_SERVICE_ACCOUNT]" \
  --role roles/iam.workloadIdentityUser \
  MY_GCP_SERVICE_ACCOUNT@PROJECT_ID.iam.gserviceaccount.com

但是,当我运行上一个命令时,我收到以下错误消息。

ERROR: Policy modification failed. For a binding with condition, run "gcloud alpha iam policies lint-condition" to identify issues in condition.
ERROR: (gcloud.iam.service-accounts.add-iam-policy-binding) INVALID_ARGUMENT: Identity Pool does not exist (PROJECT_ID.svc.id.goog). Please check that you specified a valid resource name as returned in the `name` attribute in the configuration API.

当我尝试将我的 GSA 绑定到我的 KSA 时,为什么会出现此错误?

【问题讨论】:

    标签: kubernetes google-cloud-platform google-kubernetes-engine google-cloud-sql cloud-sql-proxy


    【解决方案1】:

    为了将您的 Google 服务帐户 (GSA) 绑定到您的 Kubernetes 服务帐户 (KSA),您需要在集群上启用 Workload Identity。这在 Google 的文档 (https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) 中有更详细的解释。

    要在现有集群上启用 Workload Identity,您可以运行。

    gcloud container clusters update MY_CLUSTER \
      --workload-pool=PROJECT_ID.svc.id.goog
    

    【讨论】:

    • 您应该注意现有节点需要回收。工作负载标识仅适用于启用该功能后创建的节点。
    猜你喜欢
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 2013-09-02
    • 2019-11-08
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多