cis
cis

Reputation: 1377

Giving GCP service account Pub/Sub rights for topic in different project

I have a Node.js service running in GCP VM, running as a service account. Now I want to subscribe to a Pub/Sub topic. The Service account and the VM belong to Project A, the topic belongs to Project B.

I'm always getting Error: 7 PERMISSION_DENIED: User not authorized to perform this action.

What I have tried:

enter image description here

enter image description here

But still, the error is the same.

(Side note: If a GCP manager reads this: The GCP logs don't show any details. That's not helpful in this case. If you need four permissions to run something then I expect the logs to be like You need 4 permissions, your user has permission A, C, D, but lacking B and not just User not authorized to perform this action.)

Upvotes: 0

Views: 2916

Answers (2)

Ben Hu
Ben Hu

Reputation: 43

What's your error? Is the error from "trying to create a subscription", or "trying to connect to a subscription and consume message"?

The former needs more permissions than Subscriber: projects.subscriptions.create

Subscriber can only consumer message, but not creating a new subscription: https://cloud.google.com/pubsub/docs/access-control#pubsub.subscriber

Upvotes: 0

al-dann
al-dann

Reputation: 2725

can you try my-project-b with a service accont from the my-project-a -

slightly modified your code:

gcloud projects add-iam-policy-binding my-project-b --member="serviceAccount:[email protected]" --role='roles/pubsub.subscriber'

and so on...

Upvotes: 1

Related Questions