Question

Difficulty: MediumDeploying and Managing Compute Engine Virtual Machines

An organization is deploying a Compute Engine virtual machine instance named `data-worker` to process batch analytics. The application running inside `data-worker` must read files from a Cloud Storage bucket using a custom service account named `[email protected]`. To follow Google Cloud security best practices, the custom service account has been granted only the Storage Object Viewer IAM role on the bucket. Which `gcloud compute instances create` command correctly attaches the custom service account while allowing IAM roles to govern the instance's access?

  1. gcloud compute instances create data-worker --service-account=processing-sa@prod-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/cloud-platformAnswer
  2. B
    gcloud compute instances create data-worker [email protected]
  3. C
    gcloud compute instances create data-worker --provisioning-model=SPOT --instance-termination-action=DELETE
  4. D
    gcloud compute instances create data-worker --service-account=default --scopes=roles/owner

Answer

Execute gcloud compute instances create data-worker --service-account=processing-sa@prod-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/cloud-platform
When creating a Compute Engine VM with a custom service account, Google Cloud best practice requires attaching the service account via the --service-account flag and setting the scope to https://www.googleapis.com/auth/cloud-platform. This allows IAM permissions granted to that service account to serve as the effective boundary for Google Cloud API requests.

Step-by-Step Solution

1
Identify the service account flag requirement
Pass the custom service account email address to the --service-account flag.
This binds the specific service account identity to the Compute Engine VM.
2
Determine the correct access scope setting for custom service accounts
Set --scopes=https://www.googleapis.com/auth/cloud-platform.
Using the cloud-platform scope allows IAM roles assigned to the custom service account to grant and restrict API access without scope-level limitations.

Key Concept

Attaching custom service accounts and configuring access scopes during Compute Engine VM deployment
Rate this question