I'm trying to make IAM policies for Cloud Run work behind Google Cloud Load Balancer.
When calling a Cloud Run service directly, I need to set a target audience equal to the URL of the Cloud Run service, e.g. my-service-abcdef.a.run.app
:
import { credentials } from '@grpc/grpc-js';
import { GoogleAuth } from 'google-auth-library';
const clientCredentials = await new GoogleAuth().getIdTokenClient(
'https://my-service-abcdef.a.run.app',
);
const client = new MyServiceClient(
'my-service-abcdef.a.run.app',
credentials.combineChannelCredentials(
credentials.createSsl(),
credentials.createFromGoogleCredential(clientCredentials),
),
);
Now, when I put by Cloud Run service behind GCLB, I can actually still call it when I provide a domain I have linked to GCLB (e.g. my-domain.com
), but I need to keep target audience (for the getIdTokenClient call) intact (https://my-service-abcdef.a.run.app
).
This breaks (which is perfectly understandable) as soon as I add more regions behind GCLB, which have different "native" URL (in the .run.app
domain, therefore would require different audiences).
Do Cloud Run services accept any other audiences? Can I specify my own?