A security review of a retail client's Google Cloud project finds that the Vertex AI training pipeline, a GKE scoring service and a nightly export job all run as the Compute Engine default service account with the Editor role, and a downloaded JSON key for it sits in a Kubernetes Secret. Which redesign follows Google Cloud best practice?
Show the answer and explanation
Correct answer: A, Give each workload its own service account with only the roles it needs, use Workload Identity on GKE instead of a JSON key, and keep other secrets in Secret Manager.
Explanation Cloud & GCP
Least privilege on Google Cloud comes down to three habits:
- One service account per workload, with narrow predefined roles at the smallest scope, e.g. read one bucket (
roles/storage.objectViewer) or write one BigQuery dataset. A compromise then exposes one workload's permissions, not the whole project. - No long-lived keys. Downloaded JSON keys do not expire by default, get copied into repos, images and laptops, and are a classic source of credential leaks. On GKE, Workload Identity (Workload Identity Federation for GKE) maps a Kubernetes service account to an IAM identity so Pods receive short-lived tokens automatically; Vertex AI jobs and Cloud Run services simply run as their attached service account.
- Secrets in Secret Manager (versioned, IAM-controlled, audited) rather than in env files, images or ConfigMaps.
Why the others are wrong:
- Rotating a shared key shortens the exposure window but keeps one broad identity for everything, and base64 is an encoding, not encryption.
- Per-workload accounts that all hold Editor keep the blast radius of the old design even without keys: Editor is a basic role that can change almost every resource in the project, and Google advises against basic roles in production.
- A person's user credentials give a workload that person's usually broad roles, need a long-lived refresh token stored with the job, and break when the person leaves; accountability comes from per-workload service accounts plus Cloud Audit Logs.
Interview tip: call out running workloads as the default compute service account with Editor as a known anti-pattern, and mention that an organization policy can block service-account key creation altogether.