Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultCredentialsProvider is broken for java8 app engine #228

Closed
igorbernstein2 opened this issue Feb 27, 2019 · 18 comments · Fixed by #230
Closed

DefaultCredentialsProvider is broken for java8 app engine #228

igorbernstein2 opened this issue Feb 27, 2019 · 18 comments · Fixed by #230
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@igorbernstein2
Copy link
Contributor

This was reported by a bigtable customer:

I've traced through where it fails. In DefaultCredentialsProvider.getDefaultCredentialsUnsynchronized() it will only return the AppEngine credentials if the following evaluates to true:

this.isOnGAEStandard7()

I am on GAE Standard but am using Java 8 not 7, so this check is false and it does not return any valid credentials.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Feb 28, 2019
@sduskis
Copy link
Contributor

sduskis commented Feb 28, 2019

If you look farther down, you'll see this:

    // Then try Compute Engine and GAE 8 standard environment
    if (credentials == null) {
      credentials = tryGetComputeCredentials(transportFactory);
    }

@sduskis sduskis added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Feb 28, 2019
@sduskis
Copy link
Contributor

sduskis commented Feb 28, 2019

@neozwu, do you have any thing to add to this issue?

@romulets
Copy link

romulets commented Mar 8, 2019

I'm having the same problem. Although it falls in this condition the method tryGetComputeCredentials is also returning null.

I'm using AppEngine with Java 8

@sduskis
Copy link
Contributor

sduskis commented Mar 8, 2019

@ajaaym, can you please have someone take a look at this?

@sduskis sduskis added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed type: question Request for information or clarification. Not an issue. labels Mar 8, 2019
@ajaaym
Copy link
Contributor

ajaaym commented Mar 8, 2019

@romulets can you please check whether you have this env variable set GCE_METADATA_HOST to "http://metadata.google.internal"? If not can you set that? In mean time I will create a PR to update default metadata url.

@romulets
Copy link

romulets commented Mar 8, 2019

I didn't work :/

I configured the environment variable through appengine-web.xml using the following tag:

    <env-variables>
        <env-var name ="GCE_METADATA_HOST" value="metadata.google.internal"/>
    </env-variables>

I got the error

com.google.auth.oauth2.ComputeEngineCredentials runningOnComputeEngine: Failed to detect whether we are running on Google Compute Engine. (ComputeEngineCredentials.java:203)
java.net.UnknownHostException: DNS host lookup failed for URL: http://metadata.google.internal

Is this host available? I think it should be internal host of google, so I can't be sure it's up

@ajaaym
Copy link
Contributor

ajaaym commented Mar 8, 2019

@romulets are you running on GCP?

@romulets
Copy link

romulets commented Mar 8, 2019

Yes, AppEngine GCP

@ajaaym
Copy link
Contributor

ajaaym commented Mar 19, 2019

@romulets are you using flexible env?

@romulets
Copy link

@ajaaym No, I'm using standard environment, java8 runtime.

@ajaaym
Copy link
Contributor

ajaaym commented Mar 19, 2019

@romulets Thanks, I tried with standard java8 runtime and its working fine with me. Is it possible to provide the sample that you are using?

@romulets
Copy link

I'm retrieving a PubSub Publisher through this code:

        Credentials credentials = GoogleCredentials.getApplicationDefault();
        CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(credentials);

        return Publisher.newBuilder(topic)
                .setCredentialsProvider(credentialsProvider)
                .build();

@ajaaym
Copy link
Contributor

ajaaym commented Mar 20, 2019

@romulets I also used pubsub publisher to test, below is my code. You dont need to provide default credential, client discovers that automatically.

ProjectTopicName topicName = ProjectTopicName.newBuilder()
        .setProject(ServiceOptions.getDefaultProjectId())
        .setTopic("topic-name")
        .build();
    Publisher publisher = Publisher.newBuilder(topicName).build();
    PubsubMessage pubsubMessage =
        PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8("test message")).build();

@romulets
Copy link

@ajaaym I wasn't providing credentials and had the same error. I don't know if it is relevant, but my project runtime was java7 and then we migrated it to java8.

Anyway, I solved my problem by providing a hard-coded service account.

@ajaaym
Copy link
Contributor

ajaaym commented Mar 20, 2019

@romulets which version of pubsub are you using?

@romulets
Copy link

@ajaaym 0.33.0-beta

@ajaaym
Copy link
Contributor

ajaaym commented Mar 20, 2019

@romulets I tried with 0.33.0-beta and it worked fine. Below is my code:

Code:

    TopicName topicName = TopicName.newBuilder()
        .setProject(ServiceOptions.getDefaultProjectId())
        .setTopic("topic-name")
        .build();
    Publisher publisher = Publisher.newBuilder(topicName).build();
    PubsubMessage pubsubMessage =
        PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8("test message")).build();

<sduskis: removed sensitve data>

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 6, 2020
@hugo-ayala
Copy link

I ended up using a hard coded service account as well. I don't have problems with other services like Cloud Storage or KMS, but PubSub was a nogo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants