I have a google cloud function providing a Google Chat App. My GCF receives calls from Google Chat when users type input. It doesn't call Chat; it exposes a URL and Chat calls it, it computes for a while, and it sends a response back to Chat. So the GCF does not need authentication to work with Chat.
I seem to need to configure my Google Cloud Function to accept network requests to "Allow All Traffic". Google Chat does not seem to be part of my Google Cloud Project, so I cannot configure the connection into the GCF to be "Allow Internal Traffic Only". So anyone learning the URL of my GCF could flood it with fake traffic.
Ideally, I would like the Google networking system to only permit access to my function from Google Chat, but I cannot find a way to do this using a service account in Google IAM. Can I do this somehow?
Looking at the headers of the access from Chat to my GCF, it does contain an authorization: 'Bearer eyJhbGciO...'
header. That turns out to be a JSON Web Token. That says
headers: {
"alg": "RS256",
"kid": "06ea3d3c9414b34d77d66407580cec7e10c0b7d3",
"typ": "JWT"
}
payload: {
"aud": "939021344830",
"exp": 1680195982,
"iat": 1680192382,
"iss": "chat@system.gserviceaccount.com"
}
so it looks like that is a token generated by Google Chat and signed by Google to demonstrate that the source was indeed Google Chat. The kid
should identify the key I need to validate the JWT. How can I verify that this token is properly signed by Google?
I looked at Secure Google Cloud Functions http trigger with auth but the solutions there do not seem to be applicable because I do not have control over how Google Chat makes the call to my GCF.
Thanks!