Prepare and test your skills

Prepare and test your skills

Viewing and auditing IAM policies across resources means checking who can do what on which Google Cloud resources and whether that access is safe and compliant. Identity and Access Management (IAM) (opens in a new tab) allow policies attach to a project, folder, or organization and contain role bindings that grant permissions to principals such as users, service accounts, groups, and domains. Auditing requires looking at both the policy on one resource and the policies inherited from its ancestors, because effective access is the combination of both.
The Google Cloud console IAM page shows who has access to a selected project, folder, or organization in list form rather than showing the raw allow policy. The console list includes principals who inherit roles from parent resources, so it gives a more complete view than a single policy file. To see role grants for Google-managed service agents, select the Include Google-provided role grants checkbox.
To view current access in the console, first open the IAM page and select a project, folder, or organization. Then review the table of principals and roles, remembering that inherited roles cannot be edited at the child level and must be changed at the resource where they were granted. If an email alias or secondary domain was granted access, the console displays the primary email address or primary domain.
The gcloud CLI get-iam-policy command retrieves the allow policy for one specific project, folder, or organization. A policy retrieved this way does not include inherited roles, so it shows only direct grants on that resource. To see inherited access, use the console or review the effective allow policy across ancestors.
Viewing a policy requires a getIamPolicy permission on that level, while changing it requires the matching setIamPolicy permission:
resourcemanager.projects.getIamPolicy and resourcemanager.projects.setIamPolicyresourcemanager.folders.getIamPolicy and resourcemanager.folders.setIamPolicyresourcemanager.organizations.getIamPolicy and resourcemanager.organizations.setIamPolicyThe command has the form gcloud RESOURCE_TYPE get-iam-policy RESOURCE_ID --format=FORMAT > PATH, where FORMAT is json or yaml and PATH is the output file. For example, gcloud projects get-iam-policy my-project --format=json > ~/policy.json saves the direct allow policy for the project my-project to the home directory. The resource type and ID depend on the level being viewed:
| Level | Resource type value | ID format |
|---|---|---|
| Project | projects | Alphanumeric, like my-project |
| Folder | resource-manager folders | Numeric, like 123456789012 |
| Organization | organizations | Numeric, like 123456789012 |
Exam tip: The console IAM list includes inherited roles, while gcloud get-iam-policy shows only the direct policy on that resource.
Policy Analyzer is the auditing tool that verifies which principals have what access to which resources across the organization hierarchy. Policy Analyzer helps answer compliance and security questions about current access, including reviews of former employees, sensitive data, and privileged roles. It can be used in the Google Cloud console, through APIs, or by exporting IAM policy data to BigQuery for asynchronous analysis.
Policy Analyzer can answer questions such as:
To certify access for one user with Policy Analyzer, follow an ordered workflow where each step depends on the previous one:
cloudasset.googleapis.com for the project, because Policy Analyzer depends on the Cloud Asset API.gcloud asset analyze-iam-policy --organization="YOUR_ORG_ID" --identity="user:USERNAME_TO_CERTIFY", replacing the organization ID and username.Cloud Audit Logs and Activity logs record how IAM access changes over time and support security and compliance reviews. Changes to Google group membership are tracked in Activity logs, while creation of service accounts and service account keys appears in audit logs with method names such as google.iam.admin.v1.CreateServiceAccount and google.iam.admin.v1.CreateServiceAccountKey. Filtering logs by project and method name shows who created privileged identities and when.
Privileged access should be temporary, justified, and reviewed rather than permanently granted. Just-in-time privileged access with Privileged Access Manager (PAM) lets principals request elevated access only when needed, creates an audit trail for why privileges were activated, and supports expiration or periodic review. Administrators review Cloud Audit Logs to analyze privileged access requests and detect anomalies, export logs to retain them for audit purposes, and require 2-step verification for all users with privileged access.
Interpreting IAM policy structure and inheritance means understanding how role bindings grant access and how parent policies flow down the resource hierarchy. Identity and Access Management (IAM) (opens in a new tab) checks permissions before it allows an action to proceed, and every action requires specific permissions. An allow policy, formerly called an IAM policy, is the object that grants access by attaching role bindings to a resource.
An allow policy is a YAML or JSON object that is attached directly to a Google Cloud resource. The allow policy contains a list of role bindings, and each role binding associates one IAM role with one or more principals. A principal is an authenticated identity such as a user, Google group, service account, or federated identity, while a role is a collection of permissions in the form service.resource.verb.
Access is granted through three connected parts:
roles/pubsub.publisher)When an authenticated principal tries to access a resource, IAM checks the resource's allow policy for a binding that includes both the principal and a role with the required permission. If that binding exists in the resource policy or in an inherited ancestor policy, the request is allowed. Permissions cannot be granted directly, so a principal only receives permissions by being included in a role binding.
The resource hierarchy is the parent-child organization of container resources that allows policies to be inherited. Container resources group other resources so one policy grant can cover many descendants, including resources that cannot have their own allow policies. The hierarchy flows from the broadest container at the top to individual service resources at the bottom.
The hierarchy levels are:
Granting a role on a container gives the principal access to both the container and the resources inside it. For example, granting Security Admin (roles/iam.securityAdmin) on the organization lets a security administrator manage allow policies throughout that organization.
Policy inheritance means that an allow policy set on a parent container also applies to every descendant resource in that container. The effective permissions for a resource are the union of the policy attached to that resource and all policies inherited from its parent project, folders, and organization. A child policy therefore adds access but does not remove access granted higher in the hierarchy.
A hierarchy tree showing how allow policies flow from the organization through folders and projects to service resources. The effective policy of a resource is the union of its own policy and all inherited ancestor policies.
This inheritance creates three practical results for access design. A single role binding on a folder or organization can grant access to many projects and resources at once. A principal can gain access to a resource that has no policy of its own, such as granting Logs Bucket Writer (roles/logging.bucketWriter) on a project to allow writing to a log bucket inside it. And a project-level grant, such as Compute Engine VM administration, applies to every VM in that project regardless of the policy set on each VM.
Because access is aggregated upward, least privilege requires granting roles at the smallest scope needed. Grant Publisher only on the specific Pub/Sub topic when only that topic is needed, and move the grant to the folder level only when the same access must span multiple projects.
A resource's effective access cannot be understood from its own policy alone because ancestor policies also apply. To see complete access, the policies of the resource plus its parent project, folders, and organization must all be reviewed. Viewing those inherited policies requires getIamPolicy permission on each ancestor, such as resourcemanager.organizations.getIamPolicy on the organization, resourcemanager.folders.getIamPolicy on the folder, and resourcemanager.projects.getIamPolicy on the project.
Exam tip: In the Google Cloud console, a resource's IAM page shows an inherited role only if that role is grantable on the resource being viewed.
Creating and modifying IAM policies using best practices means granting the smallest role at the smallest scope and checking the result across the hierarchy. Identity and Access Management (IAM) (opens in a new tab) allow policies, formerly called IAM policies, are how access is granted to Google Cloud resources. An allow policy is a YAML or JSON object attached to a resource that contains a list of role bindings, and each role binding connects a principal, a role, and a resource.
IAM roles fall into three types that differ in who manages them and how much access they give. Permissions cannot be granted directly to a principal, so a principal only gets permissions by being granted a role that contains them. Choosing the smallest role that still lets the work get done is the core of least privilege.
| Role type | Who manages permissions | Choose when |
|---|---|---|
| Predefined roles | Google Cloud manages the permission set for each service, such as Pub/Sub Publisher (roles/pubsub.publisher) | The work matches a common task and a predefined role covers only the needed permissions |
| Custom roles | You create the role with only the permissions you list | No predefined role fits, and you accept higher maintenance and limits on how many custom roles a project or organization can have |
| Basic roles | Google Cloud provides highly permissive broad access, including Owner (roles/owner) | You need broad access for testing or development, but not for production environments |
Policy inheritance means an allow policy set on a container resource also applies to all resources inside that container. The Google Cloud resource hierarchy flows from the organization at the root, to folders that are children of the organization or another folder, to projects that are children of the organization or a folder, to service resources that are descendants of projects. A role granted on a parent therefore flows down to the parent itself and to every child and descendant.
This inheritance creates three practical effects for access design. First, a single binding on a container can grant access to many resources, such as granting Security Admin (roles/iam.securityAdmin) on the organization to manage policies everywhere. Second, resources that cannot have their own allow policies, such as log buckets, can still be accessed through a grant on an ancestor, such as granting Logs Bucket Writer (roles/logging.bucketWriter) on the containing project. Third, to know who can access a resource you must view all policies that affect it, including the resource policy plus the project, folder, and organization policies above it.
Exam tip: A project-level grant to administer Compute Engine virtual machine (VM) instances applies to every VM in that project, even if an individual VM has a more restrictive policy.
Managing access to a resource means viewing its current allow policy, then granting, changing, or revoking role bindings with the Google Cloud console, Google Cloud CLI (gcloud), or REST API. Viewing by members in the console shows which roles each principal has, while viewing by roles shows which principals have each role. Single-role changes in the console use Grant Access for a new principal or Edit principal plus Add another role for an existing principal, with an optional condition, then Save.
Programmatic changes to resources that accept allow policies follow the same ordered workflow:
getIamPolicy operation, such as gcloud beta projects get-iam-policy.setIamPolicy operation, while quick single grants can use add-iam-policy-binding and removals can use remove-iam-policy-binding.Managing a policy requires permission to get the resource and to get and set its policy, in the form SERVICE.RESOURCE_TYPE.get, SERVICE.RESOURCE_TYPE.getIamPolicy, and SERVICE.RESOURCE_TYPE.setIamPolicy. For example, Compute Engine instances require compute.instances.get, compute.instances.getIamPolicy, and compute.instances.setIamPolicy, while inherited policies require resourcemanager.organizations.getIamPolicy, resourcemanager.folders.getIamPolicy, or resourcemanager.projects.getIamPolicy on the parent. Administrators often grant a role such as Security Admin (roles/iam.securityAdmin) to provide these management permissions across almost all resources.
Least-privilege best practices keep new policies small, reviewable, and aligned to how the business is organized. The resource hierarchy should mirror the organization structure, with projects grouping resources that share the same trust boundary such as one product or microservice. Roles should be granted at the smallest scope needed, so a user who only publishes to one Pub/Sub topic gets Publisher on that topic rather than on the whole project.
roles/owner) on every project, or grant Owner to a group with at least two principals, so the project stays manageable if one person leaves.Assessing impact means checking the effective access created by a new or edited policy across the hierarchy before and after the change. The console IAM page shows direct grants, but inherited roles appear only if they are grantable on that resource, so parent project, folder, and organization policies must also be reviewed. Policy Analyzer can query which principals have a role or permission on a resource, what access a principal has, and which resources a principal can reach, while Policy Troubleshooter checks a specific principal, resource, and permission against allow policies, deny policies, and Principal Access Boundary policies.
Auditing and timing also affect how changes are understood. Audit logs record every setIamPolicy() call, so creation and modification of allow policies can be traced for compliance review. Revoking access typically takes effect in about a minute, although the change appears in metadata immediately and a user may retain access for a short period in some cases.
get-iam-policy command shows only direct grants on the requested resource.setIamPolicy() calls and service account creation for compliance review.The Google Cloud console Identity and Access Management (IAM) page shows who has access including principals who inherit roles from parent resources, while the get-iam-policy command retrieves only the direct allow policy for one specific project, folder, or organization. To see inherited access from the command output you must also review the effective allow policy across ancestors, and inherited roles cannot be edited at the child level but must be changed at the resource where they were granted.
Effective permissions are the union of the allow policy attached to the resource and all allow policies inherited from its parent project, folders, and organization. A child policy adds access but does not remove access granted higher in the hierarchy, so a single binding on a folder or organization can grant access to many projects and resources at once.
Use predefined roles managed by Google Cloud when the work matches a common task and the role covers only the needed permissions, and use custom roles you create when no predefined role fits. Use basic roles such as Owner only for broad access for testing or development and not for production environments, because choosing the smallest role that still lets the work get done is the core of least privilege.
Policy Analyzer verifies which principals have what access to which resources across the organization hierarchy and can answer what roles or permissions a principal has, which resources a principal can access, and which principals have a certain level of access to a resource. Auditing follows enabling the Cloud Asset API for the project, running the analysis for the organization and identity to certify, and writing the results to BigQuery when the result set is large or needs periodic compliance review.
Your organization has a production Google Cloud project named prod-backend. A software developer, dev-lead@example.com, needs to deploy, configure, and manage Cloud Run services within this project.
Company security policy mandates strict adherence to the principle of least privilege in production environments, specifically requiring:
Which gcloud command should you run to grant the appropriate access?
gcloud projects add-iam-policy-binding prod-backend --member="user:dev-lead@example.com" --role="roles/editor"
gcloud projects add-iam-policy-binding prod-backend --member="user:dev-lead@example.com" --role="roles/run.viewer"
gcloud projects add-iam-policy-binding prod-backend --member="user:dev-lead@example.com" --role="roles/run.admin"
gcloud projects add-iam-policy-binding prod-backend --member="user:dev-lead@example.com" --role="roles/run.developer"
Last updated