Least privilege is the rule that a principal should hold only the permissions strictly needed for the task it performs, scoped to the smallest resource container that contains the work. It solves the problem of blast radius:
- when a credential is stolen,
- a service account is compromised,
- or a user script behaves badly,
- the harm is bounded by what the principal could have done anyway.
On Google Cloud the rule is implemented through Identity and Access Management (IAM), which binds principals to roles at a specific resource scope. A foundational data practitioner must internalize three coordinates of every IAM decision: who the principal is, which role is granted, and where the grant takes effect.
How it works
The IAM resource hierarchy is the spine of every scoping decision. The hierarchy runs organization, folder, project, then resource (a BigQuery dataset, a Cloud Storage bucket, a Cloud SQL instance, a Pub/Sub topic). A binding made at a higher node is inherited by every node below it.
Granting roles/bigquery.dataViewer at the organization is the broadest possible grant of that role; granting the same role on a single BigQuery dataset is the narrowest. The principle of least privilege says you start at the lowest node that contains the work and only widen the scope if the access pattern truly demands it. Inheriting from a folder is convenient for analytics teams that always work across the same set of projects, but it leaves the door open to access bleed when projects are reassigned.
Principals come in several categories that a data practitioner must distinguish on sight.
- A Google account is a real human in a Workspace or Cloud Identity tenant.
- A Google group is the preferred grant target because membership is administered separately from policy, allowing personnel changes without touching IAM bindings.
- A service account is a non-human identity tied to a project and intended for workloads.
- A workload identity federation pool maps external identities (such as a GitHub Actions OIDC token or an AWS IAM role) onto short-lived Google credentials without ever provisioning a downloadable service account key.
Domain-wide grants exist (the allAuthenticatedUsers and allUsers special identifiers), and they are the most common source of accidental data exposure; the public access prevention setting on Cloud Storage and the organization policy iam.allowedPolicyMemberDomains exist to fence them off.
In practice
Service accounts deserve special discipline because they sit at the center of every pipeline.
The default Compute Engine service account and the default App Engine service account are created with Editor on the project, which is the opposite of least privilege; you should disable that default grant via the organization policy iam.automaticIamGrantsForDefaultServiceAccounts and provision a dedicated service account per workload.
The right pattern for impersonation is to assign roles/iam.serviceAccountTokenCreator to the principal that needs to act as the service account, then have that principal request a short-lived access token.
Long-lived service account keys are the most common credential leak in audit findings, and the organization policy iam.disableServiceAccountKeyCreation exists to forbid them entirely on regulated projects.
When a workload runs inside Google Cloud (Cloud Run, Cloud Functions, GKE, Dataflow, Composer), attach a service account directly to the runtime so the workload uses the metadata server, not a key file.
Conditional bindings tighten scope further by attaching a Common Expression Language (CEL) expression to a grant. The expression evaluates resource attributes (such as resource.name.startsWith("projects/_/buckets/acme-data-raw")), request attributes (such as request.time for time-bound access), or attribute-based access from access levels (such as IP allowlists from Access Context Manager).
Conditional access is the right tool for break-glass elevation, time-boxed contractor access, or restricting a broad role like Storage Object Admin to a single bucket prefix. The IAM policy troubleshooter is the official tool for testing why a principal can or cannot perform a permission on a resource; the Policy Analyzer answers the inverse question (which principals can perform a given permission).
# Grant a predefined BigQuery role to a group at the dataset scope (least privilege).
bq update --source - acme-analytics-prod:sales_marts <<'EOF'
{
"access": [
{ "role": "roles/bigquery.dataViewer", "groupByEmail": "sales-analysts@example.com" }
]
}
EOF
# Grant a service account permission to read objects from a single bucket.
gcloud storage buckets add-iam-policy-binding gs://acme-data-curated \
--member="serviceAccount:reporting-svc@acme-analytics-prod.iam.gserviceaccount.com" \
--role="roles/storage.objectViewer"
# Allow a CI workload to impersonate a deploy service account without keys.
gcloud iam service-accounts add-iam-policy-binding \
deploy-svc@acme-analytics-prod.iam.gserviceaccount.com \
--member="principalSet://iam.googleapis.com/projects/123456/locations/global/workloadIdentityPools/github/attribute.repository/acme/etl" \
--role="roles/iam.serviceAccountTokenCreator"
# Conditional binding: time-bounded contractor access to one bucket prefix.
gcloud projects add-iam-policy-binding acme-analytics-prod \
--member="user:contractor@example.com" \
--role="roles/storage.objectViewer" \
--condition='expression=resource.name.startsWith("projects/_/buckets/acme-data-handoff/objects/2030-q1/") && request.time < timestamp("2030-04-01T00:00:00Z"),title=q1-handoff,description=read-only for Q1 handoff window'
Decision Tree: Picking the IAM Scope
💡 Exam Trap: A question that grants
roles/ownerat the project level to a data analyst is almost always wrong, even when the analyst manages the project. Owner includes billing and IAM admin, which violates least privilege. The right answer pairsroles/bigquery.user(or another predefined role) withroles/storage.objectViewerat the dataset and bucket scopes.
💡 Exam Trap: Watch for stems that say "the service account needs to act as another service account." That is a permission on the target service account, granted via
roles/iam.serviceAccountTokenCreatororroles/iam.serviceAccountUser, not a project-wide role. Granting Editor on the project to make the impersonation work is the trap distractor.
⚠️ Anti-Pattern: Granting roles directly to individual users instead of to a group. Personnel churn forces repeated edits to bindings, and revocations are missed. Bind a Google group, then administer membership.
🎯 Scenario: Your dashboarding team has 12 analysts who need read on three sales datasets and read on two reporting buckets. The least-privilege design is to create a Google group
sales-analysts@example.com, grantroles/bigquery.dataVieweron each of the three datasets androles/storage.objectVieweron each of the two buckets to that group, and onboard or offboard analysts by editing group membership. Grantingroles/bigquery.userat the project would expose every dataset; granting at the organization would expose every project.
Decision Anchor. Choose a resource-scoped binding when a single bucket, dataset, instance, or topic is the work container. Choose a project-scoped binding when the principal needs equivalent access across most resources of one project.
Choose a folder-scoped or organization-scoped binding when the same team must operate identically across many projects, and use IAM Conditions to narrow inherited grants where the inheritance is too broad.
Auditing closes the loop on least privilege. Cloud Audit Logs record every IAM policy change in Admin Activity logs (always on) and every data access in Data Access logs (off by default for most services, except BigQuery Data Access logs which are always recorded for reads).
The Policy Analyzer answers questions like "which principals can run bigquery.tables.getData on dataset X" and is the official way to detect overly broad grants. Recommender produces unused permission findings on service accounts and roles so you can right-size grants without guesswork.
Treat the recommender output as part of the quarterly access review, not as a one-time cleanup.
📊 Limit: A project can carry at most 1,500 IAM role bindings in its policy, and a single resource policy can have up to 250 conditional bindings per role; large analytics estates must group principals to stay under both ceilings.
📊 Limit: A service account can hold up to 10 user-managed keys at a time, and a default key expiry policy can be set via the
iam.serviceAccountKeyExpiryorganization policy; many regulated estates set it to zero by disabling key creation entirely.
The exam favors questions in which only one option pairs the right principal type, the right role, and the right scope.
When you encounter four options that all "work technically," the correct answer is the one that grants the smallest role at the smallest scope to the most appropriate principal.
If a question lists a long-lived service account key in any option as part of the solution, it is almost never the intended answer; impersonation, workload identity federation, or attached service accounts win. ---
