【问题标题】:ESPV2 to Cloud RunESPV2 到 Cloud Run
【发布时间】: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


【解决方案1】:

好的,我了解到您的 ESPv2 已部署在 Cloud Run 上,您想要访问另一个 Cloud Run。

  • 最简单的方法是以 noallow-unauthenticated 模式部署 NodeJS 云运行,然后授予 ESPv2 Cloud Run 服务帐户访问 NodeJS Cloud Run 的权限。 IAM 过滤流量,只有有效流量才能到达您的 NodeJS Cloud Run
  • 您可以在 NodeJS Cloud Run 上将上一个选项与 ingress=internal-only 结合使用。这一次,只有经过身份验证的(因为您处于 noallow-unauthenticated 模式)和来自当前部署 NodeJS Cloud Run 服务的项目的 VPC 的流量,您需要add a serverless VPC connector to your ESPv2 Cloud Run service.
  • 您也可以只拥有内部流量,但我不建议这样做,信任 IAM 服务是很大的优势。

我写了an article on that,你可以依赖它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-18
    • 2021-09-14
    • 2020-05-27
    • 2019-10-28
    • 1970-01-01
    • 2020-07-01
    • 2020-05-27
    • 1970-01-01
    相关资源
    最近更新 更多