io.grpc.StatusRuntimeException: PERMISSION_DENIED: User not authorized to perform this action

后端 未结 1 1047
春和景丽
春和景丽 2020-12-22 01:47

I try to implement simple example of spring cloud config + spring cloud bus.

So I\'ve implemented

  1. Client server application
相关标签:
1条回答
  • 2020-12-22 02:09

    I notice in the error message that you need the access to create a new topic:

    Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed
            at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57) ~[gax-1.49.1.jar:1.49.1]
            at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112) ~[gax-1.49.1.jar:1.49.1]
            at com.google.cloud.pubsub.v1.TopicAdminClient.createTopic(TopicAdminClient.java:256) ~[google-cloud-pubsub-1.101.0.jar:1.101.0]
            at com.google.cloud.pubsub.v1.TopicAdminClient.createTopic(TopicAdminClient.java:203) ~[google-cloud-pubsub-1.101.0.jar:1.101.0]
            at org.springframework.cloud.gcp.pubsub.PubSubAdmin.createTopic(PubSubAdmin.java:107) ~[spring-cloud-gcp-pubsub-1.2.1.RELEASE.jar:1.2.1.RELEASE]
            at org.springframework.cloud.gcp.stream.binder.pubsub.provisioning.PubSubChannelProvisioner.makeSureTopicExists(PubSubChannelProvisioner.java:121) ~[spring-cloud-gcp-pubsub-stream-binder-1.2.1.RELEASE.jar:1.2.1.RELEASE]
            at org.springframework.cloud.gcp.stream.binder.pubsub.provisioning.PubSubChannelProvisioner.provisionProducerDestination(PubSubChannelProvisioner.java:63) ~[spring-cloud-gcp-pubsub-stream-binder-1.2.1.RELEASE.jar:1.2.1.RELEASE]
            at org.springframework.cloud.gcp.stream.binder.pubsub.provisioning.PubSubChannelProvisioner.provisionProducerDestination(PubSubChannelProvisioner.java:45) ~[spring-cloud-gcp-pubsub-stream-binder-1.2.1.RELEASE.jar:1.2.1.RELEASE]
            at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:174) ~[spring-cloud-stream-2.1.0.RELEASE.jar:2.1.0.RELEASE]
            at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:93) ~[spring-cloud-stream-2.1.0.RELEASE.jar:2.1.0.RELEASE]
            at org.springframework.cloud.stream.binder.AbstractBinder.bindProducer(AbstractBinder.java:139) ~[spring-cloud-stream-2.1.0.RELEASE.jar:2.1.0.RELEASE]
            at org.springframework.cloud.stream.binding.BindingService.lambda$rescheduleProducerBinding$2(BindingService.java:267) ~[spring-cloud-stream-2.1.0.RELEASE.jar:2.1.0.RELEASE]
            at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
            ... 7 common frames omitted
    Caused by: io.grpc.StatusRuntimeException: PERMISSION_DENIED: User not authorized to perform this action
    

    First, I'd like to clarify:

    1. How you pass your credentials? The following snippets will show how you can set a service account authentication:
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(<Service-account-as-string>.getBytes());
    CredentialsProvider credentialsProvider =
          FixedCredentialsProvider.create(
              ServiceAccountCredentials.fromStream(byteArrayInputStream));
    
    
    TopicAdminSettings.Builder topicAdminBuilder = TopicAdminSettings.newBuilder();
    if (credentialsProvider != null) {
      topicAdminBuilder.setCredentialsProvider(credentialsProvider);
    }
    TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminBuilder.build());
    
    1. If you're using service account, you can check whether your service account is allowed to create a new topic.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题