Google 云 运行 内部服务之间的通信

Google Cloud Run communication between internal services

我有 2 个云 运行 服务:

想法是 calculator-api 是 public,它将向 add-api 发出请求。出于某种原因,当 add-api 入口为 internal 时,我收到 403,但如果我将入口更改为 Allow all traffic,它会完美运行。

我使用以下代码正确获取了 IdToken,然后我将令牌注入 header Authorization: Bearer IdToken。我的接收者 add-api 拥有 calculator-apiCloud Run Invoker 角色权限。

GET request "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity?audience=https://add-api.a.run.app"

Header: {"Metadata-Flavor", "Google"}

因此,我认为问题不在于身份验证,而在于入口设置为 internal 时的某种网络限制。

您需要创建一个serverless VPC connector in the same region as your calculator-api service and to add it to your calculator-api service and to set the egress value to all

目前的限制是:2 个服务必须在同一个项目中(或者您需要执行 VPC 对等才能实现此目的)