tensorflow / tensorflow/cloud

Allow passing in Google Cloud Credentials (instead of application default credentials)

Open
#51 1 comment 0 reactions 1 assignee View on GitHub

@pavithrasv is already working on this.

Since Aug 18, 2020.

bug
Dominant language
Python
Stars
383
Forks
93
Avg merge
1d 3h
Merged PRs (30d)
1

Description

Kaggle Notebooks supports integrations with several Google Cloud services by authenticating the user via OAuth and providing a credentials object (for example https://www.kaggle.com/product-feedback/163416).

We'd like to provide support for tensorflow_cloud on Kaggle using user's existing auth via this mechanism. One way to do that would be allowing the library to have a credential object passed in on initialization (like other Google Cloud client libraries).

Another approach, which I've sort of hacked together below[1] is to take the credential object and write it to the filesystem as the GOOGLE_APPLICATION_CREDENTIALS file. This actually works and is implemented by the google_auth library but it always returns a None project id (https://github.com/googleapis/google-auth-library-python/blob/9058f1fea680613d9717a62ee37dc294c11b9c8a/google/auth/_default.py#L126) so tensorflow_cloud throws an error: https://github.com/tensorflow/cloud/blob/dd5c18856fcae4948f638392488e94adce90577f/tensorflow_cloud/gcp.py#L27. Would it be possible to support this approach, but have another mechanism to pass in the project id, in a constructor for example?

Is there any constraint that disallows using user credentials (and requires service accounts to be used)?

[1]

import json
import os
from kaggle_secrets import UserSecretsClient
user_secrets = UserSecretsClient()
user_credential = user_secrets.get_gcloud_credential()
with open('/tmp/key.json', 'w', encoding='utf-8') as f:
    f.write(str(user_credential))
os.environ['GOOGLE_APPLICATION_CREDENTIALS']="/tmp/key.json"
!gcloud config set project vimota-project2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.