GCP - Project-Level IAM Binding vs Resource-Level IAM Binding
Project-Level IAM Bindings
A project-level IAM binding grants a role to a principal (like a service account) for all resources within that Google Cloud project. This is a broad, inherited permission. If you grant a service account the roles/run.jobsExecutor role at the project level, it can execute any Cloud Run job in that project.
The command for this is:
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member="serviceAccount:${SERVICE_ACCOUNT_EMAIL}" --role="${ROLE}"
Resource-Level IAM Bindings
A resource-level binding, on the other hand, grants a role to a principal for a specific, single resource. For Cloud Run jobs, this is a particular job instance. Granting a service account a role at this level gives it permissions only for that specific job, not for any others in the project.
The command for this is:
gcloud run jobs add-iam-policy-binding ${JOB_NAME} --member="serviceAccount:${SERVICE_ACCOUNT_EMAIL}" --role="${ROLE}"
Get All Resource-Level IAM Bindings
It is easy to get all Project-Level IAM Bindings with
gcloud projects get-iam-policy ${PROJECT_ID}
To get all Resource-Level IAM Bindings, use Cloud Asset Inventory API:
gcloud asset search-all-iam-policies \
--scope=projects/${PROJECT_ID} \
--query="policy:${SERVICE_ACCOUNT_EMAIL}" \
--format="table(asset_type,policy.bindings.role,resource)"
If your Cloud Asset Inventory API is not enabled, it will first ask you to enable it:
API [cloudasset.googleapis.com] not enabled on project [PROJECT_ID]. Would you like to enable and retry (this will take a few minutes)? (y/N)?
- Google Cloud Platform
- GCP - Compute
- GCP - Storage
- GCP - Networking
- GCP - DNS
- GCP - AI / ML
- GCP - PubSub
- GCP - Enterprise
- GCP - Key Management
- GCP - Dev Tools
- GCP - GCE
- GCP - GKE
- GCP - Agent Engine
- GCP - Google Distributed Cloud
- GCP - Cloud Run
- GCP - Load Balancing
- GCP - IAM
- GCP - Tokens
- GCP - Service Account
- GCP - Service Account Impersonation
- GCP - Application Default Credentials
- GCP - Security Guide
- GCP - Quotas
- GCP - Billing
- GCP - Colab
- GCP - GFE
- GCP - Open Source Dependencies
- GCP - Resource Hierarchy
- GCP - SaaS Runtime
- GCP - Deprecations
- GCP - How to provision resources
- GCP - How to provision resources with Terraform
- GCP - Versus
- GCP vs Kubernetes
- Gemini vs Vertex AI
- Asset vs Resource
- Service Account vs Service Agent
- Dataflow vs Dataproc
- Producer vs Consumer vs Tenant Project
- CSEK vs CMEK
- Secret Manager vs Cloud KMS
- Persistent Disk Snapshot vs Disk Image
- VPC vs VPC Service Controls
- Cloud Hub vs App Hub vs ADC
- Google API vs Cloud API
- Cloud IAP vs Cloud SWP
- GCE Metadata Server vs GKE Metadata Server
- Project vs Resource Level IAM Binding
- GKE vs GKE Enterprise
- Cloud PubSub vs PubSub Lite vs Managed Kafka
- VPC Peering vs VPC Service Perimeter

