Soru

Zorluk: OrtaCreating and Managing Service Accounts

A DevOps engineer needs to grant an external automation pipeline short-lived authorization to upload build artifacts to a Google Cloud Storage bucket in project `proj-prod` without using long-lived service account key files. The engineer decides to implement service account impersonation. What is the correct sequence of steps to configure and execute this secure delegation workflow?

  1. 1Create a dedicated user-managed service account named `[email protected]` in project `proj-prod`.
  2. 2Grant the `roles/storage.objectAdmin` role to `[email protected]` on the target Cloud Storage bucket.
  3. 3Grant the `roles/iam.serviceAccountTokenCreator` role on `[email protected]` to the calling pipeline principal identity.
  4. 4Execute the artifact upload command using `gcloud storage` with the `--impersonate-service-account=artifact-pipeline-sa@proj-prod.iam.gserviceaccount.com` flag.

Cevap

The correct order begins with creating the dedicated service account, followed by granting object administration permissions to the service account on the Cloud Storage bucket, then delegating the Service Account Token Creator role on the service account to the calling principal, and finally running the gcloud command with the --impersonate-service-account flag.
The workflow follows logical identity management dependency. First, the service account identity must be created in the project (`[email protected]`). Second, resource permissions (`roles/storage.objectAdmin`) are granted to the service account so it possesses the necessary permissions. Third, impersonation privileges (`roles/iam.serviceAccountTokenCreator`) are granted on the service account resource to the external caller identity. Finally, the external caller executes the gcloud CLI command with `--impersonate-service-account` to generate short-lived tokens dynamically.

Adım Adım Çözüm

1
Create the user-managed service account
Establishes a dedicated identity (`[email protected]`) in GCP IAM.
An identity must be instantiated in IAM before role bindings or delegation rules can target it.
2
Bind the target resource access role to the service account
Assigns `roles/storage.objectAdmin` on the destination bucket to the service account.
Defines what operations the service account is authorized to perform when active.
3
Grant Service Account Token Creator permission to the external caller
Binds `roles/iam.serviceAccountTokenCreator` on the service account resource to the principal initiating the workflow.
Allows the external caller identity to mint short-lived OAuth 2.0 access tokens for the target service account.
4
Invoke gcloud command with impersonation flag
The CLI automatically exchanges the caller's credentials for a temporary service account token and executes the storage upload operation.
Verifies end-to-end functionality using short-lived credentials without generating static private keys.

Anahtar Kavram

Service Account Creation, Permission Delegation, and Impersonation Sequence
Bu soruyu puanla