Skip to content

Getting project ID using Application Default Credentials fails when gcloud command writes anything to stderr #673

@andytheapedemontague

Description

@andytheapedemontague
  • OS: Ubuntu 20.04
  • Python version: 3.8
  • pip version: 20.0.2
  • google-auth version: 1.19.2

Steps to reproduce

  1. Arrange for gcloud to throw a warning. For example I'm suffering from this "Old version of cryptography" warning when using gsutil installed from snap GoogleCloudPlatform/gsutil#999
  2. Attempt to use ADC e.g. credentials, project = google.auth.default()
  3. Note that project always comes back at None even if gcloud config set project is correctly set
  4. Root cause seems to be that in _cloud_sdk.py/get_project_id() the subprocess.check_output command merges stderr and stdout. So in the case that stderr is not empty and the subprocess does not fail, you might get badly formed JSON on which json.loads a few lines later chokes.

For example, my raw gcloud output is like:

/snap/google-cloud-sdk/165/lib/third_party/requests/init.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.\n warnings.warn(warning, RequestsDependencyWarning)\n{\n "configuration": {\n "active_configuration": "default",\n "properties": {\n "core": {\n "account": "me@myemailaddress.com",\n "disable_usage_reporting": "False",\n "project": "my-test-project"\n },\n "deployment_manager": {\n "glob_imports": "True"\n }\n }\n },\n "credential": {\n "access_token".... etc etc.

Expected behaviour: non-fatal errors or warnings from gcloud should not corrupt the output and cause the project ID lookup to fail.

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions