[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7215WA1TNFDZE22VJEN3XXW":3,"skill-same:01M7215WA1TNFDZE22VJEN3XXW":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":31,"ownerHtmlUrl":32,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":33,"install":34,"resources":47},"01M7215WA1TNFDZE22VJEN3XXW","gke-workload-identity",null,"Configures and diagnoses Workload Identity Federation for GKE authentication failures for Pods (403 \"iam.serviceAccounts.getAccessToken\" \u002F 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\u002FGSA bindings (`roles\u002Fiam.workloadIdentityUser`, `iam.gke.io\u002Fgcp-service-account`) or when a Pod cannot authenticate to Google Cloud APIs. Don't use for in-cluster Kubernetes RBAC errors (API-server authorization), general workload crashes (use gke-workload-troubleshooting), or Pod Security Standards and NetworkPolicies (use gke-workload-security).","gke-labs\u002Fkube-agents","gke-labs","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F197140281?v=4","01M720MEZR8K6WD2WTHNQE346Q","01M720MF0BRA9RGH1QVT4J0M0E",126,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents\u002Fblob\u002Fmain\u002Fthird_party\u002Fgoogle-skills\u002Fgke-workload-identity\u002FSKILL.md",[],[],"2026-11-10 18:39:20",false,"---\nname: gke-workload-identity\nmetadata:\n  version: \"1.0.1\"\n  category: Security\ndescription: >-\n  Configures and diagnoses Workload Identity Federation for GKE authentication failures for Pods\n  (403 \"iam.serviceAccounts.getAccessToken\" \u002F permission denied, \"could not find\n  default credentials\", or GKE metadata server unreachable) by verifying\n  cluster and node-pool Workload Identity configuration, the Kubernetes\n  ServiceAccount (KSA) to IAM binding (direct principal binding and legacy Google\n  ServiceAccount impersonation), target-resource IAM roles, and gke-metadata-server\n  health. Use when setting up KSA\u002FGSA bindings (`roles\u002Fiam.workloadIdentityUser`,\n  `iam.gke.io\u002Fgcp-service-account`) or when a Pod cannot authenticate to Google Cloud APIs. Don't use for in-cluster\n  Kubernetes RBAC errors (API-server authorization), general workload crashes\n  (use gke-workload-troubleshooting), or Pod Security Standards and NetworkPolicies\n  (use gke-workload-security).\n---\n\n# GKE Workload Identity Federation Troubleshooting Skill\n\nUse this skill to systematically diagnose why a Pod using **Workload Identity\nFederation for GKE** cannot authenticate to Google Cloud APIs. Typical symptoms:\n\n-   `HTTP\u002F403 ... Permission 'iam.serviceAccounts.getAccessToken' denied on\n    resource`\n-   `google.auth.exceptions ... could not find default credentials` \u002F\n    `ComputeEngineCredentials cannot find the metadata server`\n-   API calls that unexpectedly use the node's default Compute Engine service\n    account instead of the workload's identity.\n\n## Read-only boundary\n\nThis skill is **diagnostic and non-interactive**. It only **reads** cluster,\nIAM, and logging state and **proposes** fixes as commands or GitOps manifest\nchanges for a human to apply. It must **never** create or modify IAM bindings,\nKSA annotations, node pools, or clusters automatically. When evidence is missing\nor the fix requires a privileged change, summarize findings and hand off to a\nhuman (see Step 7).\n\n## Output discipline (apply to every conclusion)\n\nWhen you report a diagnosis, always:\n\n1.  **Name the single most-likely root cause** (not an open-ended list of\n    possibilities).\n2.  **Explicitly rule out** the other plausible causes, citing the evidence that\n    excludes them. In particular, when the cause is node-pool configuration,\n    state plainly that it is **not** a KSA annotation or IAM binding problem;\n    when the cause is a missing role on a target resource, state that Workload\n    Identity itself is **not** misconfigured.\n3.  **Give the exact remediation as a proposed change for a human** — a concrete\n    `gcloud` command (or GitOps manifest edit) with the real identifiers filled\n    in — and never apply it automatically.\n\n--------------------------------------------------------------------------------\n\n## Diagnostic Workflow\n\n### Step 0: Context discovery & time window\n\nCollect (from the user or the failing resource): `PROJECT_ID`, `PROJECT_NUMBER`,\n`CLUSTER`, cluster `LOCATION`, `NAMESPACE`, the **KSA** the Pod runs as, the\n**node and node pool** the Pod is scheduled on (used in Step 2), the **target\nresource \u002F API** being called, and the **exact error string**. Define a time\nwindow around the first observed failure for log queries.\n\n```bash\n# Resolve the project number (used in the direct-binding principal identifier).\ngcloud projects describe \"{PROJECT_ID}\" --format=\"value(projectNumber)\"\n\n# Confirm which KSA the workload runs as.\nkubectl get pod \"{pod_name}\" -n \"{namespace}\" \\\n  -o jsonpath='{.spec.serviceAccountName}'\n\n# Identify the node the Pod runs on, then the node pool that node belongs to\n# (Step 2 checks the node pool's Workload Identity mode).\nNODE=$(kubectl get pod \"{pod_name}\" -n \"{namespace}\" -o jsonpath='{.spec.nodeName}')\nkubectl get node \"$NODE\" \\\n  -o jsonpath='{.metadata.labels.cloud\\.google\\.com\u002Fgke-nodepool}'\n```\n\n--------------------------------------------------------------------------------\n\n### Step 1: Capture the exact error signature\n\nRead the workload's own logs and the `gke-metadata-server` logs to classify the\nfailure.\n\n```bash\nkubectl logs \"{pod_name}\" -n \"{namespace}\" --all-containers --prefix\nkubectl describe pod \"{pod_name}\" -n \"{namespace}\"\n```\n\nEquivalent via Cloud Logging (preferred for historical events). Open it as a\n**Logs Explorer deep link** — URL-encode the query and append the project and\ntime window:\n`https:\u002F\u002Fconsole.cloud.google.com\u002Flogs\u002Fquery;query={URL_ENCODED_QUERY};timeRange={start}%2F{end}?project={project_id}`\n(encode `\u002F` as `%2F`, or use `;duration=PT1H` for a rolling hour):\n\n```\nresource.type=\"k8s_container\"\nresource.labels.namespace_name=\"{namespace}\"\nresource.labels.pod_name=\"{pod_name}\"\nseverity>=WARNING\n```\n\n**Classify the signature:**\n\n-   `iam.serviceAccounts.getAccessToken` denied \u002F `HTTP\u002F403` → the workload is\n    using the **GSA impersonation** path. This is expected for the legacy setup,\n    but if you intend to use **direct binding**, it means the KSA still carries\n    a leftover `iam.gke.io\u002Fgcp-service-account` annotation (or the client SDK is\n    configured to impersonate) and is unintentionally impersonating a GSA; go to\n    Step 3.\n-   `403 PERMISSION_DENIED` on the **target API\u002Fresource** (no `getAccessToken`\n    in the error) → the resolved identity lacks the required IAM role on that\n    resource; go to Step 4.\n-   `could not find default credentials` \u002F `cannot find the metadata server` →\n    metadata-server connectivity or a startup race; go to Step 5.\n-   Calls succeed but as the **node default service account** → Workload\n    Identity is not in effect for this node pool; go to Step 2.\n\n--------------------------------------------------------------------------------\n\n### Step 2: Verify Workload Identity is enabled (cluster + node pool)\n\nBoth the cluster and the **node pool the Pod runs on** must have Workload\nIdentity enabled. A node pool with `GCE_METADATA` (instead of `GKE_METADATA`)\ncauses Pods to fall back to the node's default Compute Engine service account.\n\n```bash\n# Cluster must have a workload identity pool (PROJECT_ID.svc.id.goog).\ngcloud container clusters describe \"{cluster}\" --location \"{location}\" \\\n  --format=\"value(workloadIdentityConfig.workloadPool)\"\n\n# Node pool must have workloadMetadataConfig.mode = GKE_METADATA.\ngcloud container node-pools describe \"{node_pool}\" --cluster \"{cluster}\" \\\n  --location \"{location}\" \\\n  --format=\"value(config.workloadMetadataConfig.mode)\"\n```\n\n-   Empty workload pool → Workload Identity is **not enabled on the cluster**.\n-   Node-pool mode is `GCE_METADATA` (or empty) → the node pool is **not** using\n    the GKE metadata server; this is the usual cause of \"runs as the node\n    default service account\". Remediation: enable\n    `--workload-metadata=GKE_METADATA` on the node pool (propose to a human;\n    recreates nodes). This is a **node-pool configuration** problem — not a KSA\n    annotation or IAM binding problem — so do not change KSA annotations or IAM\n    bindings to fix it. When the symptom is \"runs as the node default service\n    account\", say so explicitly: the root cause is the node pool's\n    `workloadMetadataConfig.mode`, and the KSA annotation and IAM bindings are\n    **ruled out** as the cause. Propose the exact fix, e.g.:\n\n```bash\ngcloud container node-pools update \"{node_pool}\" --cluster \"{cluster}\" \\\n  --location \"{location}\" --workload-metadata=GKE_METADATA\n```\n\n--------------------------------------------------------------------------------\n\n### Step 3: Verify the KSA → identity binding\n\nThere are two supported models. **Prefer direct binding** (current default);\ntreat GSA impersonation as the **legacy** path.\n\n> **How the two models fail differently:** with **direct binding** the KSA\n> principal accesses resources directly, so failures show up as a plain `403\n> PERMISSION_DENIED` on the target API (fix in Step 4). A `403\n> iam.serviceAccounts.getAccessToken` instead means an **impersonation** attempt\n> — intended under the legacy path, or *unintended* if a leftover\n> `iam.gke.io\u002Fgcp-service-account` annotation remains on a KSA that was meant to\n> use direct binding.\n\n**(a) Direct KSA binding (no GSA impersonation).** The KSA principal is granted\nroles directly. Construct the principal identifier and search for its bindings:\n\n```\nprincipal:\u002F\u002Fiam.googleapis.com\u002Fprojects\u002F{PROJECT_NUMBER}\u002Flocations\u002Fglobal\u002FworkloadIdentityPools\u002F{PROJECT_ID}.svc.id.goog\u002Fsubject\u002Fns\u002F{NAMESPACE}\u002Fsa\u002F{KSA_NAME}\n```\n\n**(b) Legacy: KSA + GSA impersonation.** The KSA must be annotated to point at a\nGSA, and the KSA must hold `roles\u002Fiam.workloadIdentityUser` on that GSA.\n\n```bash\n# The KSA annotation must reference the intended GSA.\nkubectl get serviceaccount \"{ksa_name}\" -n \"{namespace}\" \\\n  -o jsonpath='{.metadata.annotations.iam\\.gke\\.io\u002Fgcp-service-account}'\n\n# The GSA's IAM policy must bind the KSA member to workloadIdentityUser.\ngcloud iam service-accounts get-iam-policy \\\n  \"{gsa_name}@{project_id}.iam.gserviceaccount.com\" \\\n  --format=json\n# Expect a binding: role roles\u002Fiam.workloadIdentityUser,\n# member serviceAccount:{PROJECT_ID}.svc.id.goog[{NAMESPACE}\u002F{KSA_NAME}]\n```\n\n> If the annotation is present but the binding is missing, the binding was\n> likely removed — check the `setIamPolicy` audit logs around the failure time\n> to find the responsible principal.\n\n--------------------------------------------------------------------------------\n\n### Step 4: Verify IAM permissions on the target resource\n\nEven with a correct binding, the identity (the KSA principal for direct binding,\nor the GSA for legacy) must hold the role required by the API call (for example\n`roles\u002Fstorage.objectViewer`). The standard IAM Policy Troubleshooter has\nlimited support for Workload Identity principals; use Cloud Asset Inventory to\nsearch all IAM policies for the principal instead.\n\n```bash\n# Direct binding: search for the KSA principal's bindings across the project.\ngcloud asset search-all-iam-policies \\\n  --scope=\"projects\u002F{PROJECT_ID}\" \\\n  --query='policy:\"{PROJECT_ID}.svc.id.goog\"'\n\n# Legacy: search for the GSA's bindings on the target resource's project.\ngcloud asset search-all-iam-policies \\\n  --scope=\"projects\u002F{TARGET_PROJECT_ID}\" \\\n  --query='policy:\"{gsa_name}@{project_id}.iam.gserviceaccount.com\"'\n```\n\nIf no binding grants the required role on the target resource, **that missing\nrole is the root cause** (and Workload Identity itself is **not**\nmisconfigured). Present the fix as a **proposed change for a human to apply** —\nthe exact `add-iam-policy-binding` with the real principal and role — never\napplying it automatically. For example, for direct binding on a project-level\nresource:\n\n```bash\ngcloud projects add-iam-policy-binding \"{TARGET_PROJECT_ID}\" \\\n  --member=\"principal:\u002F\u002Fiam.googleapis.com\u002Fprojects\u002F{PROJECT_NUMBER}\u002Flocations\u002Fglobal\u002FworkloadIdentityPools\u002F{PROJECT_ID}.svc.id.goog\u002Fsubject\u002Fns\u002F{NAMESPACE}\u002Fsa\u002F{KSA_NAME}\" \\\n  --role=\"{REQUIRED_ROLE}\"   # e.g. roles\u002Fstorage.objectViewer\n```\n\n--------------------------------------------------------------------------------\n\n### Step 5: GKE metadata server & connectivity\n\nApplies when the signature is `could not find the metadata server`, `cannot find\nthe metadata server`, or a connection\u002Ftimeout error. The `gke-metadata-server`\nDaemonSet (in `kube-system`) brokers the token exchange on each node; requests\nto `169.254.169.254` are redirected to it, so a Pod fails closed if it cannot\nreach a healthy metadata-server Pod on its node.\n\n**(a) Check gke-metadata-server Pod health on the workload's node.**\n\n```bash\n# The DaemonSet Pods must be healthy on the workload's node.\nkubectl get pods -n kube-system -l k8s-app=gke-metadata-server -o wide\n\n# A gke-metadata-server Pod can be OOM-evicted when the cluster has many\n# (>3,000) Kubernetes service accounts. Look for CrashLoopBackOff, then confirm\n# the eviction was OOMKilled.\nkubectl get pods -n kube-system | grep CrashLoopBackOff\nkubectl describe pod {gke_metadata_server_pod} --namespace=kube-system | grep OOMKilled\n```\n\n**(b) Inspect the `gke-metadata-server` logs** (historical, via Cloud Logging;\nopen as a Logs Explorer deep link, see Step 1):\n\n```\nresource.type=\"k8s_container\"\nresource.labels.namespace_name=\"kube-system\"\nlabels.\"k8s-pod\u002Fk8s-app\"=\"gke-metadata-server\"\nseverity>=WARNING\n```\n\n**(c) Connectivity test** from the affected Pod — it must reach the metadata\nserver and (for some client libraries) resolve its DNS name:\n\n```bash\n# Token endpoint via the hardcoded metadata IP (a healthy path returns a token).\nkubectl exec {pod_name} -n {namespace} -- \\\n  curl -sS -H 'Metadata-Flavor: Google' \\\n  'http:\u002F\u002F169.254.169.254\u002FcomputeMetadata\u002Fv1\u002Finstance\u002Fservice-accounts\u002Fdefault\u002Ftoken'\n```\n\nPossible causes:\n\n-   **Startup race**: the metadata server needs a few seconds after a Pod\n    starts. Applications that authenticate immediately may fail; the fix is\n    application-side retries or an `initContainer` that waits for the metadata\n    server, not a cluster change.\n-   **DNS**: some client libraries resolve `metadata.google.internal`; broken\n    in-cluster DNS surfaces as `cannot find the metadata server`. As a\n    workaround, set `GCE_METADATA_HOST=169.254.169.254` to skip DNS resolution.\n-   **Network policy \u002F egress**: a cluster network policy must allow egress to\n    `169.254.169.254\u002F32` on port `80` (GKE Dataplane V2), or\n    `169.254.169.252\u002F32` on port `988`. A default-deny egress rule that blocks\n    HTTPS to the public Security Token Service (`sts.googleapis.com:443`)\n    produces `504 Gateway Timeout` or `context deadline exceeded`.\n-   **`gke-metadata-server` crashing \u002F high restarts**: see (a) — reduce the\n    number of Kubernetes service accounts (\u003C3,000) to restore functionality.\n\n--------------------------------------------------------------------------------\n\n### Step 6: \"Invalid form of account ID\" edge case (legacy GSA impersonation)\n\n> **Applies only to the legacy GSA impersonation setup** (a KSA annotated with\n> `iam.gke.io\u002Fgcp-service-account`), not to direct principal binding.\n\nSignature: an operation that requires an IAM **service account email** (for\nexample, manually creating a Cloud Storage signed URL) fails with:\n\n```\nERROR: Invalid form of account ID SERVICEACCOUNT_NAME.svc.id.goog.\nShould be [Gaia ID | Email | Unique ID | ] of the account\n```\n\nCause: for a KSA linked to a GSA via annotation, the GKE metadata server by\ndefault returns `SERVICEACCOUNT_NAME.svc.id.goog` as the identifier, which is\nnot a valid IAM service account email. This is **not** a missing IAM binding and\ndoes **not** require reverting the setup.\n\nFix (propose to a human): add the\n`iam.gke.io\u002Freturn-principal-id-as-email=\"true\"` annotation to the Pod's KSA so\nthe metadata server returns the identity in the expected form:\n\n```bash\nkubectl annotate serviceaccount \"{ksa_name}\" --namespace \"{namespace}\" \\\n  iam.gke.io\u002Freturn-principal-id-as-email=\"true\"\n```\n\n--------------------------------------------------------------------------------\n\n### Step 7: Remediation boundary & escalation\n\n-   Present the **root cause + evidence** (the exact error, the missing binding\n    \u002F annotation \u002F node-pool mode, or the metadata-server state). Include a\n    **Cloud Logging deep link** (see Step 1) to the supporting entries.\n-   Propose the fix as a **command or GitOps manifest change** for a human to\n    apply — never modify IAM, KSAs, or node pools automatically.\n\n**Escalate** (instead of proposing more self-service diagnostics) when either:\n\n-   the relevant logs are **unavailable** (excluded by a filter, or past the log\n    bucket's retention); or\n-   the identity\u002Fbinding is correct, the target-resource IAM is correct, and the\n    metadata server is healthy, yet the failure persists (undetermined root\n    cause).\n\nIn those cases: state the limitation plainly, summarize the findings gathered\n(cluster\u002Fnode-pool config, bindings, annotations, metadata-server state, and any\n`setIamPolicy` audit logs), and route to GKE support \u002F engineering escalation.\nDo **not** fabricate a diagnosis when evidence is missing.\n\n--------------------------------------------------------------------------------\n\n## References\n\nThis skill is derived from public Google Cloud documentation:\n\n-   [Troubleshoot GKE authentication issues](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Ftroubleshooting\u002Fauthentication.md.txt)\n    — the Workload Identity Federation section: WI-enabled check, KSA\n    annotation, `roles\u002Fiam.workloadIdentityUser`,\n    `iam.serviceAccounts.getAccessToken` 403,\n    `iam.gke.io\u002Freturn-principal-id-as-email`, metadata-server DNS and the\n    [`gke-metadata-server` Pod is crashing](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Ftroubleshooting\u002Fauthentication.md.txt#metadata-server-crashes)\n    guidance.\n-   [About Workload Identity Federation for GKE](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Fconcepts\u002Fworkload-identity.md.txt)\n    — identities, the GKE metadata server, and why Pods don't inherit the node\n    identity.\n-   [Configure applications to use Workload Identity Federation for GKE](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Fhow-to\u002Fworkload-identity.md.txt)\n    — node-pool `--workload-metadata=GKE_METADATA`, the direct-binding\n    `principal:\u002F\u002F...` identifier, and the legacy\n    `serviceAccount:PROJECT_ID.svc.id.goog[NAMESPACE\u002FKSA_NAME]` member format.\n-   [Search IAM policies (Cloud Asset Inventory)](https:\u002F\u002Fcloud.google.com\u002Fasset-inventory\u002Fdocs\u002Fsearching-iam-policies)\n    — `gcloud asset search-all-iam-policies` for auditing a principal's\n    bindings.\n-   [View GKE logs](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Fhow-to\u002Fview-logs.md.txt)\n    — Cloud Logging queries for workload and system logs.\n","# GKE Workload Identity Federation Troubleshooting Skill\n\nUse this skill to systematically diagnose why a Pod using **Workload Identity\nFederation for GKE** cannot authenticate to Google Cloud APIs. Typical symptoms:\n\n-   `HTTP\u002F403 ... Permission 'iam.serviceAccounts.getAccessToken' denied on\n    resource`\n-   `google.auth.exceptions ... could not find default credentials` \u002F\n    `ComputeEngineCredentials cannot find the metadata server`\n-   API calls that unexpectedly use the node's default Compute Engine service\n    account instead of the workload's identity.\n\n## Read-only boundary\n\nThis skill is **diagnostic and non-interactive**. It only **reads** cluster,\nIAM, and logging state and **proposes** fixes as commands or GitOps manifest\nchanges for a human to apply. It must **never** create or modify IAM bindings,\nKSA annotations, node pools, or clusters automatically. When evidence is missing\nor the fix requires a privileged change, summarize findings and hand off to a\nhuman (see Step 7).\n\n## Output discipline (apply to every conclusion)\n\nWhen you report a diagnosis, always:\n\n1.  **Name the single most-likely root cause** (not an open-ended list of\n    possibilities).\n2.  **Explicitly rule out** the other plausible causes, citing the evidence that\n    excludes them. In particular, when the cause is node-pool configuration,\n    state plainly that it is **not** a KSA annotation or IAM binding problem;\n    when the cause is a missing role on a target resource, state that Workload\n    Identity itself is **not** misconfigured.\n3.  **Give the exact remediation as a proposed change for a human** — a concrete\n    `gcloud` command (or GitOps manifest edit) with the real identifiers filled\n    in — and never apply it automatically.\n\n--------------------------------------------------------------------------------\n\n## Diagnostic Workflow\n\n### Step 0: Context discovery & time window\n\nCollect (from the user or the failing resource): `PROJECT_ID`, `PROJECT_NUMBER`,\n`CLUSTER`, cluster `LOCATION`, `NAMESPACE`, the **KSA** the Pod runs as, the\n**node and node pool** the Pod is scheduled on (used in Step 2), the **target\nresource \u002F API** being called, and the **exact error string**. Define a time\nwindow around the first observed failure for log queries.\n\n```bash\n# Resolve the project number (used in the direct-binding principal identifier).\ngcloud projects describe \"{PROJECT_ID}\" --format=\"value(projectNumber)\"\n\n# Confirm which KSA the workload runs as.\nkubectl get pod \"{pod_name}\" -n \"{namespace}\" \\\n  -o jsonpath='{.spec.serviceAccountName}'\n\n# Identify the node the Pod runs on, then the node pool that node belongs to\n# (Step 2 checks the node pool's Workload Identity mode).\nNODE=$(kubectl get pod \"{pod_name}\" -n \"{namespace}\" -o jsonpath='{.spec.nodeName}')\nkubectl get node \"$NODE\" \\\n  -o jsonpath='{.metadata.labels.cloud\\.google\\.com\u002Fgke-nodepool}'\n```\n\n--------------------------------------------------------------------------------\n\n### Step 1: Capture the exact error signature\n\nRead the workload's own logs and the `gke-metadata-server` logs to classify the\nfailure.\n\n```bash\nkubectl logs \"{pod_name}\" -n \"{namespace}\" --all-containers --prefix\nkubectl describe pod \"{pod_name}\" -n \"{namespace}\"\n```\n\nEquivalent via Cloud Logging (preferred for historical events). Open it as a\n**Logs Explorer deep link** — URL-encode the query and append the project and\ntime window:\n`https:\u002F\u002Fconsole.cloud.google.com\u002Flogs\u002Fquery;query={URL_ENCODED_QUERY};timeRange={start}%2F{end}?project={project_id}`\n(encode `\u002F` as `%2F`, or use `;duration=PT1H` for a rolling hour):\n\n```\nresource.type=\"k8s_container\"\nresource.labels.namespace_name=\"{namespace}\"\nresource.labels.pod_name=\"{pod_name}\"\nseverity>=WARNING\n```\n\n**Classify the signature:**\n\n-   `iam.serviceAccounts.getAccessToken` denied \u002F `HTTP\u002F403` → the workload is\n    using the **GSA impersonation** path. This is expected for the legacy setup,\n    but if you intend to use **direct binding**, it means the KSA still carries\n    a leftover `iam.gke.io\u002Fgcp-service-account` annotation (or the client SDK is\n    configured to impersonate) and is unintentionally impersonating a GSA; go to\n    Step 3.\n-   `403 PERMISSION_DENIED` on the **target API\u002Fresource** (no `getAccessToken`\n    in the error) → the resolved identity lacks the required IAM role on that\n    resource; go to Step 4.\n-   `could not find default credentials` \u002F `cannot find the metadata server` →\n    metadata-server connectivity or a startup race; go to Step 5.\n-   Calls succeed but as the **node default service account** → Workload\n    Identity is not in effect for this node pool; go to Step 2.\n\n--------------------------------------------------------------------------------\n\n### Step 2: Verify Workload Identity is enabled (cluster + node pool)\n\nBoth the cluster and the **node pool the Pod runs on** must have Workload\nIdentity enabled. A node pool with `GCE_METADATA` (instead of `GKE_METADATA`)\ncauses Pods to fall back to the node's default Compute Engine service account.\n\n```bash\n# Cluster must have a workload identity pool (PROJECT_ID.svc.id.goog).\ngcloud container clusters describe \"{cluster}\" --location \"{location}\" \\\n  --format=\"value(workloadIdentityConfig.workloadPool)\"\n\n# Node pool must have workloadMetadataConfig.mode = GKE_METADATA.\ngcloud container node-pools describe \"{node_pool}\" --cluster \"{cluster}\" \\\n  --location \"{location}\" \\\n  --format=\"value(config.workloadMetadataConfig.mode)\"\n```\n\n-   Empty workload pool → Workload Identity is **not enabled on the cluster**.\n-   Node-pool mode is `GCE_METADATA` (or empty) → the node pool is **not** using\n    the GKE metadata server; this is the usual cause of \"runs as the node\n    default service account\". Remediation: enable\n    `--workload-metadata=GKE_METADATA` on the node pool (propose to a human;\n    recreates nodes). This is a **node-pool configuration** problem — not a KSA\n    annotation or IAM binding problem — so do not change KSA annotations or IAM\n    bindings to fix it. When the symptom is \"runs as the node default service\n    account\", say so explicitly: the root cause is the node pool's\n    `workloadMetadataConfig.mode`, and the KSA annotation and IAM bindings are\n    **ruled out** as the cause. Propose the exact fix, e.g.:\n\n```bash\ngcloud container node-pools update \"{node_pool}\" --cluster \"{cluster}\" \\\n  --location \"{location}\" --workload-metadata=GKE_METADATA\n```\n\n--------------------------------------------------------------------------------\n\n### Step 3: Verify the KSA → identity binding\n\nThere are two supported models. **Prefer direct binding** (current default);\ntreat GSA impersonation as the **legacy** path.\n\n> **How the two models fail differently:** with **direct binding** the KSA\n> principal accesses resources directly, so failures show up as a plain `403\n> PERMISSION_DENIED` on the target API (fix in Step 4). A `403\n> iam.serviceAccounts.getAccessToken` instead means an **impersonation** attempt\n> — intended under the legacy path, or *unintended* if a leftover\n> `iam.gke.io\u002Fgcp-service-account` annotation remains on a KSA that was meant to\n> use direct binding.\n\n**(a) Direct KSA binding (no GSA impersonation).** The KSA principal is granted\nroles directly. Construct the principal identifier and search for its bindings:\n\n```\nprincipal:\u002F\u002Fiam.googleapis.com\u002Fprojects\u002F{PROJECT_NUMBER}\u002Flocations\u002Fglobal\u002FworkloadIdentityPools\u002F{PROJECT_ID}.svc.id.goog\u002Fsubject\u002Fns\u002F{NAMESPACE}\u002Fsa\u002F{KSA_NAME}\n```\n\n**(b) Legacy: KSA + GSA impersonation.** The KSA must be annotated to point at a\nGSA, and the KSA must hold `roles\u002Fiam.workloadIdentityUser` on that GSA.\n\n```bash\n# The KSA annotation must reference the intended GSA.\nkubectl get serviceaccount \"{ksa_name}\" -n \"{namespace}\" \\\n  -o jsonpath='{.metadata.annotations.iam\\.gke\\.io\u002Fgcp-service-account}'\n\n# The GSA's IAM policy must bind the KSA member to workloadIdentityUser.\ngcloud iam service-accounts get-iam-policy \\\n  \"{gsa_name}@{project_id}.iam.gserviceaccount.com\" \\\n  --format=json\n# Expect a binding: role roles\u002Fiam.workloadIdentityUser,\n# member serviceAccount:{PROJECT_ID}.svc.id.goog[{NAMESPACE}\u002F{KSA_NAME}]\n```\n\n> If the annotation is present but the binding is missing, the binding was\n> likely removed — check the `setIamPolicy` audit logs around the failure time\n> to find the responsible principal.\n\n--------------------------------------------------------------------------------\n\n### Step 4: Verify IAM permissions on the target resource\n\nEven with a correct binding, the identity (the KSA principal for direct binding,\nor the GSA for legacy) must hold the role required by the API call (for example\n`roles\u002Fstorage.objectViewer`). The standard IAM Policy Troubleshooter has\nlimited support for Workload Identity principals; use Cloud Asset Inventory to\nsearch all IAM policies for the principal instead.\n\n```bash\n# Direct binding: search for the KSA principal's bindings across the project.\ngcloud asset search-all-iam-policies \\\n  --scope=\"projects\u002F{PROJECT_ID}\" \\\n  --query='policy:\"{PROJECT_ID}.svc.id.goog\"'\n\n# Legacy: search for the GSA's bindings on the target resource's project.\ngcloud asset search-all-iam-policies \\\n  --scope=\"projects\u002F{TARGET_PROJECT_ID}\" \\\n  --query='policy:\"{gsa_name}@{project_id}.iam.gserviceaccount.com\"'\n```\n\nIf no binding grants the required role on the target resource, **that missing\nrole is the root cause** (and Workload Identity itself is **not**\nmisconfigured). Present the fix as a **proposed change for a human to apply** —\nthe exact `add-iam-policy-binding` with the real principal and role — never\napplying it automatically. For example, for direct binding on a project-level\nresource:\n\n```bash\ngcloud projects add-iam-policy-binding \"{TARGET_PROJECT_ID}\" \\\n  --member=\"principal:\u002F\u002Fiam.googleapis.com\u002Fprojects\u002F{PROJECT_NUMBER}\u002Flocations\u002Fglobal\u002FworkloadIdentityPools\u002F{PROJECT_ID}.svc.id.goog\u002Fsubject\u002Fns\u002F{NAMESPACE}\u002Fsa\u002F{KSA_NAME}\" \\\n  --role=\"{REQUIRED_ROLE}\"   # e.g. roles\u002Fstorage.objectViewer\n```\n\n--------------------------------------------------------------------------------\n\n### Step 5: GKE metadata server & connectivity\n\nApplies when the signature is `could not find the metadata server`, `cannot find\nthe metadata server`, or a connection\u002Ftimeout error. The `gke-metadata-server`\nDaemonSet (in `kube-system`) brokers the token exchange on each node; requests\nto `169.254.169.254` are redirected to it, so a Pod fails closed if it cannot\nreach a healthy metadata-server Pod on its node.\n\n**(a) Check gke-metadata-server Pod health on the workload's node.**\n\n```bash\n# The DaemonSet Pods must be healthy on the workload's node.\nkubectl get pods -n kube-system -l k8s-app=gke-metadata-server -o wide\n\n# A gke-metadata-server Pod can be OOM-evicted when the cluster has many\n# (>3,000) Kubernetes service accounts. Look for CrashLoopBackOff, then confirm\n# the eviction was OOMKilled.\nkubectl get pods -n kube-system | grep CrashLoopBackOff\nkubectl describe pod {gke_metadata_server_pod} --namespace=kube-system | grep OOMKilled\n```\n\n**(b) Inspect the `gke-metadata-server` logs** (historical, via Cloud Logging;\nopen as a Logs Explorer deep link, see Step 1):\n\n```\nresource.type=\"k8s_container\"\nresource.labels.namespace_name=\"kube-system\"\nlabels.\"k8s-pod\u002Fk8s-app\"=\"gke-metadata-server\"\nseverity>=WARNING\n```\n\n**(c) Connectivity test** from the affected Pod — it must reach the metadata\nserver and (for some client libraries) resolve its DNS name:\n\n```bash\n# Token endpoint via the hardcoded metadata IP (a healthy path returns a token).\nkubectl exec {pod_name} -n {namespace} -- \\\n  curl -sS -H 'Metadata-Flavor: Google' \\\n  'http:\u002F\u002F169.254.169.254\u002FcomputeMetadata\u002Fv1\u002Finstance\u002Fservice-accounts\u002Fdefault\u002Ftoken'\n```\n\nPossible causes:\n\n-   **Startup race**: the metadata server needs a few seconds after a Pod\n    starts. Applications that authenticate immediately may fail; the fix is\n    application-side retries or an `initContainer` that waits for the metadata\n    server, not a cluster change.\n-   **DNS**: some client libraries resolve `metadata.google.internal`; broken\n    in-cluster DNS surfaces as `cannot find the metadata server`. As a\n    workaround, set `GCE_METADATA_HOST=169.254.169.254` to skip DNS resolution.\n-   **Network policy \u002F egress**: a cluster network policy must allow egress to\n    `169.254.169.254\u002F32` on port `80` (GKE Dataplane V2), or\n    `169.254.169.252\u002F32` on port `988`. A default-deny egress rule that blocks\n    HTTPS to the public Security Token Service (`sts.googleapis.com:443`)\n    produces `504 Gateway Timeout` or `context deadline exceeded`.\n-   **`gke-metadata-server` crashing \u002F high restarts**: see (a) — reduce the\n    number of Kubernetes service accounts (\u003C3,000) to restore functionality.\n\n--------------------------------------------------------------------------------\n\n### Step 6: \"Invalid form of account ID\" edge case (legacy GSA impersonation)\n\n> **Applies only to the legacy GSA impersonation setup** (a KSA annotated with\n> `iam.gke.io\u002Fgcp-service-account`), not to direct principal binding.\n\nSignature: an operation that requires an IAM **service account email** (for\nexample, manually creating a Cloud Storage signed URL) fails with:\n\n```\nERROR: Invalid form of account ID SERVICEACCOUNT_NAME.svc.id.goog.\nShould be [Gaia ID | Email | Unique ID | ] of the account\n```\n\nCause: for a KSA linked to a GSA via annotation, the GKE metadata server by\ndefault returns `SERVICEACCOUNT_NAME.svc.id.goog` as the identifier, which is\nnot a valid IAM service account email. This is **not** a missing IAM binding and\ndoes **not** require reverting the setup.\n\nFix (propose to a human): add the\n`iam.gke.io\u002Freturn-principal-id-as-email=\"true\"` annotation to the Pod's KSA so\nthe metadata server returns the identity in the expected form:\n\n```bash\nkubectl annotate serviceaccount \"{ksa_name}\" --namespace \"{namespace}\" \\\n  iam.gke.io\u002Freturn-principal-id-as-email=\"true\"\n```\n\n--------------------------------------------------------------------------------\n\n### Step 7: Remediation boundary & escalation\n\n-   Present the **root cause + evidence** (the exact error, the missing binding\n    \u002F annotation \u002F node-pool mode, or the metadata-server state). Include a\n    **Cloud Logging deep link** (see Step 1) to the supporting entries.\n-   Propose the fix as a **command or GitOps manifest change** for a human to\n    apply — never modify IAM, KSAs, or node pools automatically.\n\n**Escalate** (instead of proposing more self-service diagnostics) when either:\n\n-   the relevant logs are **unavailable** (excluded by a filter, or past the log\n    bucket's retention); or\n-   the identity\u002Fbinding is correct, the target-resource IAM is correct, and the\n    metadata server is healthy, yet the failure persists (undetermined root\n    cause).\n\nIn those cases: state the limitation plainly, summarize the findings gathered\n(cluster\u002Fnode-pool config, bindings, annotations, metadata-server state, and any\n`setIamPolicy` audit logs), and route to GKE support \u002F engineering escalation.\nDo **not** fabricate a diagnosis when evidence is missing.\n\n--------------------------------------------------------------------------------\n\n## References\n\nThis skill is derived from public Google Cloud documentation:\n\n-   [Troubleshoot GKE authentication issues](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Ftroubleshooting\u002Fauthentication.md.txt)\n    — the Workload Identity Federation section: WI-enabled check, KSA\n    annotation, `roles\u002Fiam.workloadIdentityUser`,\n    `iam.serviceAccounts.getAccessToken` 403,\n    `iam.gke.io\u002Freturn-principal-id-as-email`, metadata-server DNS and the\n    [`gke-metadata-server` Pod is crashing](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Ftroubleshooting\u002Fauthentication.md.txt#metadata-server-crashes)\n    guidance.\n-   [About Workload Identity Federation for GKE](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Fconcepts\u002Fworkload-identity.md.txt)\n    — identities, the GKE metadata server, and why Pods don't inherit the node\n    identity.\n-   [Configure applications to use Workload Identity Federation for GKE](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Fhow-to\u002Fworkload-identity.md.txt)\n    — node-pool `--workload-metadata=GKE_METADATA`, the direct-binding\n    `principal:\u002F\u002F...` identifier, and the legacy\n    `serviceAccount:PROJECT_ID.svc.id.goog[NAMESPACE\u002FKSA_NAME]` member format.\n-   [Search IAM policies (Cloud Asset Inventory)](https:\u002F\u002Fcloud.google.com\u002Fasset-inventory\u002Fdocs\u002Fsearching-iam-policies)\n    — `gcloud asset search-all-iam-policies` for auditing a principal's\n    bindings.\n-   [View GKE logs](https:\u002F\u002Fdocs.cloud.google.com\u002Fkubernetes-engine\u002Fdocs\u002Fhow-to\u002Fview-logs.md.txt)\n    — Cloud Logging queries for workload and system logs.\n",{"name":5,"metadata":23,"description":7},{"version":24,"category":25},"1.0.1","Security","main","af354bf2b99e17df77e52c512a7ba968c37c2306","third_party\u002Fgoogle-skills\u002Fgke-workload-identity",44,"https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents","https:\u002F\u002Fgke-labs.github.io\u002Fkube-agents\u002F","https:\u002F\u002Fgithub.com\u002Fgke-labs","2026-11-14 20:53:19",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add gke-labs\u002Fkube-agents --skill gke-workload-identity",{"tool":40,"command":41},"bunx","bunx skills add gke-labs\u002Fkube-agents --skill gke-workload-identity",{"tool":43,"command":44},"pnpm","pnpm dlx skills add gke-labs\u002Fkube-agents --skill gke-workload-identity","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents\u002Fblob\u002Fmain\u002Fthird_party\u002Fgoogle-skills\u002Fgke-workload-identity\u002FSKILL.md",true,[],[49,56,63,70,77,84],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":18},"01M72168JZM6CYRZFWW204PA2V","gke-workload-troubleshooting","Diagnoses GKE workload failures (CrashLoopBackOff, OOMKilled, ImagePullBackOff, Pending, etc.) via logs and events. Use when pods fail to start or crash repeatedly. Don't use for GKE cluster infrastructure provisioning, node pool creation, or non-Kubernetes Google Cloud services.","https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents\u002Fblob\u002Fmain\u002Fthird_party\u002Fgoogle-skills\u002Fgke-workload-troubleshooting\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":18},"01M721643JPG43MFDHGN067D7T","gke-workload-security","Audits, configures, and hardens workload-level security controls for Google Kubernetes Engine (GKE) applications and namespaces. Covers running security audits (`audit_cluster.sh`), enforcing Network Policies (default-deny and Dataplane V2 logging), isolating high-risk pods inside GKE Sandbox (`gVisor`), enforcing Pod Security Standards (`restricted` labeling) and pod securityContext, and mounting Secret Manager secrets via CSI (`SecretProviderClass`). Use when auditing workload security posture, isolating namespaces, applying pod security standards, or configuring network policies and secret volume mounts. Don't use for Workload Identity (use gke-workload-identity), cluster-wide control plane security, RBAC hardening, Binary Authorization, Shielded Nodes, or enabling platform-level GKE add-ons (use gke-platform-security instead).","https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents\u002Fblob\u002Fmain\u002Fthird_party\u002Fgoogle-skills\u002Fgke-workload-security\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":18},"01M721618QGFKZRWHS0RFVG7WT","gke-workload-scaling","Manages scaling for GKE workloads using HPA and VPA. Use when configuring Horizontal Pod Autoscaler (HPA), configuring Vertical Pod Autoscaler (VPA), or applying best practices for GKE workload autoscaling. Do not use for cluster-level autoscaling (Cluster Autoscaler), static cluster sizing, or configuring node-level machine styles directly.","https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents\u002Fblob\u002Fmain\u002Fthird_party\u002Fgoogle-skills\u002Fgke-workload-scaling\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":18},"01M7215PJTBTZ0W15ZZ2W32FF9","gke-upgrades","Plans, executes, and validates Google Kubernetes Engine (GKE) cluster upgrades and maintenance operations for both Standard and Autopilot clusters. Produces upgrade plans, pre\u002Fpost-upgrade checklists, maintenance runbooks with gcloud commands, release channel strategy, and troubleshooting guides. Handles node pool upgrade strategies (surge, blue-green), version compatibility, PDB management, and workload-specific concerns (stateful, GPU, operators). Use this skill whenever the user mentions GKE upgrades, Kubernetes version bumps, node pool maintenance, GKE patching, cluster version management, release channel selection, maintenance windows, surge upgrades, stuck upgrades, or any GKE lifecycle management task — even casual mentions like \"we need to upgrade our clusters\" or \"plan our next GKE maintenance\" or \"our upgrade is stuck.\" Don't use for GKE cluster creation, application onboarding, general networking\u002Frouting setup, or security policy configurations (use gke-basics or relevant GKE skills instead).","https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents\u002Fblob\u002Fmain\u002Fthird_party\u002Fgoogle-skills\u002Fgke-upgrades\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":18},"01M7215JX0FBZBTG4570CJ20HS","gke-tpu-metrics-monitoring","Monitors and troubleshoots GKE TPU workloads, nodes, and node pools using GKE system metrics and PromQL. Use when monitoring TensorCore duty cycle, TPU memory, node readiness, multi-host TPU node pool availability, host maintenance or preemption interruptions, and calculating MTTR or MTBI metrics for GKE TPUs. Don't use for general non-TPU GKE workload monitoring or non-metric TPU debugging.","https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents\u002Fblob\u002Fmain\u002Fthird_party\u002Fgoogle-skills\u002Fgke-tpu-metrics-monitoring\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":18},"01M7215EGS2CCPXE5YHDDRFSF8","gke-tpu-dynamic-slices-monitoring","Monitors, troubleshoots, and manages GKE TPU Dynamic Slices custom resources. Use when checking TPU slice lifecycle states, troubleshooting slice provisioning failures, validating single-slice or multi-slice (JobSet) workload manifests, or safely patching stuck finalizers and disabling the slice controller. Don't use for generic GKE cluster node pool creation or standard non-TPU workload management (use gke-basics or gke-cluster-creation instead).","https:\u002F\u002Fgithub.com\u002Fgke-labs\u002Fkube-agents\u002Fblob\u002Fmain\u002Fthird_party\u002Fgoogle-skills\u002Fgke-tpu-dynamic-slices-monitoring\u002FSKILL.md",[],[]]