Prepare and test your skills

Prepare and test your skills

Manage Permissions and Access Controls for GKE-Linked Service Accounts is the practice of giving applications on Google Kubernetes Engine (GKE) only the Identity and Access Management (IAM) permissions they need to call Google Cloud APIs. GKE workloads use two identities together: a Google Cloud service account that IAM recognizes for Google APIs, and a Kubernetes service account that is recognized only inside the cluster. Workload Identity Federation for GKE (opens in a new tab) links the two identities so a Pod can act with the Google service account's permissions without storing long-lived keys.
Google Cloud service accounts and Kubernetes service accounts are different identities with different trust boundaries. A Kubernetes service account (opens in a new tab) authenticates a Pod to the Kubernetes API inside its own cluster, but it is not recognized by any Google Cloud API and cannot replace a Google Cloud service account. A Google Cloud service account (opens in a new tab) is recognized by Google Cloud APIs and carries IAM roles that control what the workload can read, write, or administer.
Workload Identity Federation for GKE connects the identities across that boundary. When a Pod uses a linked Kubernetes service account, requests flow from the Pod to Google Cloud APIs using the Google identity, without managing certificates or keys. Access works by direct resource access, where IAM roles are granted to the Kubernetes service account identity directly on Google resources, or by impersonation, where the Kubernetes service account is bound to an IAM service account that serves as the identity for Google API calls.
Assigning least-privilege IAM roles to GKE workloads means binding a service account to only the predefined roles required for the APIs it calls. The binding connects a member such as serviceAccount:SERVICE_ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com to a role such as roles/cloudtranslate.user, and the workload can then use only the permissions in that role. The correct role is determined by the documentation for the Cloud API the workload calls.
Common permission configurations for GKE-linked service accounts include:
roles/iam.serviceAccountUser for a human user who needs permission to impersonate the service account and act with its permissions.A missing role causes the Google API to deny the request, while an extra or overly broad role widens what every workload using that service account can do. That tradeoff is why production workloads use a dedicated Google Cloud service account per application instead of sharing one broad identity.
Development and production permission models for GKE differ in which identity carries Google API permissions and how broadly those permissions are shared. The development model relies on the shared node identity, while the production model gives each workload its own federated identity.
| Configuration | Identity used for Google API calls | Workload Identity and scope settings |
|---|---|---|
| Development only | Compute Engine default service account shared by all workloads on the node, with access scopes set to Allow full access to all Cloud APIs | Workload Identity Federation for GKE is not enabled; settings are made in Node Pools > Security and Cluster > Security |
| Production recommended | Dedicated Google Cloud service account linked to a specific Kubernetes service account | Workload Identity Federation for GKE is enabled; each Deployment references its own Kubernetes service account |
The development model overprovisions permissions because traffic from every Pod on the node flows to Google APIs with the same shared node identity. The production model keeps a trust boundary around each workload because requests from one Deployment flow with only the IAM roles granted to its linked Google Cloud service account.
Exam tip: GKE cluster service account and access scope settings are permanent and cannot be changed after the cluster is created, and the shared Compute Engine default service account with full API access should be used only for development.
Linking a workload to its permissions in order is the sequence that lets a GKE Deployment act with the correct Google Cloud service account. The Deployment depends on the Kubernetes service account reference, and the Kubernetes service account depends on its link to the Google Cloud service account.
.spec.serviceAccountName field in the Kubernetes Deployment YAML file, located under the kubernetes-manifests folder for Cloud Code sample applications, so Pods from that Deployment use the linked Kubernetes service account.If any step is misconfigured, access to Google Cloud APIs breaks in a predictable way. A Deployment that points to the wrong service account name uses the wrong identity, a missing IAM grant results in a permission-denied error from the API, and an API that does not support federation needs the alternative link between Kubernetes ServiceAccounts and IAM.
Service accounts in Google Kubernetes Engine (GKE) give applications their own identities so code can authenticate without using a human login. A GKE application often needs two kinds of identity at once: a Kubernetes identity to talk to the cluster and a Google Cloud identity to talk to Google Cloud services. Google Cloud service accounts (opens in a new tab) provide the Google Cloud identity, while Kubernetes service accounts provide the in-cluster identity.
A Google Cloud service account is an identity for workloads that Google Cloud can recognize for authentication and authorization. Instead of granting access directly to a workload, you grant access to the service account and then let the workload use that service account as its identity. When a GKE workload calls a Google Cloud service, data flows from the workload to the Google API with the service account identity, and Identity and Access Management (IAM) checks which roles that identity holds. This separation lets the same application code run in different environments with different permissions by changing only which service account it uses.
A Kubernetes service account is a separate application identity that works only inside a Kubernetes cluster. A Kubernetes service account (opens in a new tab) can authenticate when an application calls the Kubernetes API of its own cluster, and a Pod associated with a service account can use that API without configuring certificates or other credentials. A Kubernetes service account cannot be used outside the cluster because it is not recognized by any Google APIs, so it is not a replacement for a Google Cloud service account.
The two account types divide responsibility by boundary:
| Identity | Recognized by | Used for |
|---|---|---|
| Kubernetes service account | Kubernetes API inside one cluster | Authenticating a Pod to the cluster API server |
| Google Cloud service account | Google Cloud APIs and IAM | Authenticating a GKE workload to Google Cloud services such as storage, monitoring, and translation |
An application that only manages cluster objects needs only the first identity, while an application that reads buckets, writes metrics, or calls other Google APIs also needs the second identity.
The relationship between a service account and Identity and Access Management (IAM) separates identity from permission. A Google Cloud service account by itself has no access; an IAM role attached to that service account defines what the identity is allowed to do. For example, granting a Monitoring Metric Writer role lets the identity write metrics, while granting a Cloud Translation API User role lets the identity call the translation service. The GKE workload then inherits only the permissions of the service account it uses, which supports least privilege because each application can receive a different service account with only the minimal roles it needs.
Service accounts should be used when a GKE application needs controlled, auditable access to Google Cloud resources without embedding long-lived keys in code. Typical application-identity requirements that service accounts address include integrating with third-party APIs and authentication solutions, enabling authentication across hybrid or multi-cloud environments, and preventing leakage of credentials. Workload Identity (opens in a new tab) links a Kubernetes service account to a Google Cloud service account, so services running as that Kubernetes service account automatically authenticate as the linked Google Cloud service account when they call Google Cloud APIs.
Using one shared node identity, such as the Compute Engine default service account with full access to all Cloud APIs, overprovisions permissions because every workload on the node shares the same identity. That shared-identity pattern is suitable only for development, while production workloads should use Workload Identity with a dedicated Google Cloud service account per application. Choose a dedicated service account when workloads need different permissions, least privilege matters, or access must be granted and revoked per application rather than per node.
Exam tip: A Kubernetes service account alone cannot call Google Cloud APIs; the Pod must use Workload Identity to act as a linked Google Cloud service account that holds the IAM roles.
Workload Identity Federation for GKE (opens in a new tab) is the secure way for applications running in Google Kubernetes Engine (GKE) to authenticate to Google Cloud APIs. A Kubernetes service account controls access inside the cluster, while a Google Cloud service account controls access to Google Cloud services, and Workload Identity links the two so a Pod can use both without managing certificates, keys, or other long-lived credentials.
Kubernetes service accounts and Google Cloud service accounts are different identities for different boundaries. A Kubernetes service account (opens in a new tab) is meant for applications, not humans, and it authenticates only when an application calls the Kubernetes API of its own cluster. A Kubernetes service account is not recognized by any Google APIs outside the cluster, so it cannot replace a Google Cloud service account.
When a Pod is deployed, the Pod is associated with a Kubernetes service account. That association lets the application call the Kubernetes API without configuring certificates. By linking that same Kubernetes service account to a Google Cloud service account with Workload Identity, the application can also call Google Cloud APIs such as Storage or Spanner with the same credential-free pattern.
How Workload Identity links identities to Google Cloud is defined by two access paths that both provide fine-grained, per-application permissions. With direct resource access, IAM roles are granted to the Kubernetes service account identity directly on the Google Cloud resource, so no intermediate service account is used. Most Google Cloud APIs support direct resource access, although certain API methods have federation limitations.
With service account impersonation, the Kubernetes ServiceAccount is bound to an Identity and Access Management (IAM) service account, and the IAM service account serves as the identity when the workload calls Google Cloud APIs. This impersonation path is the alternative to use when direct federation is not supported or is blocked by a service limitation. In both models, GKE grants IAM roles to distinct, fine-grained sets of principals for each application, rather than sharing one broad identity across the cluster.
Configuring impersonation links a specific Kubernetes ServiceAccount to a specific IAM service account. The cluster must have Workload Identity enabled, and in Standard clusters Pods must run on node pools with the GKE Metadata Server enabled, while in Autopilot clusters every node already uses it.
kubectl create namespace.kubectl create serviceaccount.gcloud iam service-accounts create, or reuse an existing IAM service account in the organization.roles/spanner.viewer, on the target project or resource so the IAM service account can access those APIs.roles/iam.workloadIdentityUser role on the IAM service account for the member serviceAccount:PROJECT_ID.svc.id.goog[NAMESPACE/KSA_NAME], which names the exact namespace and KSA.kubectl annotate serviceaccount with iam.gke.io/gcp-service-account=IAM_SA_NAME@IAM_SA_PROJECT_ID.iam.gserviceaccount.com so GKE sees the link.Exam tip: Impersonation requires both the roles/iam.workloadIdentityUser binding and the iam.gke.io/gcp-service-account annotation; configuring only one side does not complete the link.
Why Workload Identity is more secure than node-level authentication is that it replaces a shared node identity with a per-application identity. With an attached service account, the service account acts as the default identity for the resource, and any workload running on that node uses the same identity when accessing Google Cloud services. That broad scope means every Pod on the node receives the same permissions.
Workload Identity narrows that scope so each application authenticates as its own Kubernetes service account or linked IAM service account. Permissions flow from the Pod to its KSA to Google Cloud, and different applications in the same cluster can hold different IAM roles. The approach also avoids service account keys, which use a long-lived private RSA key that must be stored, rotated, and protected, and which are a security risk if not managed correctly.
| Authentication method | Identity scope | Credential handling |
|---|---|---|
| Attached node service account | Shared by all workloads on the node or resource | Workloads inherit the node default identity |
| Workload Identity Federation for GKE | Fine-grained per Kubernetes service account and application | Short-lived federated tokens or impersonation, no stored keys |
| Service account keys | Tied to one IAM service account wherever the key is copied | Long-lived private key file that must be secured and rotated |
Because Workload Identity uses federation and short-lived credentials tied to a specific namespace and service account, a compromised Pod does not expose the credentials of other applications or of the underlying node.
A Google Cloud service account is recognized by Google Cloud APIs and carries Identity and Access Management (IAM) roles that control what a workload can read, write, or administer, while a Kubernetes service account authenticates only to the Kubernetes API inside its own cluster and is not recognized by any Google Cloud API. Workload Identity Federation for GKE links the two identities so a Pod using a linked Kubernetes service account can call Google Cloud APIs with the Google identity without storing long-lived keys.
Use Workload Identity Federation for GKE with a dedicated Google Cloud service account per application for production workloads to maintain least privilege and a trust boundary around each workload, and reserve the shared Compute Engine default service account with Allow full access to all Cloud APIs for development only. The development model overprovisions permissions because every Pod on the node shares the same node identity, while the production model lets each Deployment act with only the IAM roles granted to its linked Google Cloud service account.
Impersonation requires both an Identity and Access Management (IAM) allow policy with the roles/iam.workloadIdentityUser role on the Google Cloud service account for the exact namespace and Kubernetes service account member and the iam.gke.io/gcp-service-account annotation on the Kubernetes service account naming the Google Cloud service account. The cluster must have Workload Identity Federation for GKE enabled with the GKE Metadata Server in use, and the Deployment must reference the linked account in its spec.serviceAccountName field while the Google Cloud service account holds only the required roles for the target APIs.
You are deploying a reporting service as a Pod on Google Kubernetes Engine (GKE). The service needs to read data files from a specific Cloud Storage bucket.
Your deployment must meet the following security requirements:
Which authentication method should you configure?
Generate a JSON service account private key, store it in a Kubernetes Secret, and mount it into the Pod container as a credential file
Assign the Storage Object Viewer IAM role to the default Compute Engine service account attached to the GKE worker nodes
Attach the service account to the GKE control plane and configure node access scopes to allow Cloud Storage API access
Configure Workload Identity to link a Kubernetes service account to a Google Cloud service account, and run the Pod with that Kubernetes service account
Last updated