A Cloud Engineer is configuring IAM permissions for a dedicated service account used by a Cloud Function. The function must pull messages from a specific Cloud Pub/Sub subscription and upload processed results into a specific Cloud Storage bucket. Following the principle of least privilege, which two IAM role assignments should be granted to the service account?
- Grant the Pub/Sub Subscriber role (roles/pubsub.subscriber) scoped directly to the target Pub/Sub subscription.Answer
- Grant the Storage Object Creator role (roles/storage.objectCreator) scoped directly to the target Cloud Storage bucket.Answer
- CGrant the primitive Editor role (roles/editor) at the Cloud Project level to cover both Pub/Sub and Storage access.
- DGrant the Storage Admin role (roles/storage.admin) at the Organization level so that permissions inherit down to the bucket.
Answer
Grant the Pub/Sub Subscriber role (roles/pubsub.subscriber) scoped to the specific subscription, and grant the Storage Object Creator role (roles/storage.objectCreator) scoped to the specific Cloud Storage bucket.
To adhere to the principle of least privilege, access must be limited to predefined roles that grant only the required permissions, bound directly to the target resources (the specific Pub/Sub subscription and Cloud Storage bucket). The Pub/Sub Subscriber role on the subscription allows pulling messages, while the Storage Object Creator role on the bucket permits writing output objects without granting read, list, or deletion capabilities.
Step-by-Step Solution
Key Concept
Applying Least Privilege via Predefined Roles and Fine-Grained Resource Scope Binding