Here my use case.
- I already have a Cloud Run service deployed in private mode. (same issue with Cloud Function)
- I'm developing a new service that use this Cloud Run. I use the default credential in the application for the authentication. It worked on Compute Engine and on Cloud Run because the default credential is gotten from the metadata server.
But, on my local environment, I need to use a service account key file for achieving this. (for example, when I set the GOOGLE_APPLICATION_CREDENTIALS env var)
However, I can't use my user account credential.
The log trace are very clear in Java, Node or Go: impossible to generate an identity token on a user credential type.
So,
- why google auth library doesn't allow to do this?
- Why Google Front End accept only Google signed identity token?
- Is a workaround exist for continuing to use the user account?
And a piece of context: we want to avoid to use service account key file. Today, it's our major security breach (files are copied, sent by email, even committed on Github publicly...). The user account default credential work with all Google Cloud API but not with IAP and CLoud Run/Functions.
EDIT
Here some example of error.
JAVA
I do this
Credentials credentials = GoogleCredentials.getApplicationDefault().createScoped("https://www.googleapis.com/auth/cloud-platform");
IdTokenCredentials idTokenCredentials = IdTokenCredentials.newBuilder()
.setIdTokenProvider((IdTokenProvider) credentials)
.setTargetAudience(myUri).build();
HttpRequestFactory factory = new NetHttpTransport().createRequestFactory(new HttpCredentialsAdapter(idTokenCredentials));
And my user credential is not compliant with IdTokenProvider
interface
Caused by: java.lang.ClassCastException: class com.google.auth.oauth2.UserCredentials cannot be cast to class com.google.auth.oauth2.IdTokenProvider (com.google.auth.oauth2.UserCredentials and com.google.auth.oauth2.IdTokenProvider are in unnamed module of loader 'app')
NODE
With node, this code work with a service account
const {GoogleAuth} = require('google-auth-library');
const auth = new GoogleAuth()
const client = await auth.getIdTokenClient(url);
const res = await client.request({url});
console.log(res.data);
But with my user account, I got this error
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(....)