Repository navigation
test(storage): grant only the storage service agent publish access in ITNotificationTest - #15386
Conversation
… ITNotificationTest ITNotificationTest gave roles/owner on its Pub/Sub topic to allAuthenticatedUsers. The CI project no longer allows that grant, so every test in the class fails in setup. Grant roles/pubsub.publisher to the project's Cloud Storage service agent instead. That is the only access Cloud Storage needs to publish notifications to the topic.
There was a problem hiding this comment.
Code Review
This pull request updates the IAM policy binding in ITNotificationTest.java to restrict access to the Pub/Sub topic. Instead of granting the broad roles/owner role to allAuthenticatedUsers, it now correctly grants the specific roles/pubsub.publisher role only to the project's Cloud Storage service agent. There are no review comments, and I have no feedback to provide.
nidhiii-27
left a comment
There was a problem hiding this comment.
LGTM, thanks! Granting roles/pubsub.publisher to just the GCS service agent is the right least-privilege setup.
Non-blocking follow-up: java-storage/samples/snippets/src/test/java/com/example/storage/bucket/PubSubNotificationTest.java (L84-90) still grants roles/owner and falls back to allAuthenticatedUsers when GOOGLE_CLOUD_PROJECT_NUMBER is unset. The same org policy will likely reject it, so it could use the same fix, e.g.:
String member = "serviceAccount:" + storage.getServiceAccount(GOOGLE_CLOUD_PROJECT).getEmail();
Binding binding = Binding.newBuilder().setRole("roles/pubsub.publisher").addMembers(member).build();Happy for that to land in a separate PR.
ITNotificationTest gave roles/owner on its Pub/Sub topic to allAuthenticatedUsers. The CI project no longer allows that grant, so every test in the class fails in setup.
Grant roles/pubsub.publisher to the project's Cloud Storage service agent instead. That is the only access Cloud Storage needs to publish notifications to the topic.