A Compute Engine instance needs to read from a Cloud Storage bucket and write to a BigQuery table. Grant the minimum required permissions.
→Create a custom service account. Grant it the `roles/storage.objectViewer` and `roles/bigquery.dataEditor` roles. Attach this service account to the instance.
Why: Using a custom service account with specific, predefined roles avoids the overly permissive nature of the default Compute Engine service account, adhering to the principle of least privilege.
Grant a user permissions to manage GCE instances but not delete them.
→Create a custom IAM role. Start with the permissions from the `roles/compute.instanceAdmin.v1` role and remove the `compute.instances.delete` permission.
Why: Custom roles provide the flexibility to grant a precise set-of-permissions when predefined roles are too broad or too restrictive for a specific job function.
A developer needs to SSH into a Compute Engine instance that has no external IP address, as per security policy.
→Grant the developer the `roles/iap.tunnelResourceAccessor` role. They can then connect using `gcloud compute ssh [INSTANCE_NAME] --tunnel-through-iap`.
Why: Identity-Aware Proxy (IAP) TCP forwarding provides a secure, identity-based method to access internal instances without bastion hosts, VPNs, or public IPs.
Reference↗
Allow inbound SSH (port 22) traffic to specific VMs from the corporate office IP range only.
→Create a VPC firewall rule with `direction: INGRESS`, `action: ALLOW`, `protocol/ports: tcp:22`, `source ranges: [CORPORATE_IP_CIDR]`, and `target tags: [e.g., "allow-ssh"]`. Apply the tag to the intended VMs.
Why: Combining source ranges and target tags provides a precise and scalable way to control traffic. It restricts both *who* can connect and *what* they can connect to.
Prevent data from a sensitive BigQuery project from being copied or accessed from outside a trusted network boundary, even with valid credentials.
→Configure VPC Service Controls. Create a service perimeter that includes the sensitive project and restricts the BigQuery API.
Why: VPC Service Controls create a virtual "data perimeter" that controls API-level access, providing a strong defense against data exfiltration that firewall rules cannot.
Provide a third-party application temporary, time-limited read access to a specific private object in a Cloud Storage bucket.
→Generate a signed URL for the object with a short expiration time (e.g., 15 minutes) using a service account with read permissions.
Why: Signed URLs grant temporary, per-object access without requiring the third party to have a Google account or IAM permissions. It is the most secure method for this use case.
A GKE pod needs to securely access Google Cloud APIs (e.g., Pub/Sub) without storing service account keys as Kubernetes secrets.
→Enable Workload Identity on the GKE cluster. Create a Google Service Account (GSA) and a Kubernetes Service Account (KSA). Bind the KSA to the GSA using an IAM policy. Configure the pod to use the KSA.
Why: Workload Identity is the recommended, keyless way for GKE applications to authenticate to Google Cloud services. It maps KSA identities to GSA identities, which is more secure than managing and rotating key files.
Reference↗
An organization policy requires that all data in a Cloud Storage bucket be encrypted using an encryption key that the organization controls.
→Create a cryptographic key in Cloud KMS. When creating the Cloud Storage bucket, specify this key as the Customer-Managed Encryption Key (CMEK).
Why: CMEK gives you control over the key used for encryption, including rotation and revocation, while still leveraging Google's managed encryption infrastructure.
Allow employees to use their existing on-premises Active Directory credentials to access Google Cloud resources.
→Configure Cloud Identity to federate with Active Directory using SAML 2.0. Users authenticate with AD, which then asserts their identity to Google Cloud for access.
Why: Federation allows for Single Sign-On (SSO) and centralizes identity management in the existing IdP (Active Directory), avoiding the need to manage a separate set of passwords in Google Cloud.
Grant an external contractor temporary access to a project, which should automatically expire after 30 days.
→Add the contractor as an IAM member with the required role. Add a condition to the role binding with an expiration timestamp (`request.time < timestamp("YYYY-MM-DDTHH:MM:SSZ")`).
Why: IAM Conditions provide attribute-based access control. Time-based conditions are perfect for temporary access, as they automatically revoke permissions without manual cleanup.