Google Cloud Storage - "Error: Could not load the default credentials"

766 views Asked by At

While developing my app in Node.js, I decided to persist my data by using the Google Cloud Storage client libraries.

I came across the error mentioned in the title when uploading to storage:

Error: Could not load the default credentials

I did some digging, and figured out how to solve the issue:

  1. Navigating to google cloud console credentials and creating a service account.

  2. Setting the role for the service account to have full object permissions across my project and my buckets

  3. Creating a key for the service account and downloading the associated .json file

  4. Installing Cloud SDK and running the commands:

    gcloud auth application-default login

    gcloud config set project [MY_PROJECT_ID]

    gcloud auth activate-service-account --key-file=C:/path/to/json/file

  5. In my code passing in the .json credentials file into my new client instance:

    const storage = new Storage({keyFileName: "auth.json"})

These steps described fixed the issue... in development. When I deployed my app to production the same error message comes back

I tried a few things to solve the issue. I assumed it was an issue with my web host: A2. After talking with their tech support they reassured me my file paths are correct inside their file structure, but they would not help me troubleshoot the credentials error otherwise.

So, why would my credentials be working just fine in development, but then suddenly stop working in production? Is it because I had the localhost as the callback URI instead of the domain name (or something)? Do I need to specify the domain somewhere in SDK or in the cloud console?

The error message points me to https://cloud.google.com/docs/authentication/getting-started, but I have read and reread the documentation many times, so if someone can point me to the specific place in the docs that says what I need to do that would be appreciated, but be aware that I have done my homework and I RTFM, but I am still unable to solve this issue.

0

There are 0 answers