GKE 適用的工作負載身分聯盟 (僅適用於在 Google Kubernetes Engine 上執行的工作負載)
受管理的工作負載身分 (僅適用於在 Compute Engine 和 GKE 上執行的工作負載)
服務帳戶金鑰
連結的服務帳戶
對於部分 Google Cloud 資源,您可以指定使用者管理的服務帳戶,做為資源的預設身分。這個程序稱為將服務帳戶「附加」至資源,或將服務帳戶「關聯」至資源。
當在資源上執行的程式碼存取 Google Cloud 服務和資源時,會使用附加至資源的服務帳戶做為身分。舉例來說,如果您將服務帳戶附加至 Compute Engine 執行個體,且執行個體上的應用程式使用用戶端程式庫呼叫 API,這些應用程式就會自動使用附加的服務帳戶進行驗證和授權。 Google Cloud
對於在 GKE 上執行的工作負載,您可以透過 Workload Identity Federation for GKE,為叢集中的每個應用程式,授予不同且精細的主體集 IAM 角色。透過 GKE 適用的工作負載身分聯盟,GKE 叢集中的 Kubernetes 服務帳戶可直接使用工作負載身分聯盟存取資源,也可以使用 IAM 服務帳戶模擬功能間接存取資源。 Google Cloud
使用直接資源存取權時,您可以直接在 Google Cloud 服務的資源上,將 IAM 角色授予 Kubernetes 服務帳戶身分。大多數 Google Cloud API 支援直接存取資源。不過,使用身分聯盟時,某些 API 方法可能會受到限制。如要查看這些限制的清單,請參閱「支援的產品和限制」。
或者,工作負載也可以使用服務帳戶模擬功能,將設定的 Kubernetes ServiceAccount 繫結至 IAM 服務帳戶,做為存取 Google CloudAPI 時的身分。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Identities for workloads\n\nThis page describes the identity types that you can use to configure\nyour workloads' access to Google Cloud resources.\n\nGoogle Cloud provides the following types of identities for workloads:\n\n- [**Workload Identity Federation**](/iam/docs/workload-identity-federation) and\n [**Workload Identity Federation for GKE**](/kubernetes-engine/docs/concepts/workload-identity) let your workloads access\n most Google Cloud services by using federated identities that are\n authenticated through an external identity provider (IdP). After\n Google Cloud authenticates the identity as a principal, the principal\n can access resources by using IAM roles that you grant.\n\n- [**Google Cloud service accounts**](/iam/docs/service-account-overview) can act as\n identities for workloads in production environments. Instead of granting access\n to a workload directly, you grant access to a service account, then have the\n workload use the service account as its identity.\n\n- [**Managed workload identities**](/iam/docs/managed-workload-identity) [(Preview)](/products#product-launch-stages)\n let you bind strongly attested identities to your Compute Engine and\n GKE workloads.\n\nThe types of identities that you can use for workloads and the way that you\nconfigure them depends on where your workloads are running.\n\nConfigure workloads on Google Cloud\n-----------------------------------\n\nIf you're running workloads on Google Cloud, you can use the following\nmethods to configure identities for your workloads:\n\n- Attached service accounts\n- Workload Identity Federation for GKE (for workloads running on Google Kubernetes Engine only)\n- Managed workload identities (for workloads that run on Compute Engine and GKE only)\n- Service account keys\n\n### Attached service accounts\n\n\nFor some Google Cloud resources, you can specify a user-managed service account that the\nresource uses as its default identity. This process is known as *attaching* the service\naccount to the resource, or *associating* the service account with the resource.\n\n\nWhen code running on the resource accesses Google Cloud services and resources, it uses the\nservice account attached to the resource as its identity. For example, if you [attach a\nservice account to a Compute Engine instance](/compute/docs/access/service-accounts#associating_a_service_account_to_an_instance), and the applications on the instance use a [client library](/apis/docs/client-libraries-explained) to call Google Cloud APIs,\nthose applications automatically use the attached service account for authentication and\nauthorization.\n\nIn most cases, you must attach a service account to a resource when you create\nthat resource. After the resource is created, you cannot change which service\naccount is attached to the resource. Compute Engine instances are an\nexception to this rule; you can change which service account is attached to an\ninstance as needed.\n\nTo learn more, see [Attach a service account to a resource](/iam/docs/attach-service-accounts).\n\n### Workload Identity Federation for GKE\n\nFor workloads that run on GKE, Workload Identity Federation for GKE lets you\ngrant IAM roles to distinct, fine-grained sets of principals, for\neach application in your cluster. Workload Identity Federation for GKE lets Kubernetes\nservice accounts in your GKE cluster access Google Cloud\nresources directly, by using Workload Identity Federation, or indirectly,\nby using IAM service account impersonation.\n\nBy using direct resource access, you can grant IAM roles to the\nKubernetes service account identity directly on the Google Cloud service's\nresources. Most Google Cloud APIs support direct resource access. However,\nwhen using identity federation, certain API methods might have limitations. For\na list of these limitations, see [Supported products and limitations](/iam/docs/federated-identity-supported-services).\n\nAs an alternative, workloads can also use service account impersonation, where\nthe configured Kubernetes ServiceAccount is bound to an IAM\nservice account, which serves as the identity when accessing Google Cloud\nAPIs.\n\nTo learn more about GKE Workload Identity Federation for GKE, see\n[Workload Identity Federation for GKE](/kubernetes-engine/docs/concepts/workload-identity).\n\n### Managed workload identities\n\n|\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the\n| General Service Terms section of the\n| [Service Specific Terms](/terms/service-terms#1).\n| Pre-GA features are available \"as is\" and might have limited support. For more\n| information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nManaged workload identities let you bind strongly attested identities to your\nCompute Engine and GKE workloads. You can use managed\nworkload identities to authenticate your workloads to other workloads using\n[mTLS](https://en.wikipedia.org/wiki/Mutual_authentication).\n\nTo learn more about managed workload identities, and how to configure platforms\nto use them, see [Managed workload identities overview](/iam/docs/managed-workload-identity).\n\nConfigure external workloads\n----------------------------\n\nIf you're running workloads outside of Google Cloud, you can use the\nfollowing methods to configure identities for your workloads:\n\n- Workload Identity Federation\n- Service account keys\n\n### Workload Identity Federation\n\nYou can use Workload Identity Federation with workloads on\nGoogle Cloud or external workloads that run on platforms such as AWS,\nAzure, GitHub, and GitLab.\n\nWorkload Identity Federation lets you use credentials from external identity\nproviders like [AWS, Azure](/iam/docs/workload-identity-federation-with-other-clouds), and [Active Directory](/iam/docs/workload-identity-federation-with-active-directory)\nto generate short-lived credentials, which workloads can use to temporarily\nimpersonate service accounts. Workloads can then access Google Cloud\nresources, using the service account as their identity.\n\nWorkload Identity Federation is the preferred way to configure identities for\nexternal workloads.\n\nTo learn more about Workload Identity Federation, see\n[Workload Identity Federation](/iam/docs/workload-identity-federation).\n\n### Service account keys\n\n\nA service account key lets a workload authenticate as a service account, then\nuse the service account's identity for authorization.\n| **Note:** Service account keys are a security risk if not managed correctly. You should [choose a more secure alternative to service account keys](/docs/authentication#auth-decision-tree) whenever possible. If you must authenticate with a service account key, you are responsible for the security of the private key and for other operations described by [Best practices for managing service account keys](/iam/docs/best-practices-for-managing-service-account-keys). If you are prevented from creating a service account key, service account key creation might be disabled for your organization. For more information, see [Managing secure-by-default organization resources](/resource-manager/docs/secure-by-default-organizations).\n|\n|\n| If you acquired the service account key from an external source, you must validate it before use.\n| For more information, see [Security requirements for externally sourced credentials](/docs/authentication/external/externally-sourced-credentials).\n\n\u003cbr /\u003e\n\nLocal development\n-----------------\n\nIf you're developing in a local environment, you can configure workloads to use\neither your user credentials or a service account for authentication and\nauthorization. For more information, see\n[Local development environment](/docs/authentication/set-up-adc-local-dev-environment) in the authentication documentation.\n\nWhat's next\n-----------\n\n- Learn how to [set up authentication by using service accounts](/docs/authentication#service-accounts).\n- Learn how to [set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n- Learn how to [grant service accounts access to resources](/iam/docs/granting-changing-revoking-access)."]]