为 GKE 排查托管式工作负载身份的身份验证问题

本文档介绍了一些常见托管式工作负载身份错误的解决方法。

您可以通过运行以下命令来检查 Pod 的状态:

kubectl describe pod

Pod 无法与证书一起部署

如果 Google Kubernetes Engine (GKE) 工作负载 Pod 无法与已装载的证书一起部署,请使用以下命令检查 Pod 状态:

kubectl describe pod POD_NAME -n POD_NAMESPACE

与权限相关的错误

本部分介绍了与权限不正确相关的错误。

颁发证书时权限被拒:无法从 GKE Auth 颁发证书

此错误如下所示:

Permission denied while issuing the certificate: failed to issue the certificate from the GKE Auth: rpc error: code = PermissionDenied desc = Permission 'privateca.certificates.createForSelf' denied on 'projects/PROJECT_NUMBER/locations/REGION/caPools/ CA_POOL_ID'

出现此错误的原因是,工作负载身份池缺少从属 CA 池的 CA Service Workload Certificate Requester 角色 (roles/privateca.workloadCertificateRequester)。

如需解决此错误,请向工作负载身份池授予该角色:

gcloud privateca pools add-iam-policy-binding SUBORDINATE_CA_POOL_ID \
   --project=CA_POOL_PROJECT_ID \
   --location=REGION \
   --role=roles/privateca.workloadCertificateRequester \
   --member="principal://iam.googleapis.com/projects/CA_POOL_PROJECT_NUMBER/name/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog"

替换以下内容:

  • SUBORDINATE_CA_POOL_ID:从属 CA 池 ID
  • CA_POOL_PROJECT_ID:根 CA 池的项目 ID
  • REGION:从属 CA 区域
  • CA_POOL_PROJECT_NUMBER:CA 池的项目编号
  • PROJECT_ID:工作负载身份池的项目 ID

卷的 MountVolume.SetUp 失败

此错误如下所示:

MountVolume.SetUp failed for volume "fleet-spiffe-credentials" : rpc error: code = Internal desc = unable to mount volume: while creating volume: while loading trust bundles: rpc error: code = Internal desc = while getting trust map from the trustBundleWatcher: rpc error: code = Internal desc = no GKEClusterTrustBundle objects found with fleet WIP nickname fleet-project/svc.id.goog

出现此错误的原因是,工作负载身份池缺少从属 CA 池的 Private CA Pool Reader 角色 (roles/privateca.poolReader)。

如需解决此错误,请向工作负载身份池授予该角色,并等待几分钟,以加载信任软件包:

gcloud privateca pools add-iam-policy-binding SUBORDINATE_CA_POOL_ID \
 --location=REGION \
 --role=roles/privateca.poolReader \
 --member="principal://iam.googleapis.com/projects/PROJECT_NUMBER/name/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog"

替换以下内容:

  • SUBORDINATE_CA_POOL_ID:从属 CA 池 ID
  • REGION:从属 CA 区域
  • PROJECT_NUMBER:工作负载身份池的项目编号
  • PROJECT_ID:工作负载身份池的项目 ID

您可以使用以下命令检查信任软件包是否存在:

kubectl get gkeclustertrustbundle

加载信任软件包后,响应如下所示:

NAME                                         AGE
svc.id.goog-PROJECT_ID.svc.id.goog   5m35s

在输出中,PROJECT_ID 是信任根与之关联的舰队的项目 ID。

证书错误

本部分中的错误与证书配置有关。

如果未生成托管式工作负载身份证书,则可能会出现多种错误。如需检查 Pod 装载的卷上是否存在这些证书,请执行以下操作:

  1. 连接到 Pod。

    # Open the pod sh interface
    kubectl exec -it $pod_name -n $pod_namespace -- sh
    
  2. 列出并检查凭证文件。

    # Look up the volume contents:
    ls -la /var/run/secrets/workload-spiffe-credentials
    cat /var/run/secrets/workload-spiffe-credentials/certificates.pem
    cat /var/run/secrets/workload-spiffe-credentials/ca_certificates.pem
    cat /var/run/secrets/workload-spiffe-credentials/private_key.pem
    cat /var/run/secrets/workload-spiffe-credentials/trust_bundles.json
    

您还可以通过Google Cloud 控制台检查 k8s_container 日志是否存在 gke-metadata-server 容器来检查 Pod 的证书预配状态。

颁发证书时未能满足前提条件

Pod 说明可以包含以下消息:

Failed precondition while issuing the certificate: failed to issue the certificate from the GKE Auth: rpc error: code = FailedPrecondition

出现此错误的原因是,工作负载身份池未配置证书颁发配置 (CIC)。

如需解决此错误,请创建 CIC 并使用它来更新工作负载身份池