Skip to content

test(storage): grant only the storage service agent publish access in ITNotificationTest - #15386

Merged
Dhriti07 merged 1 commit into
mainfrom
storage-notification-test-topic-iam
Dec 2, 2026
Merged

Dhriti07 merged 1 commit into
mainfrom
storage-notification-test-topic-iam

Conversation

@Dhriti07

@Dhriti07 Dhriti07 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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.

… 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.
@Dhriti07
Dhriti07 requested a review from nidhiii-27 December 2, 2026 08:25
@Dhriti07
Dhriti07 marked this pull request as ready for review December 2, 2026 08:25
@Dhriti07
Dhriti07 requested review from a team as code owners December 2, 2026 08:25

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nidhiii-27 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Dhriti07
Dhriti07 merged commit 06639c9 into main Dec 2, 2026
197 checks passed
@Dhriti07
Dhriti07 deleted the storage-notification-test-topic-iam branch December 2, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants