Problem with authentication to pubsub with subscriber (Java pubsub client, publish works)

1,715 views
Skip to first unread message

Jaap Mulder

unread,
Apr 5, 2019, 11:06:16 AM4/5/19
to Google Cloud Pub/Sub Discussions


Hi,

I fear that I have come across a bug. Since last week subscriptions don't work with the Java client. I didn't change my code...

This is the configuration (with older versions if failed, so I updated to the very latest jar files, but no success):

    <groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>1.69.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>1.69.0</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>0.15.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.28.0</version>
</dependency>

I get the following error:

Apr 05, 2019 4:08:33 PM com.google.cloud.pubsub.v1.StreamingSubscriberConnection$1 onFailure
SEVERE: terminated streaming with exception
com.google.api.gax.rpc.UnauthenticatedException: com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.


I did not change any code. I tried updating to the version of the used libraries. They are at the very latest.

I have the following code:

Credentials credentials = null;
try {
credentials = ServiceAccountCredentials.fromStream(new FileInputStream(KEYFILE));

} catch (IOException e) {
logger.error("Could not import Google Pubsub json credentials: {}" + "\n" + e.getMessage());
}
CredentialsProvider credentialsProvider = FixedCredentialsProvider.create( credentials );

try {
// create a subscriber bound to the asynchronous message receiver
logger.info("Subscription name: " + DOWNSTREAM_SUBSCRIPTION_ID);

subscriber =
Subscriber.newBuilder(subscriptionName, new MessageReceiverExample())
//.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.setCredentialsProvider(credentialsProvider)
.build();
subscriber.startAsync().awaitRunning();
//subscriber.awaitTerminated();

// Continue to listen to messages


Even not using a token, so not using setCredentialProvider at all and using the account I am logged in with in gcloud, does not work:

Apr 05, 2019 4:37:03 PM com.google.auth.oauth2.DefaultCredentialsProvider warnAboutProblematicCredentials
WARNING: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/.

The correct warning is shown that I shall use a service account token. However, when I put something on the topic, the subscriber fails again:

java.util.concurrent.ExecutionException: com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:552)
at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:533)

Does anybody get the same issues? Do I use the library in a wrong way?

Best regards,

Jaap

George (Cloud Platform Support)

unread,
Apr 10, 2019, 2:31:47 PM4/10/19
to Google Cloud Pub/Sub Discussions
Hello Jaap, 

There is no related bug or outage in Pub/Sub. What libraries did you update, and how? 

In any case, this issue needs more attention, and systematic follow-up. This is not possible here, so I encourage you to open an issue in the Public Issue Tracker, with similar contents. 

This discussion group is oriented more towards general opinions, trends, and issues of general nature touching the app engine. For coding and programming architecture, as well as update-related errors, you may be better served in dedicated forums such as stackoverflow, where experienced programmers are within reach and ready to help.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages