【问题标题】:Google Cloud API Gateway authenticate multiple service accountsGoogle Cloud API Gateway 对多个服务帐号进行身份验证
【发布时间】:2021-01-16 02:02:22
【问题描述】:

对于托管在 GCP 中的 API,我计划借助具有私钥和 API 网关的服务帐户来验证消费服务(来自外部 gcp 环境)。

对于一个服务帐户 (service-account-1) 来说一切正常,即:

paths:
    /hello:
      get:
        #...
        security:
          - service_account-1: []
securityDefinitions:
    service_account-1:
      authorizationUrl: ""
      flow: "implicit"
      type: "oauth2"
      x-google-issuer: "{service-account-1}@{project-id}.iam.gserviceaccount.com"
      x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/{service-account-1}@{project-id}.iam.gserviceaccount.com"
      x-google-audiences: "{project-id}"

但是我该如何描述它以便项目中的任何服务帐户都可以访问?

编辑:我想避免在每次创建新服务帐户并需要允许访问时更新 API 网关上的 openapi 配置。

更新:我最终使用 Identity-Aware Proxy 来保护 API,只允许授权的服务帐户。

【问题讨论】:

    标签: google-cloud-platform oauth-2.0 google-oauth openapi google-cloud-api-gateway


    【解决方案1】:

    根据官方文档:

    Authentication between services

    您可以在 API 配置中定义多个安全定义,但是 每个定义必须有不同的 x-google-issuer。如果你有 为每个调用服务创建单独的服务帐户,您可以 为每个服务帐户创建一个安全定义,例如:

    securityDefinitions:
      service-1:
        authorizationUrl: ""
        flow: "implicit"
        type: "oauth2"
        x-google-issuer: "service-1@example-project-12345.iam.gserviceaccount.com"
        x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/service-1@example-project-12345.iam.gserviceaccount.com"
      service-2:
        authorizationUrl: ""
        flow: "implicit"
        type: "oauth2"
        x-google-issuer: "service-2@example-project-12345.iam.gserviceaccount.com"
        x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/service-2@example-project-12345.iam.gserviceaccount.com"
    

    因此您必须创建多个安全定义。

    【讨论】:

    • 谢谢@marian.vladoi 我知道我可以为每个服务帐户创建定义,但是对于我的情况来说这不是一个非常灵活的方法。稍后会添加服务帐户,我希望避免每次发生时都更新配置。
    • 据我了解,阅读文档,必须在配置文件中指定服务帐户
    • 也许你知道另一种使用 gcp 环境实现相同的方法..也许不同的方法?
    • 请注意这是一项测试版功能,支持有限。另外,我发现一些用户试图通过使用 API 密钥来避免这个限制。
    • 目前,您必须在配置文件中包含所有服务帐户。因此,您必须在每次创建新服务帐户时更新配置文件。
    猜你喜欢
    • 1970-01-01
    • 2020-09-20
    • 1970-01-01
    • 2018-05-02
    • 2019-11-05
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    相关资源
    最近更新 更多