gke-workload-identity
它能做什么
这个技能找出运行在 GKE Pod 中的应用为何无法登录 Google Cloud API。它适用于在集群内看到权限或凭据错误的开发者。
适用场景
- ✓当 Pod 收到关于 iam.serviceAccounts.getAccessToken 或权限被拒绝的 403 错误的时候。
- ✓当 Pod 报告找不到默认凭据或无法访问元数据服务器的时候。
- ✓当 Pod 中的 API 调用使用了节点的默认服务账户,而不是工作负载自身身份的时候。
技能链接
https://github.com/google/skills/blob/main/skills/cloud/gke-workload-identity/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 GKE Pod 在调用 Cloud Storage 时出现权限被拒绝错误。请找出原因并告诉我修复方法。”
每周 5 个新技能,1 分钟读完。
工作原理
它会检查集群和节点池的 Workload Identity 设置,以及 Kubernetes 服务账户与 Google Cloud 服务账户之间的关联。它会报告差距,并建议由人来应用的修复方法。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
GKE Workload Identity Federation Troubleshooting Skill
Use this skill to systematically diagnose why a Pod using Workload Identity Federation for GKE cannot authenticate to Google Cloud APIs. Typical symptoms:
HTTP/403 ... Permission 'iam.serviceAccounts.getAccessToken' denied on resourcegoogle.auth.exceptions ... could not find default credentials/ComputeEngineCredentials cannot find the metadata server- API calls that unexpectedly use the node's default Compute Engine service account instead of the workload's identity.
Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read Usage Attribution. For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix gcloud with
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-workload-identity)"
and append agent-skills/1.0 (skill:gke-workload-identity) to User-Agent headers.
Read-only boundary
This skill is diagnostic and non-interactive. It only reads cluster, IAM, and logging state and proposes fixes as commands or GitOps manifest changes for a human to apply. It must never create or modify IAM bindings, KSA annotations, node pools, or clusters automatically. When evidence is missing or the fix requires a privileged change, summarize findings and hand off to a human (see Step 7).
Output discipline (apply to every conclusion)
When you report a diagnosis, always:
- Name the single most-likely root cause (not an open-ended list of possibilities).
- Explicitly rule out the other plausible causes, citing the evidence that excludes them. In particular, when the cause is node-pool configuration, state plainly that it is not a KSA annotation or IAM binding problem; when the cause is a missing role on a target resource, state that Workload Identity itself is not misconfigured.
- Give the exact remediation as a proposed change for a human — a concrete
gcloudcommand (or GitOps manifest edit) with the real identifiers filled in — and never apply it automatically.
Diagnostic Workflow
Step 0: Context discovery & time window
Collect (from the user or the failing resource): PROJECT_ID, PROJECT_NUMBER,
CLUSTER, cluster LOCATION, NAMESPACE, the KSA the Pod runs as, the
node and node pool the Pod is scheduled on (used in Step 2), the target
resource / API being called, and the exact error string. Define a time
window around the first observed failure for log queries.
# Resolve the project number (used in the direct-binding principal identifier).
gcloud projects describe "{PROJECT_ID}" --format="value(projectNumber)"
# Confirm which KSA the workload runs as.
kubectl get pod "{pod_name}" -n "{namespace}" \
-o jsonpath='{.spec.serviceAccountName}'
# Identify the node the Pod runs on, then the node pool that node belongs to
# (Step 2 checks the node pool's Workload Identity mode).
NODE=$(kubectl get pod "{pod_name}" -n "{namespace}" -o jsonpath='{.spec.nodeName}')
kubectl get node "$NODE" \
-o jsonpath='{.metadata.labels.cloud\.google\.com/gke-nodepool}'
Step 1: Capture the exact error signature
Read the workload's own logs and the gke-metadata-server logs to classify the
failure.
kubectl logs "{pod_name}" -n "{namespace}" --all-containers --prefix
kubectl describe pod "{pod_name}" -n "{namespace}"
Equivalent via Cloud Logging (preferred for historical events). Open it as a
Logs Explorer deep link — URL-encode the query and append the project and
time window:
https://console.cloud.google.com/logs/query;query={URL_ENCODED_QUERY};timeRange={start}%2F{end}?project={project_id}
(encode / as %2F, or use ;duration=PT1H for a rolling hour):
resource.type="k8s_container"
resource.labels.namespace_name="{namespace}"
resource.labels.pod_name="{pod_name}"
severity>=WARNING
Classify the signature:
iam.serviceAccounts.getAccessTokendenied /HTTP/403→ the workload is using the GSA impersonation path. This is expected for the legacy setup, but if you intend to use direct binding, it means the KSA still carries a leftoveriam.gke.io/gcp-service-account
常见问题
它会更改我的 IAM 绑定吗?
不会。它只读取设置,并提出由人来应用的修复方法。
它处理哪些类型的错误?
令牌访问权限被拒绝、缺少默认凭据,以及无法访问元数据服务器的错误。
它不做什么?
它不创建或更改 IAM 绑定、服务账户注解、节点池或集群。
详情
作者的原始描述
Configures and diagnoses Workload Identity Federation for GKE authentication failures for Pods (403 "iam.serviceAccounts.getAccessToken" / permission denied, "could not find default credentials", or GKE metadata server unreachable) by verifying cluster and node-pool Workload Identity configuration, the Kubernetes ServiceAccount (KSA) to IAM binding (direct principal binding and legacy Google ServiceAccount impersonation), target-resource IAM roles, and gke-metadata-server health. Use when setting up KSA/GSA bindings (`roles/iam.workloadIdentityUser`, `iam.gke.io/gcp-service-account`) or when a
repo: google/skills
热度
- GitHub 星标
- 22k
- 排名
- #10301
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
finding-google-skills
22k帮你的智能体为某项设置任务找到合适的 Google 指南,例如托管、数据库、存储、登录或 AI 模型服务。
gcloud
22k帮你的智能体编写并检查 Google Cloud gcloud 命令,在运行任何内容之前查阅准确的语法,避免猜测参数。
google-cloud-recipe-auth
22k引导你的智能体了解 Google Cloud 的身份与访问管理,包括人员和服务如何登录,以及它们各自获得哪些权限。
google-cloud-recipe-onboarding
22k带领新开发者完成在 Google Cloud 上的第一步,包括选择项目、关联计费,以及部署第一个资源。