I want to ensure that my Cloud Run service is using the correct service account to authorize requests, in accordance with the guidance provided here: https://cloud.google.com/run/docs/securing/service-identity#permissions-required-to-operate. However, when I invoke the service using a curl command from Cloud Shell, the logs show that the default service account is used with the message:
Default credentials provider for Google Compute Engine.
even though the service account I want is already attached to the service.
Any idea why this happens?
More context: My service account has been allowlisted and should have the scope to access the Automotive Maps API, in the application code I'm using the application default credentials to authorize the request. it works when I run the app locally when I set the environment variable GOOGLE_APPLICATION_CREDENTIALS to point to a service account key I downloaded. But it does't work when deployed to CloudRun and invoked running the following command:
curl -H \
"Authorization: Bearer $(gcloud auth print-identity-token)" \
https://cloudrunsampleretry-qwuy73xdsq-uc.a.run.app
I'm getting
io.grpc.StatusRuntimeException: PERMISSION_DENIED: Request had insufficient authentication scopes.
The instruction explicitly saying
Never set GOOGLE_APPLICATION_CREDENTIALS as an environment variable on a Cloud Run service
so application default credentials(ADC) must work in a different way comparing to the app running locally. Just don't know what could went wrong on the setups of the Cloud Run service.