Prepare and test your skills

Prepare and test your skills

Viewing and creating Identity and Access Management (IAM) policies means checking who can do what on Google Cloud resources and changing those grants safely. An Identity and Access Management (IAM) (opens in a new tab) allow policy, formerly called an IAM policy, is a YAML or JSON object attached to a resource that contains role bindings. Each role binding connects a principal, a role, and the resource where the policy is attached.
An allow policy grants access through three connected parts: principal, role, and resource. A principal is an authenticated identity such as a user, Google group, service account, or federated identity. A role is a collection of permissions in the form service.resource.verb, such as pubsub.topics.publish, and the resource is the project, folder, organization, or service resource the policy is attached to.
When a principal calls an API, IAM checks the allow policy on the target resource and on its ancestors. If a binding includes both the principal and a role with the required permission, the request is allowed. Permissions are never granted directly, so a principal receives permissions only by being included in a role binding. The resource hierarchy (opens in a new tab) flows from organization at the root, to folders, to projects, to service resources such as Compute Engine instances, Pub/Sub topics, and Cloud Storage buckets.
Policy inheritance means a grant on a parent also applies to every descendant. Effective permissions are the union of the resource policy plus all inherited parent policies, so a child policy adds access but never removes access granted higher up. For example, granting Logs Bucket Writer (roles/logging.bucketWriter) on a project allows writing to a log bucket inside it, even when the bucket has no policy of its own.
A top-down hierarchy from organization to folder to project to service resources showing that parent allow policies flow down and effective access is the union of all ancestors.
Viewing effective access means looking at both direct grants on a resource and inherited grants from its ancestors. The Google Cloud console IAM page shows effective access in list form for a selected project, folder, or organization, including principals who inherit roles from parents. To see role grants for Google-managed service agents, select the Include Google-provided role grants checkbox.
The gcloud CLI get-iam-policy command shows only the direct policy on one resource, not inherited roles. The command has the form gcloud RESOURCE_TYPE get-iam-policy RESOURCE_ID --format=FORMAT > PATH, where FORMAT is json or yaml. For example, gcloud projects get-iam-policy my-project --format=json > ~/policy.json saves the direct policy for my-project. Viewing requires getIamPolicy permission and changing requires setIamPolicy permission at the same level, such as resourcemanager.projects.getIamPolicy and resourcemanager.projects.setIamPolicy.
| Level | Resource type value | ID format |
|---|---|---|
| Project | projects | Alphanumeric, like my-project |
| Folder | resource-manager folders | Numeric, like 123456789012 |
| Organization | organizations | Numeric, like 123456789012 |
Inherited roles cannot be edited at the child level and must be changed where they were granted. To see complete access, review the resource policy plus the parent project, folder, and organization policies, which requires getIamPolicy on each ancestor. In the console, an inherited role appears on a resource page only if that role is grantable on the resource being viewed.
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 hierarchy. Policy Analyzer depends on the Cloud Asset API, so analysis starts by enabling cloudasset.googleapis.com. It can be used in the console, through APIs, or by exporting results to BigQuery for large or periodic compliance reviews.
Policy Analyzer answers questions such as:
To certify access for one user, follow an ordered workflow:
cloudasset.googleapis.com for the project because Policy Analyzer depends on it.gcloud asset analyze-iam-policy --organization="YOUR_ORG_ID" --identity="user:USERNAME_TO_CERTIFY".Cloud Audit Logs record how access changes over time and support compliance review. Every setIamPolicy() call is logged, group membership changes appear in Activity logs, and service account creation appears with methods such as google.iam.admin.v1.CreateServiceAccount and google.iam.admin.v1.CreateServiceAccountKey. Just-in-time privileged access with Privileged Access Manager (PAM) (opens in a new tab) lets principals request elevated access only when needed, creates an audit trail for why access was activated, and supports expiration and periodic review. Revoking access typically takes effect in about a minute, although metadata updates appear immediately.
Continue with this study guide: Viewing and creating IAM policies
Managing IAM role types means choosing the smallest role at the smallest scope that still lets the work succeed. Identity and Access Management (IAM) roles (opens in a new tab) are collections of permissions granted to principals such as users, groups, and service accounts through the allow policy on a resource. When a principal holds multiple roles, effective permissions are the union of all permissions, so adding a role never removes access.
Basic, predefined, and custom roles differ in breadth of access, who manages them, and when to choose them. Basic roles grant broad access across many Google Cloud resources, such as Owner (roles/owner), and do not follow least privilege. Predefined roles are granular roles managed by Google Cloud for a specific service and job, such as Pub/Sub Publisher (roles/pubsub.publisher). Custom roles (opens in a new tab) are granular roles you define with only the permissions you list.
| Role type | Who defines permissions | Scope of access |
|---|---|---|
| Basic roles | Google Cloud | Broad access across many Google Cloud resources |
| Predefined roles | Google Cloud | Granular access for a specific service and common use case |
| Custom roles | You, from a user-specified permission list | Tailored access limited to the organization or project where created |
Predefined roles are preferred when one matches the task because Google Cloud maintains them and can add new permissions as services grow. Custom roles are useful when predefined roles are too broad, too narrow, or must stay unchanged over time, because Google Cloud does not automatically add permissions to a custom role. Basic roles are useful for testing or development but should not be used in production unless there is no alternative.
A custom role definition is the set of fields that identify the role, describe its purpose, and control its behavior. The title is the human-readable name in the console, the name is the full identifier used in allow policies such as projects/PROJECT_ID/roles/IDENTIFIER, and the ID is the unique part after roles/ that cannot be changed after creation.
roles/ in the name, which is immutable after creation.SERVICE.RESOURCE.VERB format.Selecting permissions for least privilege means using only permissions supported in custom roles and valid at the role scope. An organization-level custom role can include any supported permission, while a project-level custom role cannot include permissions that only work at organization or folder level, such as resourcemanager.organizations.get. Each custom role can contain up to 3,000 permissions, and the combined size of title, description, and permission names cannot exceed 64 KB. A custom role can only be granted within the same organization or project where it was created.
To create a custom role from scratch in the console:
Managing project roles requires Role Administrator (roles/iam.roleAdmin) on that project, while managing organization roles requires Organization Role Administrator (roles/iam.organizationRoleAdmin). A custom role can also start from a predefined role, and permissions that are deprecated or not permitted in custom roles are omitted automatically.
Exam tip: Custom roles cannot be defined at the folder level — to use a custom role within a folder, define the custom role at the organization level.
Granting roles with least privilege means placing each grant at the lowest resource level that still lets the workload succeed. A role granted on an organization, folder, or project is inherited by all descendant resources, while a grant on a service resource such as one dataset, table, topic, or virtual machine (VM) instance limits access to only that resource. For example, a BigQuery role granted on a project reaches all BigQuery resources in that project, but the same role granted on one dataset reaches only that dataset.
Programmatic changes to allow policies follow an ordered workflow where each step depends on the previous one:
getIamPolicy operation.setIamPolicy operation, while quick single grants can use add-iam-policy-binding and removals can use remove-iam-policy-binding.Managing a policy requires get, getIamPolicy, and setIamPolicy permissions for that resource type, such as compute.instances.get, compute.instances.getIamPolicy, and compute.instances.setIamPolicy. Security Admin (roles/iam.securityAdmin) provides these management permissions across almost all resources. Before granting, verify the role contains the required permission in the console, with gcloud iam roles describe, or with the IAM API.
Least-privilege grants follow practical rules that keep access small and reviewable:
get-iam-policy command shows only direct grants on the requested resource.The Google Cloud console IAM list shows effective access including inherited roles from parent projects, folders, and organizations, while the gcloud get-iam-policy operation shows only the direct policy attached to the requested resource. Inherited roles cannot be edited at the child level and must be changed where they were granted, so a complete access review requires checking the resource policy plus its parent project, folder, and organization policies.
Use a custom role when predefined roles are too broad, too narrow, or must stay unchanged over time because Google Cloud does not automatically add permissions to a custom role. A predefined role is preferred when one matches the task because Google Cloud maintains it and can add new permissions as services grow. Basic roles grant broad access across many Google Cloud resources and are useful for testing or development but should not be used in production unless there is no alternative.
Custom roles can be created at the organization level or the project level and cannot be defined at the folder level, so to use a custom role within a folder you define it at the organization level. A custom role can only be granted within the same organization or project where it was created.
Effective permissions are the union of the resource allow policy plus all allow policies inherited from its parent project, folders, and organization, so a grant on a parent also applies to every descendant. A child policy adds access but never removes access granted higher up, and a principal receives permissions only by being included in a role binding on the resource or an ancestor.
Last updated