Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth.getIdTokenClient() does not honour gcloud auth application-default login #1543

Closed
mbyrne00 opened this issue Apr 27, 2023 · 5 comments
Closed
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@mbyrne00
Copy link

mbyrne00 commented Apr 27, 2023

Summary

When I test/run code locally using auth.getIdTokenClient("https://my-target-audience") will always yield the error below, despite setting application default credentials using gcloud auth application-default login. Other google libs are working fine using this.

Cannot fetch ID token in this environment, use GCE or set the GOOGLE_APPLICATION_CREDENTIALS environment variable t o a service account credentials JSON file.

  1. Is this a client library issue or a product issue?
    A client library issue.

  2. Did someone already solve this?
    No

  3. Do you have a support contract?
    No

Environment details

  • OS: MacOS
  • Node.js version: 18.14.0
  • npm version: 9.3.1
  • google-auth-library version: 8.7.0

Steps to reproduce

  1. Grant credentials with a privileged account using gcloud auth application-default login
  2. Execute the following code from somewhere in your codebase in an async function
    const auth = new GoogleAuth();
    await auth.getIdTokenClient(this.analysisBaseUrl)
    console.log("All good");
    
  3. 💥 - the following error is shown and the console log does not execute

Cannot fetch ID token in this environment, use GCE or set the GOOGLE_APPLICATION_CREDENTIALS environment variable t o a service account credentials JSON file.

If you export a JSON key and provide it via the environment variable GOOGLE_APPLICATION_CREDENTIALS then it will work. The other google libs, however, negate the need for this by supporting the application-default login and thus not needing privileged service account JSON keys stored locally.

I've also noticed others with this issue, for example when I came across this post: https://stackoverflow.com/questions/72685175/application-default-credentials-http-trigger-gcp-function-from-local-nodejs-appl

@mbyrne00 mbyrne00 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 27, 2023
@sofisl sofisl added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Apr 27, 2023
@sofisl
Copy link
Contributor

sofisl commented Apr 27, 2023

Hey @mbyrne00, sounds like this is a duplicate of: #876. Currently, this doesn't support fetch ID token.

I'll relabel as a FR for the time being.

@mbyrne00
Copy link
Author

Hey @sofisl - thanks for the reply but not sure how the other issue you linked is a duplicate. The functionality for auth.getIdTokenClient() does what we want at a functional level, but it just does not honour application-default credentials on a developer's machine locally. This just means we have to revert to other more manual means to pass in credentials locally, which we don't need to do for other libs.

The issue you linked seems more about functional changes to allow one token to be exchanged for another, which isn't really what I need. But .... I may not appreciate the internals.

I use the token id client to make the request, and thus add in the identity token for calling cloud functions. I'd be happy to plug in the identity token header manually if I had that, though, and if it supported application-default credentials stored on a developer's machine.

@Irob466
Copy link

Irob466 commented Apr 28, 2023

I believe this is actually a duplicate of #1113, which was closed but has some active conversation recently. The workarounds posted in the issue don't seem to be working for me, but the reasoning behind why the application-default credentials are failing makes sense.

@mbyrne00
Copy link
Author

Right - I get why there was the link to #876 now as the complexity is in how to get the identity token with what's available in ~/.config/gcloud/application_default_credentials.json. OK, thanks for highlighting.

The title and content of that issue isn't immediately obvious at first, which is why I didn't find it before raising this issue. At least now that they are linked someone else can find the way.

Here's hoping there's a solution going forward.

ddelgrosso1 pushed a commit to ddelgrosso1/google-auth-library-nodejs that referenced this issue May 16, 2023
* fix: add hashes to requirements.txt

and update Docker images so they require hashes.

* fix: add hashes to docker/owlbot/java/src

* Squashed commit of the following:

commit ab7384ea1c30df8ec2e175566ef2508e6c3a2acb
Author: Jeffrey Rennie <rennie@google.com>
Date:   Tue Aug 23 11:38:48 2022 -0700

    fix: remove pip install statements (googleapis#1546)

    because the tools are already installed in the docker image as of googleapis/testing-infra-docker#227

commit 302667c9ab7210da42cc337e8f39fe1ea99049ef
Author: WhiteSource Renovate <bot@renovateapp.com>
Date:   Tue Aug 23 19:50:28 2022 +0200

    chore(deps): update dependency setuptools to v65.2.0 (googleapis#1541)

    Co-authored-by: Anthonios Partheniou <partheniou@google.com>

commit 6e9054fd91d1b500cae58ff72ee9aeb626077756
Author: WhiteSource Renovate <bot@renovateapp.com>
Date:   Tue Aug 23 19:42:51 2022 +0200

    chore(deps): update dependency nbconvert to v7 (googleapis#1543)

    Co-authored-by: Anthonios Partheniou <partheniou@google.com>

commit d229a1258999f599a90a9b674a1c5541e00db588
Author: Alexander Fenster <fenster@google.com>
Date:   Mon Aug 22 15:04:53 2022 -0700

    fix: update google-gax and remove obsolete deps (googleapis#1545)

commit 13ce62621e70059b2f5e3a7bade735f91c53339c
Author: Jeffrey Rennie <rennie@google.com>
Date:   Mon Aug 22 11:08:21 2022 -0700

    chore: remove release config and script (googleapis#1540)

    We don't release to pypi anymore.

* chore: rollback java changes

to move forward with other languages until Java's docker image is fixed
Source-Link: googleapis/synthtool@4826337
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:7fefeb9e517db2dd8c8202d9239ff6788d6852bc92dd3aac57a46059679ac9de

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
@danielbankhead
Copy link
Contributor

Closing as a duplicate of #876, let's continue the conversation there!

@danielbankhead danielbankhead closed this as not planned Won't fix, can't repro, duplicate, stale Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

5 participants