Cloud Security Interview Questions with Hands-On Labs
What you build: 7 cloud security interview answers proved on Google Cloud: least privilege, Secret Manager, public buckets, keys, audit logs, firewall, Shielded VM. Every step tested.

✍️ Translate this blog into Hindi, Tamil or Telugu
Cloud security interviews test whether you understand identity, secrets, data exposure, audit and network exposure, not whether you can recite a product list. In this post, 7 common questions are answered and each answer is proved with a real command on Google Cloud, using a small, deliberately locked-down setup: a private bucket, a secret, and a VM that runs as a service account allowed to read one bucket and nothing else.
Who it is for: anyone preparing for cloud, DevOps, DevSecOps or SRE interviews. Time: about 45 minutes. Cost: one tiny VM, one secret and one small bucket for about 10 minutes, covered by the free trial credit.
Every command below was run for real by the CareerByteCode Team, and every output is the real result we got. The gcloud commands ran on a Cloud Shell-like Linux machine; the ones marked "on sec-vm" ran on the test VM over SSH, as its service account, not as us.
The lab behind the answers

One setup step creates everything:
- a private bucket with uniform access and public access prevention, holding one file;
- a service account
sec-readerwith Storage Object Viewer on that one bucket only; - a secret
seclab-db-passwordwith a random value that is never printed; sec-vm: no public IP, Shielded VM secure boot on, running assec-reader.
The bucket name is made from a hash of the project id, so it is stable but does not show the project id:
# The lab: a private bucket with one file, a secret, and a service account that may ONLY read that bucket
B=seclab-$(echo -n $PROJECT_ID | md5sum | cut -c1-8) # the same name on every machine, without showing the project id
gcloud storage buckets create gs://$B --location=us-east1 --uniform-bucket-level-access --public-access-prevention > /dev/null && echo "report for the auditors" | gcloud storage cp - gs://$B/report.txt > /dev/null && echo "bucket with report.txt created"
gcloud iam service-accounts create sec-reader --display-name="Lab: reads one bucket only" > /dev/null
until gcloud iam service-accounts describe sec-reader@$PROJECT_ID.iam.gserviceaccount.com > /dev/null 2>&1; do sleep 5; done
until gcloud storage buckets add-iam-policy-binding gs://$B --member=serviceAccount:sec-reader@$PROJECT_ID.iam.gserviceaccount.com --role=roles/storage.objectViewer > /dev/null 2>&1; do sleep 5; done; echo "sec-reader may read objects in this one bucket"
gcloud services enable secretmanager.googleapis.com > /dev/null; openssl rand -hex 16 | gcloud secrets create seclab-db-password --data-file=- --replication-policy=automatic > /dev/null && echo "secret seclab-db-password created (value never printed)"
gcloud compute instances create sec-vm --zone=us-east1-b --machine-type=e2-micro --no-address --service-account=sec-reader@$PROJECT_ID.iam.gserviceaccount.com --scopes=cloud-platform --shielded-secure-boot --image-family=debian-12 --image-project=debian-cloud > /dev/null 2>&1
until gcloud compute ssh sec-vm --zone=us-east1-b --tunnel-through-iap --command="true" > /dev/null 2>&1; do sleep 10; done; echo "sec-vm runs as sec-reader, no public IP"Creating gs://seclab-2c18be0d/...
Copying file://- to gs://seclab-2c18be0d/report.txt
...
bucket with report.txt created
Created service account [sec-reader].
Service account email: sec-reader@your-project-id.iam.gserviceaccount.com
sec-reader may read objects in this one bucket
Created version [1] of the secret [seclab-db-password].
secret seclab-db-password created (value never printed)
sec-vm runs as sec-reader, no public IP
Q1. What is least privilege, and how do you prove it?
Answer: every identity gets only the permissions its job needs, on the smallest resource possible. Grant roles on the bucket, not the project; give each workload its own service account.
Proof (on sec-vm, as sec-reader): reading the file works, writing over it is refused:
# Q1. Least privilege: on sec-vm (running as sec-reader), reading is allowed and writing is refused
B=seclab-$(echo -n $PROJECT_ID | md5sum | cut -c1-8)
echo "who am I: $(gcloud config get-value account 2>/dev/null | sed 's/@.*/@.../')"
gcloud storage cat gs://$B/report.txt
echo "tamper" | gcloud storage cp - gs://$B/report.txt 2>&1 | grep -oE "HTTPError 403|does not have [a-z.]+ access|denied" | head -1who am I: sec-reader@...
report for the auditors
does not have storage.objects.create accessQ2. Where should an app keep its database password?
Answer: in Secret Manager, read at start-up by the app's own service account, with access granted per secret. Never in code, images, environment files in Git, or VM metadata.
Break it (on sec-vm): the app needs the password, but nobody gave sec-reader access:
# Q2. Break it: the app on sec-vm needs the database password from Secret Manager, but nobody gave it access
gcloud secrets versions access latest --secret=seclab-db-password 2>&1 | grep -oE "PERMISSION_DENIED|Permission '[a-zA-Z.]+' denied" | head -1PERMISSION_DENIEDFix it: grant the Secret Accessor role on this one secret (not on the project):
# Q2. Fix it: give sec-reader the Secret Accessor role on THIS secret only (not on the whole project)
gcloud secrets add-iam-policy-binding seclab-db-password --member=serviceAccount:sec-reader@$PROJECT_ID.iam.gserviceaccount.com --role=roles/secretmanager.secretAccessor --format="value(bindings[0].role)"; sleep 30Updated IAM policy for secret [seclab-db-password].
roles/secretmanager.secretAccessorThe same request now works. We print only the length, never the value:
# Q2. The same request from sec-vm now works. We only count the characters: a secret is never printed
echo "password read: $(gcloud secrets versions access latest --secret=seclab-db-password | wc -c | tr -d ' ') characters"password read: 34 characters
Q3. How do you stop a bucket from being made public by mistake?
Answer: public access prevention blocks allUsers and allAuthenticatedUsers on the bucket (set it per bucket, or for the whole organisation with an org policy). Uniform bucket-level access turns off per-object ACLs, so IAM is the only way in.
Proof: we try to make the bucket public:
# Q3. Can someone make the bucket public by mistake? Public access prevention says no
B=seclab-$(echo -n $PROJECT_ID | md5sum | cut -c1-8)
gcloud storage buckets add-iam-policy-binding gs://$B --member=allUsers --role=roles/storage.objectViewer 2>&1 | grep -oE "public access prevention[^.]*|412[^.]*" | head -1
gcloud storage buckets describe gs://$B --format="value(public_access_prevention,uniform_bucket_level_access)" | sed 's/^/public access prevention, uniform access: /'412: The member bindings allUsers and allAuthenticatedUsers are not allowed since public access prevention is enforced
public access prevention, uniform access: enforced TrueRefused with HTTP 412, because public access prevention is enforced.
Q4. Why avoid service account keys?
Answer: a key file is a password that never expires and is easy to leak (laptops, Git, chat). Workloads on Google Cloud get short-lived tokens automatically from the metadata server; outside Google Cloud, use workload identity federation.
Proof: sec-reader has 0 user-made keys; the VM still works because Google manages its credentials:
# Q4. Service account keys: how many user-made keys does sec-reader have? (0 is the goal: VMs get short tokens)
echo "user-managed keys: $(gcloud iam service-accounts keys list --iam-account=sec-reader@$PROJECT_ID.iam.gserviceaccount.com --managed-by=user --format='value(name)' | wc -l)"
echo "Google-managed keys: $(gcloud iam service-accounts keys list --iam-account=sec-reader@$PROJECT_ID.iam.gserviceaccount.com --managed-by=system --format='value(name)' | wc -l)"user-managed keys: 0
Google-managed keys: 1📝⭐ Recommended by CareerByteCode · Certification examGoogle Analytics Certification (GA4) PracticeTake the examTake the exam →Q5. Who changed access, and when?
Answer: Cloud Audit Logs. Admin Activity logs (who changed IAM, created or deleted resources) are always on and free.
Proof: the IAM change we made to the secret in Q2, found in the logs a minute later:
# Q5. Who changed access? Cloud Audit Logs record every IAM change (here: the secret's policy, a few minutes ago)
sleep 60; gcloud logging read 'protoPayload.methodName="google.cloud.secretmanager.v1.SecretManagerService.SetIamPolicy" AND protoPayload.resourceName:"seclab-db-password"' --freshness=30m --limit=1 --format="value(timestamp,protoPayload.methodName)"2026-11-19T08:39:57.856960396Z google.cloud.secretmanager.v1.SecretManagerService.SetIamPolicyQ6. Which firewall rules expose machines to the whole internet?
Answer: look for ingress rules with source 0.0.0.0/0, especially for SSH (22) and RDP (3389). Prefer no public IPs, and SSH through IAP (Identity-Aware Proxy) from Google's range 35.235.240.0/20 only.
Proof: we list them (we did not change them in this lab):
# Q6. Which firewall rules let the whole internet (0.0.0.0/0) reach SSH or RDP? (we only list them here)
gcloud compute firewall-rules list --format="table(name,network.basename(),direction,sourceRanges.list(),allowed[].map().firewall_rule().list())" | awk 'NR == 1 || (/0[.]0[.]0[.]0[/]0/ && /INGRESS/)'NAME NETWORK DIRECTION SOURCE_RANGES ALLOW
default-allow-icmp default INGRESS 0.0.0.0/0 icmp
default-allow-rdp default INGRESS 0.0.0.0/0 tcp:3389
default-allow-ssh default INGRESS 0.0.0.0/0 tcp:22The default network that new projects get allows SSH and RDP from anywhere. That is fine for a first test, and a finding in any real audit: delete these rules or limit them, and use IAP.
Q7. How do you know a VM booted what it should?
Answer: Shielded VM: secure boot only runs signed boot software, the virtual TPM measures the boot, and integrity monitoring compares each boot with a known-good baseline. And give VMs no public IP unless they need one.
Proof:
# Q7. Is the VM protected at boot? Shielded VM: secure boot, measured boot (vTPM), integrity monitoring
gcloud compute instances describe sec-vm --zone=us-east1-b --format="value(shieldedInstanceConfig.enableSecureBoot,shieldedInstanceConfig.enableVtpm,shieldedInstanceConfig.enableIntegrityMonitoring)" | awk '{print "secure boot " $1 ", vTPM " $2 ", integrity monitoring " $3}'
echo "public IP: '$(gcloud compute instances describe sec-vm --zone=us-east1-b --format='value(networkInterfaces[0].accessConfigs[0].natIP)')'"secure boot True, vTPM True, integrity monitoring True
public IP: ''
Clean up (delete everything)
# Clean up: VM, secret, service account, bucket
gcloud compute instances delete sec-vm --zone=us-east1-b --quiet 2>&1 | tail -1
gcloud secrets delete seclab-db-password --quiet 2>&1 | tail -1
gcloud iam service-accounts delete sec-reader@$PROJECT_ID.iam.gserviceaccount.com --quiet 2>&1 | tail -1
gcloud storage rm -r gs://seclab-$(echo -n $PROJECT_ID | md5sum | cut -c1-8) --quiet > /dev/null 2>&1; echo "buckets left from this lab: $(gcloud storage ls 2>/dev/null | grep -c seclab-)"Deleted [https://www.googleapis.com/compute/v1/projects/your-project-id/zones/us-east1-b/instances/sec-vm].
Deleted secret [seclab-db-password].
deleted service account [sec-reader@your-project-id.iam.gserviceaccount.com]
buckets left from this lab: 0Quick answers to remember
| Question | One-line answer | Proved in |
|---|---|---|
| Least privilege | Own account per workload, roles on the smallest resource | Q1 |
| Secrets | Secret Manager, access per secret, never in code | Q2 |
| Public buckets | Public access prevention + uniform access | Q3 |
| Service account keys | Avoid; use short-lived tokens or federation | Q4 |
| Who changed what | Cloud Audit Logs, Admin Activity always on | Q5 |
| Internet exposure | Find 0.0.0.0/0 on 22 and 3389; use IAP | Q6 |
| Trusted boot | Shielded VM, no public IP | Q7 |
What next
- Build a database the secure way: Cloud SQL for PostgreSQL: Create, Connect and Back Up.
- Lock down Linux itself: Linux Users, Groups and sudo Explained.
- More hands-on posts: ByteBlog. Practice in ByteLabs and see the courses.
Prepared by the CareerByteCode Team from our tested lab, with AI help for the write-up.
⭐ Keep learning with CareerByteCode
Hand-picked to go deeper on this topicGet CareerByteCode Team's next blog by email
One email a week when they publish. Add the weekly Best of ByteBlog too. No spam, unsubscribe with one click.
We email you once to confirm. By subscribing you agree to the privacy policy.
Related blogs
CareerByteCode TeamNetworking Interview Questions for Cloud Engineers, Proved in Labs
What you build: 10 cloud networking interview answers, each proved on Google Cloud: CIDR, Cloud NAT, firewall priority, DNS, TLS and routes. Every step tested.
#bigquery
CareerByteCode TeamSpanner Free Trial: Global SQL Database Hands-On
What you build: a free trial Cloud Spanner instance with interleaved tables, real duplicate and orphan errors, a unique index, a Python app saving an order and points in one transaction, and a stale r
#beginners
CareerByteCode TeamGoogle Cloud IAM for Beginners: Roles, Members and Least Privilege
What you build: a project where each person has only what they need, in your own Google Cloud account. Every step, command and screenshot explained for beginners.
#finops
CareerByteCode TeamSRE Interview Questions Answered with Hands-On Labs
What you build: 8 SRE interview answers proved on one Linux VM: error budgets, burn rate, p99, load average, OOM, a full disk, restart vs reload. Every step tested.
💬 Comments (0)
Top · NewestSign in to comment