Authenticating a Cloud Run Service with a Service Account Key

I'm trying to setup a resource that triggers a Cloud Run Service.
It should be able to preform a POST request to the base url with a JSON payload.
The resource works fine if I set the authentication to Allow unauthenticated invocations, but I want to be the only to that's able to access it.

I have the resource set up like so:


where the connected service account has the appropriate permissions.
Is this misguided?
As far as I know, Cloud Run expects an identity token, which can be generated using the service account key. Is that what's being used to authenticate a request in such a case? I would assume not, since I keep getting the error:
Your client does not have permission to get URL / from this server.

Am I completely missing the mark here? Is there any way to do this?
Again, OAuth 2.0 doesn't work, since Cloud Run expects an identity token (gcloud auth print-identity-token), not an access token.

Any info or help is appreciated.

Hi @gasperblk :wave: I think you're on the right track!

Here's what I did to try to reproduce what you're seeing:

  1. I just spun up a test GCP Cloud Run Service
  2. Created a service account
  3. Added that service account to be able to invoke the Cloud Run Service
  4. Created a key for that service account
  5. Set the REST API authentication in Retool similarly to how you did in your screenshot... with one difference: I did not specify any scope in the Service Account OAuth Scopes field whereas you provided one.

Can you try clearing out the scopes, saving the resource, and retrying your query?

Here's a GIF showing how removing the scope worked for me. Were you seeing the exact same error message?

gif2

Yeah that seems to have worked :smile: Thanks a lot!
Though I'm not sure I understand why it works without a scope?

1 Like

@gasperblk :raised_hands: Woohoo :tada: glad you're all set.

I did find some documentation online about how scopes are not necessary for Cloud Functions so perhaps Cloud Runs invoked via HTTP act similarly. This StackOverflow answer seems to support that hypothesis.

Happy building!

1 Like