SecurityGoogle Cloud
Google Cloud IAM and organization policies
In Google's words, IAM focuses on who and Organization Policy focuses on what. IAM authorizes who can act on a resource. An organization policy restricts how resources can be configured. Both are inherited through the resource hierarchy.

The resource hierarchy
The organization is at the top of the hierarchy. Folders are optional and come next: a folder can contain projects and other folders. Projects contain the service resources, such as virtual machines and storage buckets. Every resource except the top one has exactly one parent.
Organizations, folders and projects are the inheritance points for allow policies, deny policies and organization policies. Roles granted on a folder are inherited by all projects and folders in it. The effective policy for a resource results from the policies applied directly to it and the policies inherited from its ancestors. So grant a role no higher in the hierarchy than the work requires.
Allow policies and role types
An allow policy is a collection of role bindings. A role binding associates one or more principals with a single role and, optionally, a condition. IAM has three kinds of role:
- Basic roles give broad access across Google Cloud resources. They are Admin (
roles/admin), Writer (roles/writer) and Reader (roles/reader), plus the legacy basic roles Owner (roles/owner), Editor (roles/editor) and Viewer (roles/viewer). Google's guidance: a production environment gets basic roles only where no alternative exists. - Predefined roles give granular access for a specific service.
roles/storage.objectVieweris one. - Custom roles bundle permissions that you choose. You create them at the project or organization level. They cannot be defined at the folder level.
The command that grants a role on a project has this form:
gcloud projects add-iam-policy-binding <project-id> \
--member=<principal> --role=<role>A principal is written with its type as a prefix, as in group:[email protected]. To read the current allow policy, run gcloud projects get-iam-policy <project-id>.
Deny policies
A deny policy prevents principals from using specific permissions, regardless of the roles they are granted. IAM always checks relevant deny policies before it checks relevant allow policies. You attach a deny policy to an organization, a folder or a project, and it is inherited by the resources below.
Each deny rule lists the denied principals and the denied permissions. Exception principals and a condition are optional. This file wraps Google's own example rule. It stops the eng group from creating or deleting service account keys and exempts the eng-prod group. Save it as policy.json:
{
"displayName": "My deny policy.",
"rules": [
{
"denyRule": {
"deniedPrincipals": [
"principalSet://goog/group/[email protected]"
],
"exceptionPrincipals": [
"principalSet://goog/group/[email protected]"
],
"deniedPermissions": [
"iam.googleapis.com/serviceAccountKeys.create",
"iam.googleapis.com/serviceAccountKeys.delete"
]
}
}
]
}gcloud iam policies create my-deny-policy \
--attachment-point=cloudresourcemanager.googleapis.com/projects/my-project \
--kind=denypolicies \
--policy-file=policy.jsonA deny policy writes permissions in the IAM v2 format, where a fully qualified domain name identifies the service.
Organization policy constraints
An organization policy configures a single constraint. You set it on an organization, a folder or a project, and descendants inherit it by default.
Constraints come in three kinds. Managed constraints are designed to replace the equivalent legacy managed constraints. Legacy managed constraints, previously known as predefined constraints, have list rules or boolean rules. Custom constraints are managed by your organization. Six constraints by name:
constraints/gcp.resourceLocationsdefines the locations where location-based resources can be created.constraints/iam.allowedPolicyMemberDomainsdefines whose principals can be added to IAM policies.constraints/iam.managed.disableServiceAccountCreationdisables the creation of service accounts.constraints/iam.managed.disableServiceAccountKeyCreationblocks service account key creation.constraints/storage.publicAccessPreventionenforces public access prevention on Cloud Storage data.constraints/compute.managed.vmExternalIpAccessdenies the creation or update of VM instances with external IPv4 addresses.
A policy is a YAML file. This is Google's example for a managed constraint:
name: organizations/<organization-id>/policies/iam.managed.disableServiceAccountCreation
spec:
rules:
- enforce: truegcloud org-policies set-policy policy.yaml
gcloud org-policies describe iam.managed.disableServiceAccountCreation \
--effective --organization=<organization-id>describe --effective returns the policy as it is evaluated at that point in the hierarchy, with inheritance included. Full enforcement of a change can take up to 15 minutes. A new policy does not stop behavior that a service is already in: Google states that you address such a violation manually.
To test a policy, define the rules under dryRunSpec in place of spec. Violations are then audit logged, but the violating actions are not denied. Dry-run mode is available for custom constraints, managed constraints and four legacy ones: Restrict service usage, Restrict endpoint usage, Restrict TLS versions and Restrict TLS cipher suites.
A rollout order
- Group projects in folders and grant roles on the folder. All projects in it inherit them.
- Replace basic roles with the most limited predefined or custom roles that meet your needs.
- Add a deny policy where a permission must stay unused regardless of granted roles, and list exception principals for the group that still needs it.
- Set organization policies in dry-run mode where the constraint supports it, and read the audit logs before you enforce them.
- After each change, check one project with
gcloud org-policies describeand--effective.
Managing organization policies requires the Organization policy administrator role (roles/orgpolicy.policyAdmin) on the organization. Grant that role to few people.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

Landing zones: accounts, subscriptions and projects in order
Cloud operations · 5 min read
The account hierarchy, identity, network, logging and guardrails in each vendor's landing zone design.

Keyless deploys to AWS and Google Cloud with OIDC
Authentication · 2 min read
The trust policy for AWS and the provider setting for Google Cloud, with the workflow for each.

CloudTrail, Azure Activity Log and Cloud Audit Logs: turn them on first
Security · 4 min read
What each cloud logs by default, how long it keeps the record and where to send a copy.