A security audit highlights that a Compute Engine virtual machine running an automated nightly report generator is using the default Compute Engine service account with the primitive Editor role. To comply with security mandates and the principle of least privilege, you need to reconfigure the workload to use a dedicated user-managed service account that only has access to read Cloud Storage objects and write BigQuery datasets in the project. Which sequence of steps should you take?
- ACreate a user-managed service account, grant it the broad Editor role at the project level, generate a new JSON service account key file, and save the key file inside the Virtual Machine filesystem.
- BCreate a user-managed service account, grant it the roles/storage.objectViewer and roles/bigquery.dataEditor predefined roles on the project, download its JSON key file, and pass the key to the application using environment variables.
- Create a user-managed service account, grant it the roles/storage.objectViewer and roles/bigquery.dataEditor roles at the project level, stop the VM instance, attach the new service account to the VM, and restart the instance.Answer
- DEdit the existing default Compute Engine service account policy at the instance level to deny all permissions except Cloud Storage and BigQuery, leaving the project-level Editor role intact.
Answer
Create a dedicated user-managed service account, grant it the predefined roles roles/storage.objectViewer and roles/bigquery.dataEditor at the project level, stop the VM instance, attach the custom service account to the VM, and restart the instance.
The solution follows Google Cloud security best practices by replacing the default service account with a custom user-managed service account, granting minimal predefined roles (roles/storage.objectViewer and roles/bigquery.dataEditor), and attaching the service account directly to the Compute Engine instance so the application uses automatic metadata credentials rather than exported long-lived JSON key files.
Step-by-Step Solution
Key Concept
User-managed service accounts best practices and VM attachment