A cloud engineer needs to configure a running Compute Engine VM instance to securely read objects from a Cloud Storage bucket using a dedicated user-managed service account following Google Cloud security best practices. In what order should the engineer execute the following steps to complete this configuration using `gcloud` CLI tools?
- 1Create a dedicated user-managed service account named `app-processor-sa` in the project using `gcloud iam service-accounts create`.
- 2Grant the `roles/storage.objectViewer` role to `app-processor-sa` on the target Cloud Storage bucket using `gcloud storage buckets add-iam-policy-binding`.
- 3Stop the running Compute Engine VM instance using `gcloud compute instances stop`.
- 4Attach `app-processor-sa` to the VM instance using `gcloud compute instances set-service-account` with the `cloud-platform` scope.
- 5Start the Compute Engine VM instance using `gcloud compute instances start`.
Answer
The correct order of steps is: 1) Create the user-managed service account, 2) Grant the required IAM storage role on the bucket, 3) Stop the Compute Engine instance, 4) Attach the service account with the cloud-platform scope, and 5) Start the instance.
The proper sequence begins by provisioning the identity via IAM service-accounts create, binding the least-privilege predefined storage role to the bucket, stopping the VM instance, applying the new service account identity with full API access scopes using gcloud compute instances set-service-account, and finally starting the instance to enable metadata server token retrieval.
Step-by-Step Solution
Key Concept
Creating and Attaching User-Managed Service Accounts to Compute Instances