Service Accounts, Impersonation, and Workload Identity Federation
A service account is the identity your workloads use to call Google Cloud APIs: a non-human principal with an email address such as name@project.iam.gserviceaccount.com that holds IAM roles just as a user does, but authenticates as software instead of a person. Managing service accounts well means creating user-managed accounts per workload (and recognising the Google-managed service agents and default accounts you did not create), granting each one only the roles its job needs, attaching them to Compute Engine VMs, Cloud Run services and GKE workloads so code gets credentials automatically, controlling who may use or impersonate them, and avoiding downloadable keys in favour of keyless options: impersonation with short-lived credentials, Workload Identity Federation for GKE, and Workload Identity Federation for workloads outside Google Cloud. This lesson covers the full lifecycle with gcloud commands, the organization policies that now guard service accounts by default, and a comparison of every authentication option.
On this page10 sections
- What service accounts are — and the three kinds you will meet
- Service agents: creating them and granting the roles a service needs
- Creating service accounts and granting minimum permissions
- Disabling, deleting and undeleting service accounts
- Attaching service accounts to resources
- Managing the IAM permissions of a service account itself
- Why service account keys are dangerous
- Impersonation and short-lived credentials
- Workload Identity Federation for GKE: service accounts for GKE applications
- Workload Identity Federation and the authentication options compared
- Distinguish service agents, default service accounts and user-managed service accounts, and grant service agents the roles a service needs
- Create, disable, delete and undelete service accounts, and grant them least-privilege roles in the same or another project
- Attach service accounts to Compute Engine VMs and Cloud Run services, and explain how access scopes combine with IAM roles
- Choose between the roles granted on a service account: Service Account User, Token Creator, Creator, Admin and Key Admin
- Impersonate a service account and create short-lived access tokens and ID tokens, including lifetimes beyond one hour
- Apply the organization policies that restrict service account keys, default grants and cross-project use
- Configure Workload Identity Federation for GKE and Workload Identity Federation for external workloads, including attribute conditions
What service accounts are — and the three kinds you will meet
A service account is a non-human identity that applications, VMs and pipelines use to authenticate to Google Cloud APIs. It is a principal like any other (you bind roles to it with serviceAccount:EMAIL members), but it belongs to a project, is identified by an email address and never signs in with a password. Three kinds appear in projects, and you need to tell them apart.
Google-managed service accounts (service agents) let Google services act on resources in your project. Their email usually has the form service-PROJECT_NUMBER@gcp-sa-SERVICE.iam.gserviceaccount.com (for example gcp-sa-pubsub for Pub/Sub); a few older services use their own domains, such as the Cloud Storage service agent service-PROJECT_NUMBER@gs-project-accounts.iam.gserviceaccount.com. Google creates them as you enable and use services, you never hold their credentials, and they appear on your project's IAM page holding a service agent role. Seeing one that nobody on your team created is normal.
Default service accounts are created in your project when you enable certain services: the Compute Engine default service account (PROJECT_NUMBER-compute@developer.gserviceaccount.com), which VMs and, unless you choose otherwise, Cloud Run services run as; and the App Engine default service account (PROJECT_ID@appspot.gserviceaccount.com). They live in your project and you can change their grants, but historically they were automatically granted the project-wide Editor role. Attached by default and broadly privileged is exactly what least privilege forbids, so do not use them for real workloads (the organization policy that now stops that Editor grant is covered below).
User-managed service accounts are the ones you create deliberately, one per workload, with an email of the form ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com. You decide their roles, which resources carry them and who may act as them.
| Kind | Who creates it | Email pattern | What you manage |
|---|---|---|---|
| Service agent | Google, as services are enabled and used | service-PROJECT_NUMBER@gcp-sa-SERVICE.iam.gserviceaccount.com | Only its role grants, when a service's docs require it |
| Default service account | Google, when Compute Engine or App Engine is enabled | PROJECT_NUMBER-compute@developer.gserviceaccount.com, PROJECT_ID@appspot.gserviceaccount.com | Its roles and attachments (avoid it for workloads) |
| User-managed | You | ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com | Everything: roles, attachments, keys, lifecycle |
Service agents: creating them and granting the roles a service needs
A service agent needs IAM roles on the resources a Google service touches on your behalf, and sometimes you must grant them yourself. When Google creates an agent automatically as a service is enabled, it normally also grants that agent its service agent role on the project. Some features, though, need the agent to reach a resource that the default role does not cover.
The classic case is customer-managed encryption keys (CMEK). When you set a Cloud KMS key as a Cloud Storage bucket's default key, it is the Cloud Storage service agent of the bucket's project, not you, that encrypts and decrypts objects with the key. That agent therefore needs roles/cloudkms.cryptoKeyEncrypterDecrypter on the key; without it, writes and reads that use the key fail with a permission error, however many roles you hold yourself. Grant the combined Encrypter/Decrypter role because the service must do both: roles/cloudkms.cryptoKeyDecrypter alone cannot write new objects and roles/cloudkms.cryptoKeyEncrypter alone cannot read them back. gcloud storage service-agent --project=PROJECT_ID prints the agent's address.
You can also create a service agent before first use, for example in automation that must grant it access before the service runs: gcloud workload-identity service-agents generate (older material uses gcloud beta services identity create --service=SERVICE). Agents created at your request are not granted any roles automatically, so you must grant the roles the service's documentation lists for its agent; otherwise the service fails with permission errors that do not occur in projects where Google created the agent itself.
Creating service accounts and granting minimum permissions
Create a service account with gcloud iam service-accounts create app-backend --display-name="Backend API" in the target project; the account ID becomes the email prefix, so the account is app-backend@PROJECT_ID.iam.gserviceaccount.com. List accounts with gcloud iam service-accounts list.
Granting the account access works exactly like granting a user: bind a role with the service account as the member. gcloud projects add-iam-policy-binding PROJECT_ID --member=serviceAccount:app-backend@PROJECT_ID.iam.gserviceaccount.com --role=roles/pubsub.publisher lets the workload publish to Pub/Sub topics in the project. Least privilege is stricter in practice for workloads because their needs are predictable: an application that publishes to one topic and writes to one bucket needs roles/pubsub.publisher and roles/storage.objectCreator, bound on that topic and that bucket rather than the project where the service supports resource-level policies. Never give a workload Editor because listing its needs feels tedious; that list is the security work.
Plan for one service account per workload, not one shared account. Separate accounts keep the blast radius small, make Cloud Audit Logs attributable to the right application, and let you revoke one workload's access without touching the others. A scenario where several applications share one powerful account is describing the problem; splitting it per workload is the fix.
Using an account in another project. A service account is a principal anywhere in the organization: to let it read a bucket in project B, grant it a role on that bucket in project B; nothing changes in its home project. Attaching an account to a resource in another project (a VM in one project running as an account that lives in a central identity project) is different: it needs Service Account User on the account and is blocked when the organization policy constraints/iam.disableCrossProjectServiceAccountUsage is enforced on the service account's project. Google enforces that constraint by default, which is why cross-project attachment fails out of the box; teams that centralise workload identities in one project must stop enforcing it there. Some services also need their service agent in the resource's project (for example the Compute Engine service agent) to hold Token Creator on the account.
Disabling, deleting and undeleting service accounts
Disable before you delete. gcloud iam service-accounts disable EMAIL stops the account authenticating but keeps its identity and role bindings, and gcloud iam service-accounts enable EMAIL reverses it instantly. That makes disabling the safe first step when retiring an account: if something breaks, you re-enable it.
Deletion (gcloud iam service-accounts delete EMAIL) is harder to undo. A deleted account can be undeleted within 30 days with gcloud beta iam service-accounts undelete ACCOUNT_UNIQUE_ID, using the account's numeric unique ID (the email no longer resolves; find the ID in the audit log entry for the deletion). Undeleting restores the same identity, and its existing role bindings work again. Undelete is not possible once 30 days have passed. While a new account with the same name exists, it also blocks undeleting the original; delete the new account first, then undelete.
Do not try to "recreate" a deleted account under the same name. IAM bindings refer to the account's unique ID, so a new account with the same email is a different identity: it inherits none of the old roles (the old bindings show as deleted:serviceAccount:...), and while it exists it blocks undeleting the original until you delete it.
Attaching service accounts to resources
Attaching a service account to a resource gives the code running there credentials without any secret in your code. The attached account becomes the resource's identity: Google issues short-lived access tokens for it on demand, client libraries pick them up through Application Default Credentials, and nothing sensitive is written to disk. To attach an account, the caller needs roles/iam.serviceAccountUser on that account as well as permission to create the resource.
Compute Engine. Attach at creation with gcloud compute instances create web-1 --service-account=app-backend@PROJECT_ID.iam.gserviceaccount.com --scopes=cloud-platform. To change the attached account or the scopes of an existing VM, stop the VM, then run gcloud compute instances set-service-account web-1 --service-account=EMAIL --scopes=cloud-platform, then start it.
Access scopes are a legacy, per-VM limit on what the VM's tokens may be used for; effective access is the intersection of the scopes and the account's IAM roles. The default scopes allow read-only Cloud Storage, Logging write, Monitoring write, Service Control, Service Management read-only and Trace append, and nothing else (no Pub/Sub, no Storage writes). If you run gcloud compute instances create without --scopes, it applies these defaults, even when you pass a user-managed --service-account; the console, by contrast, selects the full cloud-platform scope when you pick a user-managed account. Two different errors follow from this:
- An insufficient authentication scopes error means the token's scopes do not cover the API. Granting more IAM roles will not help; change the scopes (stop the VM,
set-service-account --scopes). - A permission denied error with a missing IAM permission means the account lacks a role; grant the role.
Google's recommended pattern is to give VMs a dedicated service account with the cloud-platform scope and let IAM roles be the only place access is decided.
Cloud Run. Set the service identity at deploy time with gcloud run deploy my-service --image=IMAGE --service-account=app-backend@PROJECT_ID.iam.gserviceaccount.com. If you omit --service-account, the service runs as the Compute Engine default service account, which in older projects holds Editor, so an unexpectedly over-privileged Cloud Run service usually traces back to a missing --service-account. Whoever deploys also acts as the runtime identity, so the deployer (a person or a CI/CD pipeline's own service account) needs roles/iam.serviceAccountUser on the runtime account in addition to its Cloud Run role. The deploying identity and the runtime identity are two different accounts with two different jobs.
GKE. Do not give your application's powers to the node service account: it is shared by every pod on the node. Per-workload identity on GKE uses Workload Identity Federation for GKE, covered below.
Managing the IAM permissions of a service account itself
A service account is both a principal and a resource. As a principal it appears as a serviceAccount: member in other resources' policies; that is what the account can do. As a resource it has its own IAM policy saying who can use, impersonate or administer it; that is what can be done to the account. View that policy with gcloud iam service-accounts get-iam-policy EMAIL and edit it with gcloud iam service-accounts add-iam-policy-binding EMAIL --member=user:alice@example.com --role=roles/iam.serviceAccountUser.
| Role | What it allows | What it does not allow |
|---|---|---|
roles/iam.serviceAccountUser | Act as the account: attach it to VMs, Cloud Run services and other resources (iam.serviceAccounts.actAs) | Minting tokens through the Service Account Credentials API |
roles/iam.serviceAccountTokenCreator | Impersonate: create access tokens, ID tokens and signed JWTs/blobs for the account | Managing the account or its keys |
roles/iam.serviceAccountCreator | Create service accounts only | Updating, disabling, deleting or changing IAM policies |
roles/iam.serviceAccountAdmin | Full account lifecycle (create, update, disable, enable, delete, undelete) and managing each account's IAM policy | Creating or managing keys |
roles/iam.serviceAccountKeyAdmin | List, create, disable and delete the account's keys | Changing roles or IAM policies; using the Credentials API |
Note that Key Admin can create keys, and a key is a credential: a Key Admin can mint a key and authenticate as the account unless constraints/iam.disableServiceAccountKeyCreation is enforced. Grant it as rarely as Token Creator.
These roles follow normal IAM inheritance: granted on one service account they cover that account; granted on the project they cover every service account in it. That makes project-level grants an escalation path. Anyone who can create a resource and holds Service Account User on the whole project can attach any account in it, including the most privileged one, and then use that account's access from inside the resource. The same applies to Token Creator, and to delegation chains, where a low-privilege account that may impersonate a higher-privilege one gains its access for that step. The rule: grant these roles on the specific accounts a person or pipeline genuinely needs, never on the project, and review who holds them on highly privileged accounts. Whoever can act as an identity effectively holds that identity's access.
Why service account keys are dangerous
A service account key is a downloadable JSON credential containing a private key that authenticates as the account from anywhere, so it is the option of last resort. Keys are long-lived: a user-managed key has no expiry by default and stays valid until it is disabled or deleted. They are bearer credentials: anyone holding the file is the service account, from any machine. They leak easily through repositories, container images and CI logs. And use by a thief looks the same as legitimate use.
If you must create one, typically for third-party software that only accepts a key file, use gcloud iam service-accounts keys create key.json --iam-account=EMAIL; audit with keys list; revoke with keys disable or keys delete. Deleting a leaked key invalidates it immediately. Rotation means creating a new key, moving the consumer to it, then deleting the old one.
Organization policies enforce avoidance instead of trusting discipline:
constraints/iam.disableServiceAccountKeyCreationblocks creating keys.constraints/iam.disableServiceAccountKeyUploadblocks uploading your own public keys to service accounts.constraints/iam.serviceAccountKeyExpiryHoursgives keys a fixed lifetime counted from creation. It applies only to keys created after it is enforced (existing keys keep no expiry), and it is not an inactivity timeout.constraints/iam.serviceAccountKeyExposureResponsecontrols what happens when Google detects a key exposed publicly, for example pushed to a public repository. Since 16 June 2024, if you have not set it, Google disables the exposed key and notifies you, so a job using it starts failing with an authentication error. The response is to move the workload to a keyless method (or, if unavoidable, a new key) and investigate how it leaked.
Organizations created on or after 3 May 2024 are secure by default: key creation and key upload are blocked, and constraints/iam.automaticIamGrantsForDefaultServiceAccounts is enforced, so default service accounts are no longer automatically granted Editor. In such an organization, a VM created with every default runs as a default account with no project role, which is why reads that worked in an older organization fail with 403 there; grant a dedicated account the specific roles it needs. Older organizations can enforce the same constraints themselves.
The decision rule: workloads on Google Cloud use attached service accounts; humans and automation with a Google identity use impersonation; GKE pods use Workload Identity Federation for GKE; external workloads use Workload Identity Federation. A key is justified only when none of those paths exist.
Impersonation and short-lived credentials
Service account impersonation lets an authenticated principal obtain short-lived credentials as a service account without any key. The authorisation is split in two. The caller needs roles/iam.serviceAccountTokenCreator on the target account. The service account, not the caller, needs the roles on the resources being changed. So a team can run infrastructure tooling through a deployer service account while its members hold no direct permissions on the target project: the team's group gets Token Creator on the deployer account, and the deployer account gets the resource roles. If either half is missing, the call fails.
In gcloud, --impersonate-service-account=EMAIL runs one command as the account, and gcloud config set auth/impersonate_service_account EMAIL makes every following command use it until you unset it. Client libraries support impersonated credentials too.
The Service Account Credentials API issues three kinds of short-lived credential:
| Credential | Use it for | gcloud example |
|---|---|---|
| OAuth 2.0 access token | Calling Google APIs (Cloud Storage, Compute Engine, and so on) | gcloud auth print-access-token --impersonate-service-account=EMAIL |
| OpenID Connect ID token | Proving identity to a service that checks who you are, such as a private Cloud Run service or an IAP-protected app; the token names an audience (the target URL) | gcloud auth print-identity-token --impersonate-service-account=EMAIL --audiences=https://SERVICE_URL |
| Signed JWT or blob | Custom assertions signed with the account's Google-managed key | Credentials API signJwt / signBlob |
A private Cloud Run service checks that the identity in the ID token holds Cloud Run Invoker (roles/run.invoker). An ID token for your own user is rejected if your user lacks that role; when only a service account holds it, mint the ID token as that account with impersonation, which needs Token Creator on it. An access token is the wrong credential here, because it is meant for Google APIs, not for proving identity to your service.
Lifetimes. Access tokens last one hour by default, and one hour is also the maximum unless the organization policy constraints/iam.allowServiceAccountCredentialLifetimeExtension lists the service account; listed accounts can get access tokens of up to 12 hours (43,200 seconds). Short-lived credentials are not revoked like keys; they simply expire, so a stolen token is useful for minutes or hours, not months.
Why this replaces keys: instead of giving five engineers a JSON key each, grant their group Token Creator on the deployer account. They authenticate as themselves, mint hour-long tokens on demand, Cloud Audit Logs attribute every action to the human who impersonated, and offboarding is a group-membership change.
Workload Identity Federation for GKE: service accounts for GKE applications
Workload Identity Federation for GKE (formerly called simply Workload Identity) is Google's recommended way for GKE applications to get Google Cloud credentials without keys. Each pod runs as a Kubernetes service account (KSA), and GKE exchanges that KSA's token for short-lived Google Cloud credentials. The node's service account is shared by every pod on the node, and key files in pods bring back every key risk, so both are the wrong answer.
Enable it. Autopilot clusters always have it. On Standard, enable it on the cluster with gcloud container clusters update CLUSTER --workload-pool=PROJECT_ID.svc.id.goog, which gives the cluster the project's workload identity pool. Existing node pools are not converted: update each one with gcloud container node-pools update POOL --cluster=CLUSTER --workload-metadata=GKE_METADATA (new node pools get it automatically). Until you do, pods on the old pool keep calling Google APIs as the node's service account.
Grant access: the recommended method. Grant IAM roles directly to the KSA's principal identifier:
principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/KSA_NAME
Note the two different project identifiers: the projects/ segment takes the project number, while the pool name is the project ID followed by .svc.id.goog. No Google service account is involved.
Alternative: link to an IAM service account. Where a Google Cloud API does not yet accept federated principals, or you want to reuse an existing service account, create an IAM service account with the roles, grant roles/iam.workloadIdentityUser on it to serviceAccount:PROJECT_ID.svc.id.goog[NAMESPACE/KSA_NAME], and annotate the KSA with iam.gke.io/gcp-service-account=GSA_EMAIL. Pods using that KSA then act as the Google service account.
Either way, application code uses Application Default Credentials exactly as it would on a VM, credentials are short-lived and per workload, and audit logs name the right identity.
Workload Identity Federation and the authentication options compared
Workload Identity Federation extends the keyless model to workloads outside Google Cloud: CI/CD pipelines, on-premises services and applications on other clouds. Instead of exporting a key, you configure Google Cloud to trust tokens the external environment already issues.
- Workload identity pool (
gcloud iam workload-identity-pools create): a project-level container for external identities. - Provider: describes the external issuer: OIDC (which also covers Azure workloads through Microsoft Entra ID), SAML 2.0, AWS or X.509 certificates, and which audiences its tokens must carry.
- Attribute mapping: translates token claims into Google attributes, such as
google.subject=assertion.subandattribute.repository=assertion.repository. It shapes identities; it does not reject anyone. - Attribute condition: a CEL expression every token must satisfy, such as
assertion.repository == 'ORG/REPO'. This is what restricts which external workloads can federate. A shared issuer like GitHub Actions signs tokens for every GitHub user, so Google requires an attribute condition when you create a GitHub provider, and a narrower condition (a single repository or branch rather than a whole organization's owner claim) narrows trust.
The external workload exchanges its token through the Security Token Service for a federated token. It then either uses that token directly, with roles granted to principal:// or principalSet:// identifiers from the pool, or impersonates a service account you allow it to use.
Workload versus workforce pools. Workload identity pools are for software (a CI system, a service on another cloud). Workforce identity pools, created at the organization level, are for human users from an external identity provider who sign in to the console or gcloud. An external CI pipeline needs a workload identity pool. Workforce Identity Federation belongs to identity management for users rather than service accounts.
| Option | Where the workload runs | Credential lifetime | Standing secret? | Use when |
|---|---|---|---|---|
| Attached service account | On Google Cloud (Compute Engine, Cloud Run) | Short-lived tokens, auto-refreshed | No | Always, for workloads on Google Cloud compute |
| Workload Identity Federation for GKE | GKE pods | Short-lived, per workload | No | Any GKE application needing Google Cloud APIs |
| Impersonation / short-lived credentials | Anywhere the caller already has a Google identity | One hour by default (up to 12 with the extension policy) | No | Humans and automation temporarily acting as a service account |
| Workload Identity Federation | Outside Google Cloud (other clouds, CI/CD, on-premises) | Short-lived, exchanged per run | No | External workloads with an OIDC, SAML, AWS or X.509 identity |
| Service account keys | Anywhere | No expiry by default | Yes | Last resort only, when no other path exists |
Example: a CI system outside Google Cloud must deploy to Cloud Run on every merge. The old answer was a service account key stored in the CI platform's secrets, a long-lived production credential in a third-party system. The federated answer creates a pool and an OIDC provider for the CI platform's issuer, with an attribute condition so only your pipeline qualifies, and lets the pipeline impersonate the deployer service account for minutes at a time.
Tip. Expect ranking questions where service account keys are the wrong answer and the right option depends on where the workload runs: attached account, impersonation, Workload Identity Federation for GKE or Workload Identity Federation. Know the roles on a service account by name (User, Token Creator, Creator, Admin, Key Admin) and why project-level grants enable escalation. Scenarios also probe access scopes versus IAM, changing a VM's account, Cloud Run's default identity, service agents and CMEK, undeleting accounts, the secure-by-default organization policies for keys and default grants, ID tokens versus access tokens, the principal:// identifier and node pool metadata for GKE, and attribute conditions for federation.
- Three kinds of service account: Google-managed service agents (service-PROJECT_NUMBER@gcp-sa-SERVICE…), default accounts such as the Compute Engine default, and user-managed accounts you create per workload
- Service agents created on request get no roles; grant what the service needs, such as Cloud KMS CryptoKey Encrypter/Decrypter to the Cloud Storage service agent for CMEK
- Grant service accounts minimum roles at the resource level, one account per workload; attaching an account across projects is blocked by iam.disableCrossProjectServiceAccountUsage on the account's project
- Disable before deleting; a deleted account can be undeleted by numeric unique ID within 30 days with its roles; a recreated same-name account is a new identity with no roles and blocks the undelete until you delete it
- Access scopes intersect with IAM roles; gcloud without --scopes applies the defaults (read-only Storage), and changing scopes or the account needs a stopped VM and set-service-account
- Service Account User attaches, Token Creator impersonates, Creator only creates, Admin manages lifecycle and policy, Key Admin manages keys; project-level grants cover every account and enable escalation
- Keys have no expiry by default; orgs created from 3 May 2024 block key creation/upload and default Editor grants, keyExpiryHours affects only new keys, and exposed keys are disabled automatically
- Impersonation needs Token Creator for the caller and resource roles for the account; use access tokens for Google APIs and ID tokens with an audience for private Cloud Run; lifetimes beyond 1 hour (up to 12) need an org policy
- Workload Identity Federation for GKE grants roles to the KSA principal:// identifier (project number, PROJECT_ID.svc.id.goog pool) or links a GSA; old node pools need --workload-metadata=GKE_METADATA
- Workload Identity Federation trusts external OIDC/SAML tokens; attribute conditions restrict who can federate; workforce pools are for humans, workload pools for software
Frequently asked questions
What is the difference between service agents, default service accounts and user-managed service accounts?
Service agents are Google-managed accounts, usually named service-PROJECT_NUMBER@gcp-sa-SERVICE.iam.gserviceaccount.com, that Google services use to act on resources in your project; you never hold their credentials and only adjust their roles when a feature needs it. Default service accounts, such as the Compute Engine default PROJECT_NUMBER-compute@developer.gserviceaccount.com, are created when a service is enabled and were historically granted Editor. User-managed accounts are the ones you create per workload with gcloud iam service-accounts create.
Why are service account keys considered a security risk?
A key is a downloadable private key that authenticates as the service account from any machine, and it has no expiry by default. Keys leak through repositories, images and logs, and a thief's use looks legitimate. Block them with iam.disableServiceAccountKeyCreation and iam.disableServiceAccountKeyUpload (enforced by default in organizations created from 3 May 2024), and use attached accounts, impersonation or Workload Identity Federation instead. Google also disables keys it detects exposed publicly by default.
What role do I need to impersonate a service account?
roles/iam.serviceAccountTokenCreator on the target service account, which lets you mint access tokens, ID tokens and signed JWTs as it, for example with gcloud --impersonate-service-account. The service account itself, not you, needs the roles on the resources you change. Grant Token Creator on the individual account rather than the project, because a project-level grant covers every service account in the project. Service Account User is different: it lets you attach the account to resources.
Can I restore a service account that was deleted by mistake?
Yes, within 30 days. If a new account with the same name now exists, delete it first, because it blocks the undelete while it exists. Run gcloud beta iam service-accounts undelete with the account's numeric unique ID (found in the deletion audit log entry). The restored account is the same identity and its role bindings work again. Creating a new account with the same name instead gives a different identity with none of the old roles.
Why does my VM get 403 errors writing to Cloud Storage even though its service account has the right role?
Usually its access scopes. Effective access is the intersection of the VM's scopes and the account's IAM roles, and the default scopes allow only read-only Cloud Storage. gcloud compute instances create applies those defaults whenever --scopes is omitted, even with a user-managed service account. Stop the VM, run gcloud compute instances set-service-account with --scopes=cloud-platform, start it, and let IAM roles control access.
How does Workload Identity Federation for GKE work?
GKE exchanges a pod's Kubernetes service account token for short-lived Google Cloud credentials. Enable it with --workload-pool=PROJECT_ID.svc.id.goog and make sure node pools use --workload-metadata=GKE_METADATA. Google recommends granting roles directly to principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/KSA_NAME. Alternatively, grant roles/iam.workloadIdentityUser on an IAM service account to the KSA and annotate the KSA with iam.gke.io/gcp-service-account.
When should I use Workload Identity Federation instead of a service account key?
Whenever a workload outside Google Cloud, such as a CI/CD pipeline, an on-premises service or an application on another cloud, has an identity it can prove: OIDC or SAML tokens, AWS credentials, or X.509 certificates (Azure workloads federate through OIDC). You create a workload identity pool and provider, and an attribute condition restricts which external identities may federate. The workload exchanges its own token for short-lived Google Cloud credentials, so no long-lived key ever leaves Google Cloud.
How do I get a token that lasts longer than one hour?
Access tokens from the Service Account Credentials API last at most one hour unless the organization policy constraint iam.allowServiceAccountCredentialLifetimeExtension lists the service account. For listed accounts you can request a lifetime of up to 12 hours (43,200 seconds). Prefer refreshing tokens where possible, because a longer lifetime also lengthens the window in which a stolen token works.
Source
This lesson covers the "Configuring access and security" domain of the official ACE exam guide. Vendors revise their guides — check the source for the current version.
- Google Cloud Associate Cloud Engineer exam guide — Google Cloud
Sign up free to mark lessons complete, bookmark topics and track your exam readiness.