googleapis / googleapis/google-cloud-node

ID token with workload identity federation

Open
#7,784 11 comments 2 reactions 0 assignees View on GitHub
external library: google-cloud-node-core priority: p2 type: feature request
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

Hello togehter,

I want to access an GCP Cloud Endpoint with workload identity federation from AWS. I have a generated impersonated key file and your first example with list buckets worked well.

For Cloud endpoints and gRPC there is the need to use GOOGLE_ID_TOKEN instead of ACCESS_TOKENS.

My code looks like this. I used the getIdTokenClient function.

`

async function main() {
const url = "https://my-cloud-endpoint-url-endpoint-pimf6a67fa-ew.a.run.app/v1/status"

const auth = new GoogleAuth({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
scopes: 'https://www.googleapis.com/auth/cloud-platform',
projectId: 'my-project',
});
const targetAudience = "this-is-my-target-audience"
const client = await auth.getIdTokenClient(targetAudience);

const res = await client.request({ url });
console.log(res.data); }
`

The error message is:

`Error: Cannot fetch ID token in this environment, use GCE or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to a service account credentials JSON file.
at GoogleAuth.getIdTokenClient `

The problem is that I have an access token. In my case I need an ID Token. I was wondering if there is a possibility to get an ID Token before I request my endpoint.

( It works in python: Python google.auth has an impersonated_credentials object with an ID Token functionality.

` creds = impersonated_credentials.IDTokenCredentials(
target_creds,
target_audience=audience,
include_email=True
)`

Anyway, I need a solution for nodeJs.

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.