【问题标题】:How to enable api-key auth for all version when deploying multiple versions to same configuration in Google Clould Endpoint在 Google Cloud Endpoint 中将多个版本部署到相同配置时如何为所有版本启用 api-key 身份验证
【发布时间】:2018-02-08 05:51:28
【问题描述】:

我使用 Cloud Endpoint 的版本控制功能(即 gcloud service-management deploy openapi_v1.yaml openapi_v2.yaml)将 2 个版本的 openapi.yaml 文件部署到 Google Cloud Endpoint。每个版本的 yaml 文件都包含一个版本号和不同的基本路径,一个使用 api-key 身份验证的端点,以及 api-key 身份验证标签的定义。部署到 Endpoint 后,配置显示两个 yaml 文件,但是使用此配置将 api 部署到 GAE 只会为较新版本打开 api-key 身份验证。

有谁知道这是否是一个已知的错误,或者我需要做些什么来为所有版本启用身份验证?

.yaml 文件如下所示。我用来测试的两个版本是相同的,除了版本和浴路径:

swagger: "2.0"
info:
  description: "This API is used to connect 3rd-party ids to a common user identity"
  version: "0.0.1"
  title: "****"
host: "uie-dot-user-id-exchange.appspot.com"
basePath: "/v0"

...

- "https"
x-google-allow: all

paths:

  ...

  /ids/search:
    get:
      operationId: "id_search"
      produces:
      - "application/json"
      security:
      - api_key: []
      tags:
      - "Ids"
      summary: "Privileged endpoint. Provide any id (3rd party or otherwise) and get a hash of all ids associated with it."
      parameters:
      - in: "query"
        name: "id_type"
        description: "Type of id to search"
        required: true
        type: string
      - in: "query"
        name: "id_value"
        description: "Value of id to search"
        required: true
        type: string
      responses:
        200:
          description: "AssociatedIdsHash"
          schema:
            $ref: '#/definitions/AssociatedIdsHash'
        400:
          description: "Bad request. Requires both id_type and id_value query parameters."
        401:
          description: "Unauthorized. Please provide a valid api-key in the \"api-key\" header."
        404:
          description: "Not found - no entry found for key provided"

...

################ SECURITY DEFINITIONS ################
securityDefinitions:
  # This section configures basic authentication with an API key.
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"

【问题讨论】:

  • 您可以发布您的 yaml 文件吗?

标签: google-app-engine authentication google-cloud-platform google-cloud-endpoints google-cloud-endpoints-v2


【解决方案1】:

我可以复制这个问题,它似乎是一个错误。

有效的是在两个版本的全局级别而不是在每个路径级别添加 API 密钥限制。也许这种解决方法足以满足您的用例。

...
security:
- api_key: []
path:
...

【讨论】:

  • 感谢您的确认。是否有时间修复此问题?对于项目,我们确实需要在每个路径级别启用 api_key auth
  • 没有修复时间表,但已记录并正在跟踪一个错误。
猜你喜欢
  • 2023-03-21
  • 2021-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-12
  • 1970-01-01
相关资源
最近更新 更多