Top 20 GCP IAM & Identity Interview Questions
- What is GCP IAM?
- What are IAM roles?
- What are service accounts?
- What is the principle of least privilege?
- What are IAM policies?
- What is Identity Platform?
- How do you manage service account keys?
- What is Workload Identity?
- What are IAM conditions?
- How do you audit IAM permissions?
- What is organization policy?
- What are custom roles?
- How do you implement cross-project access?
- What is Identity-Aware Proxy (IAP)?
- How do you manage access at scale?
- What are IAM recommender insights?
- What is VPC Service Controls?
- How do you implement identity federation?
- What are domain-wide delegation?
- What are IAM best practices?
☁ Google Cloud Interview Questions
📊 GCP Data Engineer
BigQuery, Dataflow, Pub/Sub, GCS
⚡ Cloud Functions
Serverless, Triggers, Cloud Run
🗃 BigQuery
Data Warehouse, ML, Analytics
📦 Cloud Storage & Data Lake
GCS, Dataplex, Data Catalog
🚀 Dataproc & Dataflow
Spark, Hadoop, Apache Beam
🔄 Workflows & Composer
Orchestration, Airflow, Scheduling
🔒 IAM & Identity
Roles, Service Accounts, Identity Platform
🤖 Vertex AI
ML Platform, AutoML, Pipelines
🛠 Cloud Build & Deploy
CI/CD, Artifact Registry, GKE
📨 Pub/Sub & Streaming
Messaging, Streaming, Event-Driven
🎯 Data Engineering Scenarios
Real-world Architecture Questions
1. What is GCP IAM?
Identity and Access Management (IAM) controls who (identity) has what access (role) to which resources.
IAM Concepts:
+-------------------------------------------------------------+
| GCP IAM |
+-------------------------------------------------------------+
| |
| WHO (Members/Principals) |
| +-- Google Account (user@gmail.com) |
| +-- Service Account (sa@project.iam.gserviceaccount.com) |
| +-- Google Group (group@googlegroups.com) |
| +-- Google Workspace domain (domain.com) |
| +-- Cloud Identity domain |
| +-- allUsers, allAuthenticatedUsers |
| |
| WHAT (Roles) |
| +-- Basic: Owner, Editor, Viewer |
| +-- Predefined: roles/bigquery.dataViewer |
| +-- Custom: projects/my-project/roles/customRole |
| |
| WHICH (Resources) |
| +-- Organization |
| +-- Folder |
| +-- Project |
| +-- Individual resources (bucket, dataset, etc.) |
| |
| Policy = Bindings (Member + Role) attached to Resource |
+-------------------------------------------------------------+
Resource Hierarchy:
+------------------+
| Organization |
+--------+---------+
|
+----+----+
| Folder | (optional)
+----+----+
|
+----+----+
| Project |
+----+----+
|
+----+----+
| Resource| (bucket, VM, etc.)
+---------+
# View IAM policy
gcloud projects get-iam-policy my-project
# Add binding
gcloud projects add-iam-policy-binding my-project \
--member="user:alice@example.com" \
--role="roles/viewer"
2. What are IAM roles?
Role Types:
1. Basic Roles (Primitive)
+-- roles/owner - Full access + IAM management
+-- roles/editor - Read/write access
+-- roles/viewer - Read-only access
# Avoid basic roles in production - too broad
2. Predefined Roles (Fine-grained)
# BigQuery
+-- roles/bigquery.admin
+-- roles/bigquery.dataEditor
+-- roles/bigquery.dataViewer
+-- roles/bigquery.jobUser
+-- roles/bigquery.user
# Cloud Storage
+-- roles/storage.admin
+-- roles/storage.objectAdmin
+-- roles/storage.objectViewer
+-- roles/storage.objectCreator
# Compute Engine
+-- roles/compute.admin
+-- roles/compute.instanceAdmin
+-- roles/compute.viewer
3. Custom Roles
gcloud iam roles create myCustomRole \
--project=my-project \
--title="My Custom Role" \
--description="Custom role for specific tasks" \
--permissions=bigquery.datasets.get,bigquery.tables.list,bigquery.jobs.create
# List permissions for a role
gcloud iam roles describe roles/bigquery.dataViewer
# View all predefined roles
gcloud iam roles list --filter="name:roles/bigquery"
Role Binding Example:
{
"bindings": [
{
"role": "roles/bigquery.dataViewer",
"members": [
"user:alice@example.com",
"serviceAccount:sa@project.iam.gserviceaccount.com",
"group:data-team@example.com"
]
},
{
"role": "roles/bigquery.jobUser",
"members": [
"user:bob@example.com"
]
}
]
}
3. What are service accounts?
Service accounts are special accounts for applications and services to authenticate to GCP APIs.
Service Account Types:
+-- User-managed - Created by users
+-- Default - Created automatically (avoid using)
+-- Google-managed - Used by GCP services
# Create service account
gcloud iam service-accounts create my-service-account \
--display-name="My Service Account" \
--description="Used for data processing"
# Grant roles to service account
gcloud projects add-iam-policy-binding my-project \
--member="serviceAccount:my-service-account@my-project.iam.gserviceaccount.com" \
--role="roles/bigquery.dataEditor"
# Service account impersonation
gcloud iam service-accounts add-iam-policy-binding \
my-service-account@my-project.iam.gserviceaccount.com \
--member="user:developer@example.com" \
--role="roles/iam.serviceAccountUser"
# Impersonate in gcloud
gcloud config set auth/impersonate_service_account \
my-service-account@my-project.iam.gserviceaccount.com
# Python with impersonation
from google.auth import impersonated_credentials
from google.auth import default
source_credentials, _ = default()
target_credentials = impersonated_credentials.Credentials(
source_credentials=source_credentials,
target_principal='sa@project.iam.gserviceaccount.com',
target_scopes=['https://www.googleapis.com/auth/cloud-platform']
)
# Use in client
from google.cloud import bigquery
client = bigquery.Client(credentials=target_credentials)
Service Account Best Practices:
+-- One SA per application/service
+-- Grant minimum required permissions
+-- Avoid SA keys (use Workload Identity)
+-- Rotate keys if they must be used
+-- Use short-lived tokens when possible
+-- Audit SA usage regularly
4. What is the principle of least privilege?
Least Privilege Principle:
+-- Grant only permissions needed
+-- For the specific resources needed
+-- For the time needed
+-- Audit and revoke unused permissions
Implementation:
1. Use predefined roles instead of basic
# Bad
gcloud projects add-iam-policy-binding my-project \
--member="user:analyst@example.com" \
--role="roles/editor"
# Good
gcloud projects add-iam-policy-binding my-project \
--member="user:analyst@example.com" \
--role="roles/bigquery.dataViewer"
2. Grant at resource level, not project
# Instead of project-level
gcloud projects add-iam-policy-binding my-project \
--member="serviceAccount:etl@project.iam.gserviceaccount.com" \
--role="roles/bigquery.dataEditor"
# Grant on specific dataset
bq add-iam-policy-binding \
--member="serviceAccount:etl@project.iam.gserviceaccount.com" \
--role="roles/bigquery.dataEditor" \
project:dataset
3. Use IAM conditions for time-bound access
gcloud projects add-iam-policy-binding my-project \
--member="user:contractor@example.com" \
--role="roles/viewer" \
--condition="expression=request.time < timestamp('2024-03-31T23:59:59Z'),title=temporary-access"
4. Regular access reviews
# Use IAM Recommender
gcloud recommender recommendations list \
--project=my-project \
--location=global \
--recommender=google.iam.policy.Recommender
5. Separate environments
+-- Development - More permissive
+-- Staging - Production-like permissions
+-- Production - Strictest controls
5. What are IAM policies?
IAM Policy Structure:
# Get current policy
gcloud projects get-iam-policy my-project --format=json > policy.json
# policy.json
{
"version": 3,
"etag": "BwXXXXXXXXX=",
"bindings": [
{
"role": "roles/owner",
"members": [
"user:admin@example.com"
]
},
{
"role": "roles/bigquery.dataViewer",
"members": [
"user:analyst@example.com",
"group:data-team@example.com"
],
"condition": {
"title": "Dataset access only",
"description": "Access to specific datasets",
"expression": "resource.name.startsWith('projects/my-project/datasets/public_')"
}
}
],
"auditConfigs": [
{
"service": "bigquery.googleapis.com",
"auditLogConfigs": [
{"logType": "ADMIN_READ"},
{"logType": "DATA_READ"},
{"logType": "DATA_WRITE"}
]
}
]
}
# Set policy
gcloud projects set-iam-policy my-project policy.json
Policy Inheritance:
+------------------+
| Organization | --- Policy A
+--------+---------+
| (inherits)
+----+----+
| Folder | --- Policy B
+----+----+
| (inherits)
+----+----+
| Project | --- Policy C
+----+----+
| (inherits)
+----+----+
| Resource| --- Policy D
+---------+
Effective policy = A + B + C + D (union)
Note: Deny policies override allow
# Python: Get/Set policy
from google.cloud import resourcemanager_v3
client = resourcemanager_v3.ProjectsClient()
policy = client.get_iam_policy(resource=f"projects/my-project")
# Add binding
policy.bindings.add(
role="roles/viewer",
members=["user:new@example.com"]
)
client.set_iam_policy(resource=f"projects/my-project", policy=policy)