Skip to content

pubsub permission question regarding getTopic and getSubscription #1376

Description

@fondberg

We would like to have a service account with access only to subscribe to a topic and not t to publish or create anything else than create its subscription on one topic if the subscription doesn't exists.

Given the code below what is needed to get it to work without granting access to the actual project?

  private static void ensureTopicAndSubscriptionExist(
      PubSub pubsub, String topic, String subscription) {
   
    if (pubsub.getTopic(topic) == null) {
      throw new IllegalStateException("Topic does not exist: " + topic);
    }
   
    if (pubsub.getSubscription(subscription) == null) {
      LOG.info("creating PubSub subscription={} for topic={}", subscription, topic);
      pubsub.create(SubscriptionInfo.of(topic, subscription));
      LOG.info("created PubSub subscription={} for topic={}", subscription, topic);
    }
  }

We only get this to work if the service account user has edit rights on the project

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions