Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default credential for app engine project accessing google cloud storage?

I have an app engine project, I want to access my google cloud storage default bucket. The first step of getting a Credential object fails, doing the following on a live instance:

Credential creds = GoogleCredential.getApplicationDefault();

The exception message I get:

"The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information."

The doc here says that production app engine projects should have access to the default credentials?:

https://developers.google.com/identity/protocols/application-default-credentials

"3. If you are running in Google App Engine production, the built-in service account associated with the application will be used."

Is there some setup I'm missing?

My app engine version (gradle):

com.google.appengine:appengine-java-sdk:1.9.18

and google cloud storage lib version:

com.google.apis:google-api-services-storage:v1-rev35-1.20.0

Thanks

like image 734
user1219278 Avatar asked Jun 22 '15 14:06

user1219278


People also ask

What is application default credentials in GCP?

Application Default Credentials (ADC) ADC is a strategy used by Cloud Client Libraries and Google API Client Libraries to automatically find credentials based on the application environment, and use those credentials to authenticate to Google Cloud APIs.

Where are Google application credentials stored?

Credentials are stored in two files: access_tokens. db and credentials. db in that directory. Both files are an SQLite database.

How do I get Google Cloud credentials?

Open the Google Cloud Platform Console Credentials page. If it's not already selected, select the project that you're creating credentials for. To set up a new service account, click New credentials and then select Service account key. Choose the service account to use for the key.


1 Answers

Go to Google Developers Console -> Credentials and create a default service account .json key. When you do that, it will download a file like default-account-credentials.json for you. You must then put that file somewhere in your app engine project. This file will be referenced when you call

Credential creds = GoogleCredential.getApplicationDefault();

However, before that works you must set the environmental variable to that files location. To do that open up your appengine-web.xml file and put this line into it:

<env-variables>
            <env-var name="GOOGLE_APPLICATION_CREDENTIALS"
                value="WEB-INF/default-account-credentials.json" />
        </env-variables>

Where value is the path to your .json creds file you just downloaded.

Now it will work. (your gradle imports are fine)

like image 126
Micro Avatar answered Oct 18 '22 01:10

Micro