Failed to load default credentials? (Node.js Google Compute Engine)

SITUATION:

I follow this guide: https://cloud.google.com/nodejs/tutorials/bookshelf-on-compute-engine

Everything works fine until I npm startand npm startto:

HTTP: // local: 8080

The following text met me on a blank page:

Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.

Which does not make sense since I am using OAuth. I followed the link and read the page, but I don’t have a field anywhere GOOGLE-APPLICATION-CREDENTIALSand there is nothing about it in the textbook.


QUESTION:

Could you please reproduce the steps and tell me if you get the same result?

(takes 5 minutes)

If not, then what could I do wrong?

+26
8

, . , Google Cloud Platform . , , , .

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

, : gcloud auth application-default login

, gcloud auth application-default login : https://cloud.google.com/sdk/install 1) SDK 2) 3) Gmail, !

, .

+86

2 . , , gcloud auth application-default login

- GOOGLE_APPLICATION_CREDENTIALS. , . , :

API.

.

" " " ", .

" " .

JSON, . .

*.json, , .

( - ), -.

GOOGLE_APPLICATION_CREDENTIALS JSON.

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

+11

, gcloud beta auth application-default login ( ).

Google Compute Engine, Compute Engine (cloud-platform ), API- Google Cloud Platform .

+5
  1. json. https://console.cloud.google.com/apis/credentials/serviceaccountkey

  2. ENV

    GOOGLE_APPLICATION_CREDENTIALS = "<PATH_TO_SERVICE_ACCOUNT_JSON_FILE>"

:

GOOGLE_APPLICATION_CREDENTIALS=/Users/hello/Documents/ssh/my-10ebbbc8b3df.json
+5

, . : - .

const serviceAccount = require('../key.json');
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount)
});
+1

: https://firebase.google.com/docs/admin/setup#initialize_the_sdk , . :

 set GOOGLE_APPLICATION_CREDENTIALS=C:\YOUR-PATH\YOUR-KEY.json
+1

CI/CD :

.

gcloud auth application-default login gcloud auth application-default login json , $GOOGLE_APPLICATION_CREDENTIALS

, echo "export GOOGLE_APPLICATION_CREDENTIALS=${TF_VAR_gcp_service_account_file_loc}" >> $BASH_ENV ( env /). $BASH_ENV - , CircleCI, CI/CD, bash.

export GOOGLE_APPLICATION_CREDENTIALS=[path-to-service-account-json-file]

0

, . GCP, Cloud Function, Compute Engine.

. Cloud Trace

private_key, client_email projectId GCP. json .

, Cloud Trace Node.js .

credentials projectId :

: : . https://developers.google.com/accounts/docs/application-default-credentials . GoogleAuth. (/srv/node_modules/google-auth-library/build/src/auth/googleauth.js:248:31) (/srv/node_modules/google-auth-library/build/src/auth/googleauth.js: 47:23) Object.next(/srv/node_modules/google-auth-library/build/src/auth/googleauth.js:28:53) (/srv/node_modules/google-auth-library/build/src/auth/googleauth.js: 19: 58) at at process._tickDomainCallback ( /process/next_tick.js: 229: 7)

You can transfer credentialsand projectIdhow the environment variables. After configuration credentials, the projectIderror disappeared.

const tracer = require('@google-cloud/trace-agent').start({
    samplingRate: 0,
    bufferSize: 1,
    credentials: {
      client_email: process.env.CLIENT_EMAIL,
      private_key: process.env.TRACE_AGENT_ADMIN,
    },
    projectId: process.env.X_GOOGLE_GCLOUD_PROJECT || process.env.PROJECT_ID,
  });

X_GOOGLE_GCLOUD_PROJECT is a built-in environment variable for executing a cloud function

0
source

Source: https://habr.com/ru/post/1668821/


All Articles