Skip to content

Add EndUserCredentials and implement get_default_google_credentials#42

Merged
mergify[bot] merged 2 commits intoEmbarkStudios:mainfrom
boulos:main
Aug 7, 2021
Merged

Add EndUserCredentials and implement get_default_google_credentials#42
mergify[bot] merged 2 commits intoEmbarkStudios:mainfrom
boulos:main

Conversation

@boulos
Copy link
Copy Markdown
Contributor

@boulos boulos commented Aug 7, 2021

As requested in #39 , I added just enough to do the full default credentials flow. I haven't tested it on Windows, but I believe :).

Note: I am intentionally ignoring App Engine Standard v1 and Cloud Functions (since Rust doesn't run there), as well as legacy gcloud ADC locations. As a surprising bonus, I learned that the golang client doesn't respect the CLOUDSDK_CONFIG environment variable (so I'll probably go contribute this back to them).

Please take a thorough look, especially if there's a cleaner way to do the enum and static dispatch stuff (and I didn't work hard on a name, since I assume we'll discuss it now).

boulos added 2 commits August 7, 2021 01:06
Along the way to support EmbarkStudios#39, we need to support the gcloud
application_default_credentials.json / EndUserCredential format. The
flow is pretty similar to a ServiceAccount, but with a couple
differences:

 - You can't specify scopes dynamically (the scopes are assigned at
   authorization time, not access token / refresh time)

 - The endpoint isn't included (but oauth2.googleapis.com/token is the
   de facto endpoint)

 - After some period of time the refresh token is invalid, and you
   need to re-run `gcloud auth application-default login` (which sadly
   isn't check-able upfront, as the file doesn't store an
   `expires_in`) field.

I tested this out manually with a build of gcsfuser that does the full
Google default credentials flow.

Next up: I'll move that logic here into tame-oauth for everyone to use.
Now that we support all three flavors of OAuth credentials (Service
Account, gcloud ADC file, and Metadata server), we can do the full
"check this, then that, then that" flow that client libraries use (as
requested in EmbarkStudios#39).

With this change, getting the right `TokenProvider` is now just a call
to get_default_google_credentials(). Then the `get_token` and
`parse_token_response` work as expected.

This change does *not* yet handle caching. I think caching should move
out of the ServiceAccount handler and into its own generic "I can
cache anything" TokenProvider (CachedTokenProvider?).
@boulos boulos requested a review from Jake-Shadle as a code owner August 7, 2021 01:38
Copy link
Copy Markdown
Member

@Jake-Shadle Jake-Shadle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'll merge this for now and probably just do some minor cleanup in a separate branch before doing a release. Thanks for another PR!

@mergify mergify bot merged commit b1c8a84 into EmbarkStudios:main Aug 7, 2021
boulos added a commit to GoogleCloudPlatform/gcsfuser that referenced this pull request Aug 10, 2021
After adding Metadata server support in [1] and an initial "do the
entire credential flow" in [2] that are in 0.6, gcsfuser now supports
auth "correctly".

I verified that on GCE the metadata server caches tokens for you, but
I'm still hoping we do [3] to avoid even issuing the http request.

[1] EmbarkStudios/tame-oauth#40

[2] EmbarkStudios/tame-oauth#42

[3] EmbarkStudios/tame-oauth#45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants