Denying permissions that let users grant access helps you prevent unauthorized privilege escalation and tighten your security controls. This document describes how to identify these permissions and create a deny policy that blocks them for most users while allowing exceptions for trusted principals.
Before you begin
Enable the IAM API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.Set up authentication.
Select the tab for how you plan to use the samples on this page:
Console
When you use the Cloud de Confiance console to access Cloud de Confiance by S3NS services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity. After signing in, initialize the Google Cloud CLI by running the following command:
gcloud initREST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Cloud de Confiance authentication documentation.
Optional: Read the overview of deny policies.
Required roles
To get the permission that
you need to create a deny policy,
ask your administrator to grant you the
Deny Admin (roles/iam.denyAdmin) IAM role on your organization.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the
iam.denypolicies.create
permission,
which is required to
create a deny policy.
You might also be able to get this permission with custom roles or other predefined roles.
Identify permissions that let users grant access
Before you create a deny policy to prevent users from granting access, determine which permissions you want to deny.
The following permissions let users grant access:
Permissions ending in
setIamPolicy. The most broadly permissive of these permissions are those for Resource Manager resources because allow policies for those resources are inherited by all descendant resources. These permissions are as follows:cloudresourcemanager.googleapis.com/projects.setIamPolicycloudresourcemanager.googleapis.com/folders.setIamPolicycloudresourcemanager.googleapis.com/organizations.setIamPolicy
Other resources also have
setIamPolicypermissions—for example, Compute Engine instances have the permissioncompute.googleapis.com/instances.setIamPolicy. To prevent users from modifying allow policies for these resources, add these permissions to your deny policy.For a full list of deniable permissions ending in
setIamPolicy, go to Permissions supported in deny policies and search forsetIamPolicy.The
iam.googleapis.com/roles.updatepermission, which lets users modify custom roles. Users with this permission can add permissions to custom roles, effectively granting themselves or others those permissions.
Deny access change permissions
After you determine which permissions you want to deny, create a deny policy for your organization that denies these permissions.
Console
In the Cloud de Confiance console, go to the Deny tab on the IAM page.
Select your organization.
Click Create deny policy.
In the Policy name section, define the policy ID by doing one of the following:
- In the Display name field, enter a display name for the policy. Filling out this field automatically fills out the ID field. If you want to change the ID of the policy, update the text in the ID field.
- In the ID field, enter an ID for the policy.
In the Deny rules section, add a deny rule that blocks access change permissions:
In the Denied principals field, add the principals to deny access to. To deny access change permissions to all users, use the value
principalSet://goog/public:all. For a full list of values that you can use, see Principal identifiers for deny policies.In the Exception principals field, add the trusted principals that you want to let grant access. For a full list of values that you can use, see Principal identifiers for deny policies.
In the Denied permissions section, add the permissions that you identified in Identify permissions that let users grant access.
Optional: Add a denial condition that specifies which resources are affected by this rule. For example, you can add a condition to ensure that the policy applies only for resources with the
prodtag value. For more information about denial conditions, see Conditions in deny policies.
Click Create.
gcloud
The
gcloud iam policies create
command creates a deny policy for a resource.
Before using any of the command data below, make the following replacements:
POLICY_ID: An identifier for the deny policy.-
ORG_ID: The numeric ID of the organization where you want to create the deny policy. -
POLICY_FILE: A file that contains the deny policy that you want to set. Use the following format for the deny policy:{ "displayName": "POLICY_NAME", "rules": [ { "denyRule": { "deniedPrincipals": [ DENIED_PRINCIPALS ], "exceptionPrincipals": [ EXCEPTION_PRINCIPALS ], "deniedPermissions": [ ACCESS_CHANGE_PERMISSIONS ], DENIAL_CONDITION } } ] }
Replace the following values:
POLICY_NAME: The display name for the deny policy.-
DENIED_PRINCIPALS: The principals to deny access to. To deny access change permissions to all users, use the value"principalSet://goog/public:all". For a full list of values that you can use, see Principal identifiers for deny policies. -
EXCEPTION_PRINCIPALS: The trusted principals that you want to let grant access. For a full list of values that you can use, see Principal identifiers for deny policies. -
ACCESS_CHANGE_PERMISSIONS: The permissions that you identified in Identify permissions that let users grant access. -
DENIAL_CONDITION: Optional. A denial condition that specifies which resources are affected by this rule. For example, you can add a condition to ensure that the rule applies only for resources with theprodtag value. For more information about denial conditions, see Conditions in deny policies.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud iam policies create POLICY_ID \ --attachment-point=cloudresourcemanager.googleapis.com/organizations/ORG_ID \ --kind=denypolicies \ --policy-file=POLICY_FILE
Windows (PowerShell)
gcloud iam policies create POLICY_ID ` --attachment-point=cloudresourcemanager.googleapis.com/organizations/ORG_ID ` --kind=denypolicies ` --policy-file=POLICY_FILE
Windows (cmd.exe)
gcloud iam policies create POLICY_ID ^ --attachment-point=cloudresourcemanager.googleapis.com/organizations/ORG_ID ^ --kind=denypolicies ^ --policy-file=POLICY_FILE
If successful, this command returns no output. To print a detailed response,
use the --format=json flag.
REST
The
policies.createPolicy
method creates a deny policy for a resource.
Before using any of the request data, make the following replacements:
-
ORG_ID: The numeric ID of the organization where you want to create the deny policy. POLICY_ID: An identifier for the deny policy.POLICY_NAME: The display name for the deny policy.-
DENIED_PRINCIPALS: The principals to deny access to. To deny access change permissions to all users, use the value"principalSet://goog/public:all". For a full list of values that you can use, see Principal identifiers for deny policies. -
EXCEPTION_PRINCIPALS: The trusted principals that you want to let grant access. For a full list of values that you can use, see Principal identifiers for deny policies. -
ACCESS_CHANGE_PERMISSIONS: The permissions that you identified in Identify permissions that let users grant access. -
DENIAL_CONDITION: Optional. A denial condition that specifies which resources are affected by this rule. For example, you can add a condition to ensure that the rule applies only for resources with theprodtag value. For more information about denial conditions, see Conditions in deny policies.
HTTP method and URL:
POST https://iam.googleapis.com/v2/policies/cloudresourcemanager.googleapis.com%2Forganizations%2FORG_ID/denypolicies?policyId=POLICY_ID
Request JSON body:
{
"displayName": "POLICY_NAME",
"rules": [
{
"denyRule": {
"deniedPrincipals": [
DENIED_PRINCIPALS
],
"exceptionPrincipals": [
EXCEPTION_PRINCIPALS
],
"deniedPermissions": [
ACCESS_CHANGE_PERMISSIONS
],
DENIAL_CONDITION
}
}
]
}
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{
"name": "policies/cloudresourcemanager.googleapis.com%2Forganizations%2F1234567890123/denypolicies/deny-access-granting/operations/89cb3e508bf1ff01",
"metadata": {
"@type": "type.googleapis.com/google.iam.v2.PolicyOperationMetadata",
"createTime": "2026-10-31T19:06:12.455151Z"
},
"response": {
"@type": "type.googleapis.com/google.iam.v2.Policy",
"name": "policies/cloudresourcemanager.googleapis.com%2Forganizations%2F1234567890123/denypolicies/deny-access-granting",
"uid": "6665c437-a3b2-a018-6934-54dd16d3426e",
"kind": "DenyPolicy",
"displayName": "Deny access change permissions.",
"etag": "MTc3NDU4KjM4OZ0MzU5MjQ5OTI=",
"createTime": "2026-10-31T19:06:12.455151Z",
"updateTime": "2026-10-31T22:26:21.968687Z",
"rules": [
{
"denyRule": {
"deniedPrincipals": [
"principalSet://goog/public:all"
],
"exceptionPrincipals": [
"principalSet://cloudresourcemanager.googleapis.com/organizations/1234567890123/type/ServiceAgent",
"principalSet://iam.googleapis.com/locations/global/workforcePools/example-pool/group/iam-admins"
],
"deniedPermissions": [
"cloudresourcemanager.googleapis.com/projects.setIamPolicy",
"cloudresourcemanager.googleapis.com/folders.setIamPolicy",
"cloudresourcemanager.googleapis.com/organizations.setIamPolicy"
],
"denialCondition": {
"title": "Only for prod resources",
"expression": "resource.matchTag('12345678/env', 'prod')"
}
}
}
]
}
}
The response identifies a long-running operation. You can monitor the status of the long-running operation to find out when it's complete. For details, see Check the status of a long-running operation.
What's next
- Find out how to troubleshoot access issues with deny policies.
- Learn more about denying access to principals.