Skip to content

DefaultCredentialsError (only sometimes) in Google Compute Engine with docker #2995

Closed
@gjanvier

Description

Hello,

I run a python script hourly, embedded in a docker container hosted on a Google Compute Engine instance. That script includes a step where I use python lib google.cloud.storage to upload files in google storage.

I want to use the default service account of the compute engine instance. As written in the doc, authentication should “just work”. And most of the time it does.

Yet I quite often get the error:
File "/usr/local/lib/python2.7/dist-packages/google/auth/_default.py", line 282, in default raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credential and re-run the application. For more information, please see https://developers.google.com/accounts/docs/application-default-credentials.

My code:

import google.auth
from google.cloud import storage
...
credentials, projectId = google.auth.default()
# Next line raises sometimes the exception
client = storage.Client(projectId, credentials=credentials)
...

When I run a python CLI from that same docker container, and call the credentials, projectId = google.auth.default(), I can see that the credentials are a google.auth.compute_engine.credentials.Credentials object, so I guess that the "magic" works even in a container (the doc does not explain how it works though).

Any explanation on how to make it work, using the service account from the host compute instance ?

My env:

  • OS: ubuntu:16:04 (compute instance and docker instance)
  • python 2.7.12
  • google-cloud-storage==0.22.0, google-auth==0.5.0

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions