【发布时间】:2021-05-26 15:52:53
【问题描述】:
我正在设置 ESPv2,它将访问另一个用 NodeJS+Express 编写的 Cloud Run 服务。我可以直接访问 NodeJS+Express 服务,但想使用 ESPv2 限制访问。
ESPv2 安装没有任何问题,但我有以下问题。
当我使用 ESPv2 访问 NodeJS+Express Cloud Run 服务时,NodeJS+Express 服务触发器必须使用“允许所有流量”和“允许未经授权的调用”。
如果我将访问限制为仅允许内部流量,ESPv2 将无法访问 NodeJS+Express Cloud Run 服务。
我应该做些什么来授权 ESPv2 和被调用的 NodeJS 服务之间的调用吗?
下面给出了yaml的顶部
swagger: "2.0"
info:
description: "APIs for managing My Site"
version: "0.0.3"
title: "My API"
contact:
email: "email@email.com"
license:
name: "Copyright Amzu IT Ltd"
host: "apihost-xxxx.a.run.app"
x-google-endpoints:
- name: "apihost-xxxx.a.run.app"
allowCors: True
x-google-backend:
address: https://<nodejs-expess-cloud-run-url>.a.run.app
protocol: h2
schemes:
- "https"
paths:
/test:
get:
operationId: Testing
summary: A Test Endpoint to check if the URL is working.
description: A Test Endpoint to check if the URL is working, does not have any security enabled for this URL.
responses:
200:
description: Success
schema:
type: "string"
security:
- key: []
securityDefinitions:
key:
type: apiKey
in: header
name: x-api-key
firebase:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "https://securetoken.google.com/REMOVED"
x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
x-google-audiences: "REMOVED"
【问题讨论】:
-
我即将为一个项目重新访问 Cloud Endpoints,因此您的问题很及时。自从我上次使用 Endpoints v2 已经有一段时间了,但是 IIRC....您不希望 Cloud Run 服务以
--allow-unauthenticated运行(因为它会并且您可以轻松地向自己证明这一点)。您希望将 Cloud Run 限制为仅由为您运行 Endpoint 服务的服务帐户调用。见:cloud.google.com/run/docs/securing/managing-access#gcloud -
我之前尝试过的时候在博客上写过这个(使用 Golang,但应该有点不同)。唯一的变化是 ESP 图像现在包含版本(我将更新帖子)。请参阅
gcloud run services add-iam-policy-binding的部分。 pretired.dazwilkin.com/posts/200325
标签: google-cloud-platform google-cloud-run