CareerByteCode
ByteBlogby CareerByteCode

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.

Cloud Security Interview Questions with Hands-On Labs

✍️ 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.

🧪⭐ Recommended by CareerByteCode · ByteLabs project bundleCloud and DevOps Realtime Starterโ‚น499Build the projects →

The lab behind the answers

The lab
sec-vm runs as sec-reader, which may only read objects in one private bucket; a secret in Secret Manager; audit logs record every change

One setup step creates everything:

  • a private bucket with uniform access and public access prevention, holding one file;
  • a service account sec-reader with Storage Object Viewer on that one bucket only;
  • a secret seclab-db-password with a random value that is never printed;
  • sec-vm: no public IP, Shielded VM secure boot on, running as sec-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
The setup
A private bucket with one file, the sec-reader account, a secret and sec-vm

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 -1
who am I: sec-reader@...
report for the auditors
does not have storage.objects.create access

Q2. 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 -1
PERMISSION_DENIED

Fix 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 30
Updated IAM policy for secret [seclab-db-password].
roles/secretmanager.secretAccessor

The 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
Least privilege and secrets
sec-reader can read but not write the bucket; the secret is refused, then readable after a grant on that one secret

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	True

Refused 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.SetIamPolicy

Q6. 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:22

The 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: ''
Exposure checks
Public access refused, 0 user keys, the IAM change in the audit log, rules open to 0.0.0.0/0, Shielded VM on and no 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: 0

Quick answers to remember

QuestionOne-line answerProved in
Least privilegeOwn account per workload, roles on the smallest resourceQ1
SecretsSecret Manager, access per secret, never in codeQ2
Public bucketsPublic access prevention + uniform accessQ3
Service account keysAvoid; use short-lived tokens or federationQ4
Who changed whatCloud Audit Logs, Admin Activity always onQ5
Internet exposureFind 0.0.0.0/0 on 22 and 3389; use IAPQ6
Trusted bootShielded VM, no public IPQ7

What next

Prepared by the CareerByteCode Team from our tested lab, with AI help for the write-up.

Read next →Networking Interview Questions for Cloud Engineers, Proved in Labs⏱ 11 min

⭐ Keep learning with CareerByteCode

Hand-picked to go deeper on this topic
News, guides and updates from the CareerByteCode team
🏅 Expert writer

The CareerByteCode team writes about what is new on careerbytecode.in: courses, labs, exams, events and the community, which is free to join for influencers and content creators in tech.

Get 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.

💬 Comments (0)

Top · Newest

Sign in to comment

Related blogs

🧪⭐ Recommended by CareerByteCode · ByteLabs project bundleCloud and DevOps Realtime Starterโ‚น499Build the projects →