Prepare and test your skills

Prepare and test your skills

Understanding service account purpose and scope means knowing which identity a workload uses and where that identity is allowed to act. A service account (opens in a new tab) is an identity for an application, virtual machine, or automated process, and its access is controlled by Identity and Access Management (IAM) (opens in a new tab). The scope of a service account is the resource where its role is granted plus any child resources that inherit that grant.
A service account is a workload principal that lets code and Google Cloud resources authenticate and act without a human signing in. Every access request follows the same relationship: a principal requests an operation on a resource, Identity and Access Management (IAM) checks whether an allow policy grants that principal a role with the required permission, and IAM allows the action only when the permission is present. To give access, an administrator binds the service account to a role on a resource, and the service account can then use all permissions in that role on that resource.
Service account permissions come from roles, which differ in breadth and maintenance:
In production, grant only the most limited predefined role or custom role that meets the workload need and reserve basic roles for test or development.
Service accounts represent workloads while user accounts represent people, and Identity and Access Management (IAM) separates principals into those two categories. Human-user principals include Google Accounts, Google groups, and federated identities in workforce identity pools. Workload principals include service accounts and federated identities in workload identity pools.
| Principal type | Represents | Used for |
|---|---|---|
| User account principals | Human users, groups, and workforce federated identities | Employee access to Google Cloud resources |
| Service accounts | Applications, virtual machines, and automated workloads | Workload access to Google Cloud resources without human sign-in |
A service account authenticates as its own identity, so permissions flow to the workload itself rather than to the person who deployed it. A separate control governs who can use that identity: users granted the Service Account User role (roles/iam.serviceAccountUser) for a service account can access all resources to which that service account has access. Because impersonation extends the full reach of the service account, access to act as service accounts must be tightly limited.
Scope in Identity and Access Management (IAM) is the resource level where a role is granted, and it determines how broadly a service account can act. Google Cloud resources are organized in a hierarchy where organization, folder, and project containers hold service-specific resources such as Compute Engine instances, disks, and Pub/Sub topics. Allow policies on child resources inherit from allow policies on their parent resources, so granting a role on a project implicitly grants it on every virtual machine (VM) in that project.
Least privilege narrows scope by granting roles at the smallest level that still lets the workload function:
Granting access at a lower level limits blast radius when credentials or code are compromised. For example, a service account that can administer one Compute Engine VM cannot administer other VMs in the same project unless it also holds a broader project-level grant.
Exam tip: Granting a role on a parent container grants access to all of its children, so choose a resource-level grant when the workload needs access to only one topic, instance, or other child resource.
Least privilege in Identity and Access Management (IAM) means giving a principal such as a service account only the permissions it needs to do its job and nothing more. Access is granted by creating a role binding in an allow policy, which attaches a role containing permissions to a principal on a specific resource. Applying least privilege therefore requires identifying the exact permissions needed, choosing the smallest role that contains them, and granting that role at the lowest resource level that still works.
Identifying required permissions is the starting point for least-privilege configuration because focusing on high-risk permissions narrows the list of roles to consider. Especially powerful permissions deserve extra review because they can affect many resources or sensitive data. Less powerful permissions carry limited risk and are safer to include in a workload role.
Powerful permissions include:
Less powerful permissions include:
Predefined roles (opens in a new tab) are Google-maintained roles that give granular access for a specific service and are updated automatically when Google Cloud adds features or services. After identifying required permissions, search the IAM roles and permissions index for each permission name to see which predefined roles contain it and build a short list of candidates. For workloads that use more than one service, expect to combine roles, such as one role for viewing Cloud Storage objects and another for administering Cloud SQL databases, rather than using one broad role with many unrelated permissions.
Choosing the most appropriate predefined roles means first eliminating roles that are too broad for production use. Do not grant basic roles such as Owner (roles/owner), Editor (roles/editor), and Viewer (roles/viewer) in production because they include thousands of permissions across all Google Cloud services. Also eliminate service agent roles, whose titles end in "Service Agent" and whose names end in serviceAgent, because they are intended for Google-managed service agents and often span services the workload does not need. Then use the predefined roles reference or the Roles page in the Google Cloud console to compare permissions in each remaining role, preferring service-level Admin, Editor, and Viewer roles that cover the likely use case, or the role with the fewest permissions for strict least privilege.
Custom roles (opens in a new tab) are user-defined bundles of supported IAM permissions that help enforce least privilege when no predefined role fits. Create a custom role when every predefined role that contains a needed permission also contains unwanted permissions the service account should not have, or when a role recommendation suggests creating one to replace an overly permissive grant. A custom role is created in an organization or project and can only be granted inside that same organization or project, and custom roles cannot be defined at the folder level, so a folder use case requires an organization-level custom role.
Custom roles have concrete limits that affect planning:
Custom roles are not maintained by Google, so they do not gain new permissions automatically, and some permissions have dependencies that must be granted together. For example, updating an allow policy usually requires both the getIamPolicy permission to read the policy and the setIamPolicy permission to write it. Starting from a predefined role with similar permissions helps ensure those dependencies are included.
Every IAM grant applies to a specific resource in the Google Cloud resource hierarchy, where lower-level resources inherit allow policies from higher levels. The hierarchy flows from organization to folder to project to individual resources such as Compute Engine VM instances, Cloud Storage buckets, or Cloud SQL databases. Because a role granted on a project, folder, or organization is inherited by everything below it, granting too high in the hierarchy gives the service account access it does not need.
Choose the lowest-level resource that meets the workload needs to limit inheritance. Grant the role directly on specific lower-level resources when the workload needs only those resources, and grant on a project, folder, or organization only when the workload needs many resources inside it. IAM Conditions can further narrow a higher-level grant to only specific resources, and different roles can be granted at different levels, such as granting a Cloud SQL role on one database while granting a Compute Engine role on the project. This placement is especially important for default service accounts, which must not receive the Owner or Editor basic roles in production.
Exam tip: In production, do not grant basic roles such as Owner, Editor, or Viewer to a service account; grant the most limited predefined or custom role at the lowest resource level that allows the workload to run.
Granting roles to a principal creates the role binding that lets the service account use the permissions on the selected resource. After granting, use Policy Analyzer and Policy Troubleshooter to check which resources the service account can actually access and to diagnose denied requests. Use Policy Simulator to test the effect of changing a role before applying it, and review role recommendations that suggest a less permissive replacement when a grant is too broad. If the workload cannot complete its tasks, iterate by adding the missing permission to the required list, finding roles that contain it, and choosing the smallest fit again.
Secure management of service account keys and impersonation means giving workloads only the access they need while avoiding long-lived credentials whenever possible. In Identity and Access Management (IAM) (opens in a new tab), a service account is a workload identity that can be granted roles on resources, and another principal can use it either by holding its downloadable service account key or by impersonating it with short-lived credentials. Impersonation through Workload Identity Federation (opens in a new tab) is the preferred path because it removes the need to store and rotate a private key file.
Service account impersonation lets an authorized principal act as a service account without downloading its private key. The caller authenticates to Google Cloud first, then requests short-lived credentials for the target service account, and then data and requests flow from the caller through the service account to the target resource with only the service account permissions. Workload Identity Federation extends this model to identities outside Google Cloud, such as on-premises apps, Terraform running on another cloud, or platform integrations, by exchanging the external identity for short-lived Google Cloud credentials.
Use impersonation when the workload runs outside Google Cloud, when Terraform needs Application Default Credentials without a key file, or when an integration supports a workload identity email. The credential configuration file path is supplied through the GOOGLE_APPLICATION_CREDENTIALS environment variable, so no JSON private key is stored on the workstation. Choose a downloadable JSON key only when keyless authentication is not supported by the tool or environment.
| Authentication option | Credential type | Management burden |
|---|---|---|
| Workload Identity Federation with impersonation | Short-lived credentials issued after authentication | No long-lived key to store or rotate, recommended for external and cross-cloud use |
| Service account key in JSON format | Long-lived private key file | Owner must secure, rotate, validate, and clean up the key |
Exam tip: A principal granted the Service Account User role (roles/iam.serviceAccountUser) on a service account can access all resources that the service account can access, so restrict who can impersonate each service account.
Minimum permissions for service accounts means treating each application component as a separate trust boundary with its own service account and roles. A service account created for one service should receive only the predefined roles or custom roles it needs, at the smallest resource scope needed, such as Publisher on a single Pub/Sub topic rather than on the whole project. Because allow policies for child resources inherit from parent resources in the project, folder, and organization hierarchy, a role granted on a project flows down to every resource in that project.
Do not grant basic roles such as Owner, Editor, or Viewer in production because basic roles include thousands of permissions and allow privilege escalation and lateral movement. To change access safely, use role recommendations to find a narrower replacement and use the Policy Simulator to confirm the change will not break the workload. Control who can attach and use service accounts by granting roles/iam.serviceAccountUser only to specific principals and by limiting who can create and manage service accounts with roles such as Service Account Creator.
A service account key is a long-lived public and private key pair that authenticates as the service account wherever the private JSON file is present. The key file is a security risk if it is leaked, copied, or left unrotated because anyone holding the private key can act with all permissions granted to the service account. When keys cannot be avoided, limit which principals can create keys, store the private key securely, rotate it periodically, delete keys that are no longer needed, and validate any key obtained from an external source before use.
Secure handling depends on tight ownership and scope:
iam:GetAccountSummary when a tool requires it for initialization checks.If key creation is blocked, service account key creation may be disabled for the organization by a secure-by-default policy, which is an intentional control to force keyless authentication.
Restrictive policies reduce key and impersonation exposure while keeping operational access available through temporary and narrowly scoped grants. An organization policy can disable service account key creation entirely, which prevents new long-lived keys while existing workloads continue to use impersonation and federation. IAM conditional role bindings let access expire automatically, and temporary elevated access through Privileged Access Manager provides privileged rights only for the time and resources needed.
Prefer administrative roles that separate policy management from data access when broad control is needed. Granting Project IAM Admin and Folder IAM Admin allows a principal to modify allow policies without granting direct read, write, and administrative access to all resources, while granting Owner (roles/owner) allows access and modification of almost all resources including allow policies. Use the narrowest grant that meets the need, create backup administrator accounts so no single Organization Administrator creates a lockout risk, and review inherited project and folder policies before adding new bindings.
Service accounts are workload identities for applications, virtual machines, and automated processes that act without human sign-in, while user account principals represent people, groups, and workforce federated identities. Permissions granted to a service account flow to the workload itself, while a separate grant controls who can use that identity.
Grant the most limited predefined role or custom role at the lowest resource level that still lets the workload function, because a role granted on a parent organization, folder, or project is inherited by all child resources below it. For example, grant Publisher on one Pub/Sub topic rather than on the whole project, and do not grant basic roles such as Owner, Editor, or Viewer in production.
Use Workload Identity Federation with impersonation because it issues short-lived credentials after authentication and avoids storing or rotating a long-lived private key file. Choose a downloadable JSON service account key only when keyless authentication is not supported by the tool or environment.
A developer needs to run and test an application on a local workstation. The application requires specific Google Cloud permissions that are granted to a dedicated service account. The organization strictly enforces a security policy that prohibits downloading, storing, or managing persistent service account private key files (.json) on developer machines to prevent credential leakage.
Which approach should you implement to allow the developer to test the application securely?
Generate a user-managed service account key with an explicit expiration time of 8 hours, and download the key to the developer's workstation.
Assign the developer the Project Editor role (roles/editor) at the project level so their user account has broad permissions to perform the required actions directly.
Store a user-managed service account private key in Secret Manager and grant the developer the Secret Manager Secret Accessor role.
Assign the developer the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the service account and configure the application to use service account impersonation.
Last updated