Search code examples
google-cloud-platformgoogle-cloud-rungoogle-iam

CloudRun Service to Service returning 403 After Setup


I have a service to service set up that I completed using the google cloud tutorial (https://cloud.google.com/run/docs/authenticating/service-to-service#nodejs)

  1. Changed the cloudrun Service account to have roles/run.invoker (they both share the same role)

  2. Make a request to get the access token: http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=https://XXXX-XXXX-XXXX-xx.a.run.app'

  3. (failing) Use that access token to make a request at https://XXXX-XXXX-XXXX-xx.a.run.app/my-endpoint with the access token: axios.post('https://XXXX-XXXX-XXXX-xx.a.run.app/my-endpoint', {myData}, {headers: {Authorization: 'Bearer eyJhbGciOiJSUz.....'}})

However, on step 3, making the call to my service, I receive a 403 error, any thoughts on what I missed?

Note: I have tried deploying my invoked service with --allow-unauthenticated and without it. I am not using a custom domain, I am using the CloudRun created url.

PS: If I change the ingress from internal and load balancer to all it works, however I'm not sure if this is correct to do.


Solution

  • The HTTP 403 Forbidden error message when accessing your Cloud Run service means that your client is not authorized to invoke this service.

    You have not granted the service account permission to call the receiving service. Your question states that you added roles/run.invoker but the error message indicates you did not complete this step correctly.

    1. Go to the Google Cloud Console.
    2. Select the receiving service (this is the Cloud Run service you are calling).
    3. Click Show Info Panel in the top right corner to show the Permissions tab.
    4. In the Add members field, enter the identity of the calling service.
    5. Select the Cloud Run Invoker role from the Select a role drop-down menu.
    6. Click Add.

    Note: When requesting the Identity Token, do not specify the custom domain. Your question's wording is confusing on that point.

    [UPDATE]

    The OP has enabled internal and load balancer. This requires setting up Serverless VPC Access.

    Connecting to a VPC network