[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["# Protecting cluster metadata\n\n[Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nGoogle Kubernetes Engine (GKE) uses\n[instance metadata](/compute/docs/storing-retrieving-metadata) to configure node\nvirtual machines (VMs), but some of this metadata is potentially sensitive and\nshould be protected from workloads running on the cluster.\n\nBefore you begin\n----------------\n\nBefore you start, make sure that you have performed the following tasks:\n\n- Enable the Google Kubernetes Engine API.\n[Enable Google Kubernetes Engine API](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com)\n- If you want to use the Google Cloud CLI for this task, [install](/sdk/docs/install) and then [initialize](/sdk/docs/initializing) the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running `gcloud components update`. **Note:** For existing gcloud CLI installations, make sure to set the `compute/region` [property](/sdk/docs/properties#setting_properties). If you use primarily zonal clusters, set the `compute/zone` instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: `One of [--zone, --region] must be supplied: Please specify location`. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.\n\nConfigure node service account\n------------------------------\n\nEach node's service account credentials continue to be exposed to workloads.\nBy default, your nodes use the [Compute Engine default service account](/compute/docs/access/service-accounts#default_service_account).\nYou should configure a **minimally-privileged service account** for your nodes\nto use instead of the Compute Engine default service account. Then, attach\nthis service account to your nodes, so that an attacker cannot circumvent\nGKE metadata protections by using the Compute Engine API to\naccess the underlying VM instances directly.\n\nFor more information, refer to [Use least privilege node service accounts](/kubernetes-engine/docs/how-to/hardening-your-cluster#use_least_privilege_sa).\n| **Caution:** Do not use a service account that has `compute.instances.get` permission, the Compute Instance Admin role, or other similar permissions, as they allow potential attackers to obtain instance metadata using the Compute Engine API. Restrict the permissions of a node VM by using service account permissions, *not access scopes* . For more information, see [Migrating from legacy access scopes](/kubernetes-engine/docs/how-to/access-scopes#service_account).\n\nTo create a minimally privileged node service account, perform the following\nsteps:\n\n1. Create a new Identity and Access Management (IAM) service account and save the email\n address in an environment variable:\n\n gcloud iam service-accounts create \u003cvar translate=\"no\"\u003eNODE_SA_NAME\u003c/var\u003e \\\n --display-name=\"\u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e\"\n export NODE_SA_EMAIL=$(gcloud iam service-accounts list --format='value(email)' \\\n --filter='displayName:\u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e')\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNODE_SA_NAME\u003c/var\u003e: the name of your new node service account.\n - \u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e: the display name of the new service account.\n\n The node service account email address has the format \u003cvar scope=\"NODE_SA_NAME\" translate=\"no\"\u003eNODE_SA_NAME\u003c/var\u003e`@`\u003cvar scope=\"PROJECT_ID\" translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.iam.gserviceaccount.com`.\n2. Configure your service account with the minimum roles and permissions to run\n your GKE nodes:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=serviceAccount:$NODE_SA_EMAIL \\\n --role=roles/monitoring.metricWriter\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=serviceAccount:$NODE_SA_EMAIL \\\n --role=roles/monitoring.viewer\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=serviceAccount:$NODE_SA_EMAIL \\\n --role=roles/logging.logWriter\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your Google Cloud project ID.\n\n Additionally, if your cluster pulls private images from [Artifact Registry](/artifact-registry/docs/access-control),\n add the `roles/artifactregistry.reader` role: \n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=serviceAccount:$NODE_SA_EMAIL \\\n --role=roles/artifactregistry.reader\n\nMetadata concealment\n--------------------\n\n| **Warning:** [Workload Identity Federation for GKE](/kubernetes-engine/docs/how-to/workload-identity) replaces the need to use metadata concealment and the two approaches are incompatible. We recommend that you use Workload Identity Federation for GKE instead of metadata concealment.\n|\n| **Beta**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nGKE *metadata concealment* prevents user Pods from accessing\n`kube-env`, which contains kubelet credentials, and the VM's\n[instance identity token](/compute/docs/instances/verifying-instance-identity).\n\nMetadata concealment firewalls traffic from user Pods (Pods *not* running on\n`HostNetwork`) to the cluster metadata server, only allowing safe queries. The\nfirewall prevents user Pods from using kubelet credentials for privilege\nescalation attacks, or from using VM identity for instance escalation attacks.\n\nWorkload Identity Federation for GKE replaces the need to use metadata concealment and expands\non the protections that metadata concealment offers. You should use\nWorkload Identity Federation for GKE instead of metadata concealment in all situations. To\nlearn more, see\n[About Workload Identity Federation for GKE](/kubernetes-engine/docs/concepts/workload-identity).\n\nTo enable metadata concealment, use the deprecated `--workload-metadata=SECURE`\noption in your\n[`gcloud beta container clusters create` command](/sdk/gcloud/reference/beta/container/clusters/create#--workload-metadata)\nor in your\n[`gcloud beta container node-pools create` command](/sdk/gcloud/reference/beta/container/node-pools/create#--workload-metadata).\n\n### Limitations\n\nMetadata concealment has limitations such as the following:\n\n- Metadata concealment only protects access to `kube-env` and the node's instance identity token.\n- Metadata concealment does not restrict access to the node's [service account](/compute/docs/access/service-accounts).\n- Metadata concealment does not restrict access to other related instance metadata.\n- Metadata concealment does not restrict access to other legacy metadata APIs.\n- Metadata concealment doesn't restrict traffic from Pods running on the host network (`hostNetwork: true` in the Pod specification).\n\nDisabling and transitioning from legacy metadata APIs\n-----------------------------------------------------\n\nThe `v0.1` and `v1beta1` Compute Engine metadata server endpoints were deprecated\nand shutdown on **September 30, 2020**.\n\nFor the shutdown schedule, refer to [`v0.1` and `v1beta1` metadata server endpoints deprecation](/compute/docs/deprecations/v0.1-v1beta1-metadata-server).\n\nWhat's next\n-----------\n\n- [Enable Workload Identity Federation for GKE on your clusters](/kubernetes-engine/docs/how-to/workload-identity)."]]