Skip to content

Emulator with Anonymous Credentials is No Longer Possible #250

@alphapseudo

Description

@alphapseudo

Previously on version 1.9.0, setting the environment variable FIRESTORE_EMULATOR_HOST and providing AnonymousCredentials allowed the transport to be established successfully.

After upgrading to 2.0.0, we are receiving a DefaultCredentialsError instead. When FIRESTORE_EMULATOR_HOST is set, the credentials provided to the client are no longer respected.

Environment details

Running an instance of the Firestore emulator inside of a Docker container

  • OS type and version: CentOS 7.5
  • Python version: 3.8
  • pip version: 20.2
  • google-cloud-firestore version: 2.0.0
  • google-auth version: 1.23.0

Steps to reproduce

  1. Set FIRESTORE_EMULATOR_HOST environment variable e.g. FIRESTORE_EMULATOR_HOST=emulator_host:8200
  2. Instantiate a new Firestore client by providing AnonymousCredentials
  3. Execute an example query/request using this client

Code example

# e.g. export FIRESTORE_EMULATOR_HOST=emulator_host:8200

from google.auth.credentials import AnonymousCredentials
from google.cloud.firestore import Client

credentials = AnonymousCredentials()
client = Client(project="my-project", credentials=credentials)

product = db.collection("products").document("product_abcd").get()

print(product)

Stack trace

File "/pyenv/versions/test-app/lib/python3.8/site-packages/google/cloud/firestore_v1/document.py", line 359, in get
  firestore_api = self._client._firestore_api
File "/pyenv/versions/test-app/lib/python3.8/site-packages/google/cloud/firestore_v1/client.py", line 104, in _firestore_api
  return self._firestore_api_helper(
File "/pyenv/versions/test-app/lib/python3.8/site-packages/google/cloud/firestore_v1/base_client.py", line 152, in _firestore_api_helper
  channel = transport.create_channel(host=self._emulator_host)
File "/pyenv/versions/test-app/lib/python3.8/site-packages/google/cloud/firestore_v1/services/firestore/transports/grpc.py", line 223, in create_channel
  return grpc_helpers.create_channel(
File "/pyenv/versions/test-app/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 275, in create_channel
  composite_credentials = _create_composite_credentials(
File "/pyenv/versions/test-app/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 217, in _create_composite_credentials
  credentials, _ = google.auth.default(scopes=scopes)
File "/pyenv/versions/test-app/lib/python3.8/site-packages/google/auth/_default.py", line 356, in default
  raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)

google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

Metadata

Metadata

Labels

api: firestoreIssues related to the googleapis/python-firestore API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions