An event-driven microservice deployed in Google Cloud needs to publish telemetry messages to a specific Cloud Pub/Sub topic named `device-telemetry-topic` in the project `iot-ingestion-prod`. The microservice should only be granted permissions to publish messages to this specific topic and must not be allowed to create topics, modify subscriptions, or access other resources in the project. Which access control configuration adheres to the principle of least privilege?
- Grant the Pub/Sub Publisher role (`roles/pubsub.publisher`) to the microservice's service account directly on the `device-telemetry-topic` resource.Answer
- BGrant the primitive Editor role (`roles/editor`) to the microservice's service account at the project level.
- CGrant the Pub/Sub Admin role (`roles/pubsub.admin`) to the microservice's service account at the parent Folder level containing the project.
- DGrant the primitive Viewer role (`roles/viewer`) to the microservice's service account at the Organization level.
Answer
Grant the predefined Pub/Sub Publisher role (`roles/pubsub.publisher`) to the microservice's service account directly on the target topic resource (`device-telemetry-topic`).
The correct approach applies the principle of least privilege by combining a specific predefined role (`roles/pubsub.publisher`) with the narrowest resource scope (the `device-telemetry-topic` topic itself). This allows message publishing while preventing access to any other resources or administrative actions.
Step-by-Step Solution
Key Concept
Principle of Least Privilege with Predefined Roles and Resource-Level IAM Bindings