Topic 1 of 3
Exam section 4.1 covers managing IAM: viewing and changing policies, understanding inheritance in the resource hierarchy, choosing between basic, predefined, and custom roles, and applying least privilege.
Contents
IAM controls who can do what on which resource. To give access, you grant a role to a principal on a resource. Permissions are never granted directly: they always come inside roles.
Principal
People: Google Accounts, Google groups, and federated identities in workforce pools. Workloads: service accounts and identities in workload identity pools. Previously called "members".
Role
A set of permissions in the form service.resource.verb, for example resourcemanager.projects.list.
Resource
A service resource (VM, bucket, topic) or a container: project, folder, or organization.
An allow policy (formerly "IAM policy") is a JSON or YAML object attached to a resource with a list of role bindings: each one ties a role to the principals who hold it.
{
"bindings": [
{ "role": "roles/storage.objectViewer",
"members": ["group:analysts@example.com"] },
{ "role": "roles/compute.instanceAdmin.v1",
"members": ["user:ana@example.com"],
"condition": { "title": "until-dec",
"expression": "request.time < timestamp('2026-12-31T00:00:00Z')" } }
],
"etag": "BwUjMhCsNvY=",
"version": 3
}condition field (2 is internal).An allow policy on a container applies to that container and everything below it: organization → folders → projects → resources. A resource's effective policy is the union of its own policy and those of all its ancestors: a binding at any level is enough to grant access.
| Type | Detail |
|---|---|
| Basic | Highly permissive, with thousands of permissions across all services. Google says not to use them in production unless there's no alternative |
| Predefined | Created and maintained by Google for specific tasks in each service; updated automatically when features are added. E.g. roles/pubsub.publisher |
| Custom | You create them with the exact permissions. They help with least privilege, but maintenance is on you |
Basic roles (preview)
roles/reader: read-only actions.roles/writer: Reader plus actions that modify state.roles/admin: Writer plus sensitive tasks, such as managing roles and permissions or setting up billing.Legacy basic roles
roles/viewer, roles/editor, and roles/owner, which predate IAM (formerly "primitive").SUPPORTED, TESTING, or NOT_SUPPORTED level.getIamPolicy as well as setIamPolicy. Starting from a predefined role helps.ALPHA, BETA, GA, DEPRECATED. With DISABLED the role stays in policies but has no effect.gcloud iam roles create vmOperator --project=my-project \ --title="VM Operator" --description="Start and stop VMs" \ --permissions="compute.instances.get,compute.instances.list,compute.instances.start,compute.instances.stop" \ --stage=GA gcloud iam roles create orgAuditor --organization=123456789012 --file=role.yaml gcloud iam roles update vmOperator --project=my-project --stage=DISABLED gcloud iam roles delete vmOperator --project=my-project gcloud iam roles undelete vmOperator --project=my-project
# Grant or remove a role (one-off change) gcloud projects add-iam-policy-binding my-project \ --member=group:devs@example.com --role=roles/compute.viewer gcloud projects remove-iam-policy-binding my-project \ --member=group:devs@example.com --role=roles/compute.viewer # Bulk changes: read, modify, write gcloud projects get-iam-policy my-project --format=json > policy.json gcloud projects set-iam-policy my-project policy.json
user:, group:, serviceAccount:, domain:.set-iam-policy overwrites the whole policy. Always follow the read-modify-write pattern so you don't drop bindings by accident; the etag rejects the write if someone else changed it in between.gcloud resource-manager folders), organizations, and individual resources.Attribute-based access control: the binding only grants the role if the expression, written in a subset of CEL (Common Expression Language), is true. Useful, for example, for temporary access or access limited to resources with a certain name. They're also used in deny rules and Principal Access Boundary.
request.time < timestamp('2026-12-31T00:00:00Z')
resource.name.startsWith('projects/_/buckets/exampleco-site-assets/')allUsers or allAuthenticatedUsers.Deny policies
exceptionPrincipals, exceptionPermissions).Principal Access Boundary (PAB)
Privileged Access Manager (PAM) lets principals request temporary, auditable access, with justification or approval, instead of holding a role permanently.
| Tool | Answers… |
|---|---|
| Policy Analyzer | "Who has access to this service account?", "Which datasets can this user read?" (part of Cloud Asset Inventory) |
| Policy Troubleshooter | "Why does this user have, or not have, this permission?" |
| Role recommendations | Remove or replace roles with excess permissions |
| Activity Analyzer | When service accounts and their keys were last used |
| Service account insights | Service accounts unused in the past 90 days |
| Lateral movement insights | Roles that let a service account impersonate one in another project |
| Situation | Answer | Why |
|---|---|---|
| Give the data team read access to every project in a folder | Grant the predefined role to the group on the folder | It's inherited; groups simplify management. |
| No predefined role fits and the closest one grants too much | Custom role at the project or organization level | Least privilege; folder-level custom roles don't exist. |
| Give a contractor access only until the end of the month | Role binding with a request.time condition | Needs policy version 3. |
| Stop everyone except one group from deleting projects across the organization | Deny policy with exceptionPrincipals | Evaluated before allow policies. |
| Find out why a user can't read a bucket | Policy Troubleshooter | Explains which policy grants or denies. |
| Find out who has access to a BigQuery dataset | Policy Analyzer | Analyzes allow policies. |
| Remove permissions a user hasn't used in months | Role recommendations (IAM recommender) | Suggests removing or replacing roles. |
| Prevent service accounts from accessing resources in other organizations | Principal Access Boundary policy | Defines which resources principals can access. |
❓ Can you remove, on a project, a role that was granted on the folder?
Not with an allow policy: the effective policy is the union of every level. To block it, use a deny policy.
❓ Can you create a custom role at the folder level?
No. Only at the organization or project level; for a folder, create it in the organization.
❓ Can you add a condition to an Editor role binding?
No. Legacy basic roles (Owner, Editor, Viewer) don't support conditions.
❓ What happens if you run set-iam-policy with a file that only has the new binding?
It overwrites the whole policy and the other bindings are lost. Read, modify, then write.
❓ Does Owner have every permission?
No. For example, it can't change Cloud Billing payment information or create deny policies.
❓ Which is evaluated first, a deny or an allow policy?
The deny policy. If it denies the permission, the principal's roles don't matter.
Did you get this topic?
Test what you just learned
A support team should only be able to start and stop VMs in the prod project. No predefined role is limited to that. Following best practices, what do you do?
Original questions, each with a full explanation.
Start a mock exam