Service Account Key vs Workload Identity Federation for least‑privilege VM access to a single Cloud Storage bucket
0 reputation · 10 May 2021, 12:19 UTC
0 reputation · 10 May 2021, 12:19 UTC
The goal is to grant a Compute Engine VM read‑only access to a single Cloud Storage bucket while adhering to least‑privilege principles. Two documented approaches are available: (1) create a service account, download its JSON key file, and attach the key to the VM; (2) configure Workload Identity Federation so the VM obtains short‑lived OAuth tokens from an external identity provider without storing any long‑lived secret.
The key‑file method is simple to set up but introduces a long‑lived credential that must be rotated manually, raising the risk of stale keys if rotation lapses. The federation method issues tokens that expire after a short period and are bound to the workload identity, yet the exact inactivity window and revocation propagation delay for OAuth refresh tokens and impersonation tokens are not uniformly documented across Google APIs, leaving operators uncertain how quickly access is cut off after a credential is revoked.
Which approach better satisfies the requirement to avoid storing long‑lived secrets while ensuring timely revocation of access? What is the maximum acceptable delay for revocation propagation when using workload identity federation? How does the absence of built‑in expiry for service account keys affect operational overhead compared with federation?
33775 reputation · 10 May 2021, 14:49 UTC
For a Compute Engine VM that needs read-only access to a single Cloud Storage bucket, Workload Identity Federation is the approach that avoids storing long-lived secrets. A service account key attached to the VM is a long-lived credential that must be managed manually. Federation issues short-lived OAuth access tokens bound to the workload identity, so no JSON key is stored on the VM.
Confirmed facts:
Likely explanation, marked for review:
Service account key:
Workload Identity Federation:
[contact removed].roles/storage.objectViewer on the specific bucket, not project-wide.roles/iam.workloadIdentityUser on the service account to the pool principal. Remove any existing key files from the VM.Missing diagnostic detail that changes the recommendation: Does the VM have outbound HTTPS egress to the federation token endpoint and the Google OAuth token endpoint? If egress is blocked, federation cannot obtain tokens and a key-based approach would be required. Confirm network egress before committing to federation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.