GCP
PERMISSION_DENIED - Permission Denied: IAM Authorization Failure
Hitting PERMISSION_DENIED means your authenticated identity got past login but lacks the IAM role or permission GCP requires for this operation. This server-side authorization failure happens in GCP's control plane—your credentials are valid, but GCP evaluated your request and blocked it. You'll see this most often in Compute Engine VM operations, but it also surfaces in Cloud SQL database management, GKE cluster operations, and BigQuery dataset access. IAM role assignments can take 30-60 seconds to propagate, so recent grants might not be active yet.
#Common Causes
- →Missing IAM Role: Your identity doesn't have a required IAM role at the project, folder, or organization level. IAM role assignments can take 30-60 seconds to propagate across GCP's systems.
- →Resource-Level Permission Missing: Some operations require permissions at the resource level (e.g., specific Compute Engine instance, Cloud SQL database, GKE cluster) in addition to project-level roles. Resource-level bindings take precedence over project-level bindings.
- →Service Account Lacks Role: The service account your application uses doesn't have the IAM role needed for the operation. Service accounts need explicit role assignments—they don't inherit permissions from the user who created them.
- →Organization Policy Denial: Organization policies can explicitly deny operations even if IAM permissions allow them. Policies are evaluated after IAM but can override permissions.
✓Solutions
- 1Step 1: Diagnose - Check your IAM role assignments at the project level: gcloud projects get-iam-policy PROJECT_ID --flatten="bindings[].members" --filter="bindings.members:YOUR_IDENTITY" --format="table(bindings.role)"
- 2Step 2: Diagnose - If the operation requires resource-level permissions (e.g., Compute Engine instance, Cloud SQL database), check resource-level IAM: gcloud compute instances get-iam-policy INSTANCE_NAME --zone ZONE --project PROJECT_ID Or for Cloud SQL: gcloud sql instances get-iam-policy INSTANCE_NAME --project PROJECT_ID
- 3Step 3: Fix - Grant the missing IAM role at the appropriate level: gcloud projects add-iam-policy-binding PROJECT_ID --member="user:EMAIL" --role="roles/ROLE_NAME" For service accounts: gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT@PROJECT_ID.iam.gserviceaccount.com" --role="roles/ROLE_NAME"
- 4Step 4: Verify - Wait 30-60 seconds for IAM propagation, then retry your operation. If it still fails, check organization policies: gcloud resource-manager org-policies list --project PROJECT_ID
</>Code Examples
IAM Permission Diagnosis and Fix
1# This script helps diagnose and fix PERMISSION_DENIED errors
2
3# Step 1: Check your current IAM roles at project level
4# Replace PROJECT_ID with your GCP project ID
5PROJECT_ID="my-project"
6IDENTITY="user:example@example.com"
7
8echo "Checking project-level IAM roles..."
9gcloud projects get-iam-policy $PROJECT_ID \
10 --flatten="bindings[].members" \
11 --filter="bindings.members:$IDENTITY" \
12 --format="table(bindings.role)"
13
14# Step 2: Check resource-level permissions (example: Compute Engine instance)
15INSTANCE_NAME="my-instance"
16ZONE="us-central1-a"
17echo "Checking instance-level IAM policies..."
18gcloud compute instances get-iam-policy $INSTANCE_NAME \
19 --zone $ZONE \
20 --project $PROJECT_ID
21
22# Step 3: Grant missing role (example: Compute Instance Admin)
23# Replace ROLE_NAME with the required role (e.g., roles/compute.instanceAdmin)
24ROLE_NAME="roles/compute.instanceAdmin"
25echo "Granting role $ROLE_NAME..."
26gcloud projects add-iam-policy-binding $PROJECT_ID \
27 --member="$IDENTITY" \
28 --role="$ROLE_NAME"
29
30# Step 4: Wait for IAM propagation (30-60 seconds)
31echo "Waiting 60 seconds for IAM propagation..."
32sleep 60
33
34# Step 5: Verify access
35echo "Verifying access..."
36gcloud compute instances list --project $PROJECT_ID↗Related Errors
Provider Information
This error code is specific to GCP services. For more information, refer to the official GCP documentation.