GCP 端点:调用方在查询中请求 API 键后没有权限

GCP endpoints: The caller does not have permission after requesting API key in query

尝试将 Google 云平台与部署了 GKE 的后端一起使用。

我有一个用于端点的 swagger 文件,它在不使用安全性时工作正常。

我在 swagger 文件中添加了 api 键定义:

paths:
  /create:
    post:
      ...
      security:
        - api_key: []
      
securityDefinitions:
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"

现在,如果我尝试 post,我会得到预期的

{
    "code": 16,
    "message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.",
    "details": [
        {
            "@type": "type.googleapis.com/google.rpc.DebugInfo",
            "stackEntries": [],
            "detail": "service_control"
        }
    ]
}

很好,现在我在 GCP 的凭据部分创建了一个 API 密钥

我更新 post 请求以包含 ?key=API_KEY 并收到以下错误:

{
    "code": 13,
    "message": "\b#The caller does not have permission",
    "details": [
        {
            "@type": "type.googleapis.com/google.rpc.DebugInfo",
            "stackEntries": [],
            "detail": "service_control"
        }
    ]
}

我找不到关于此错误的任何信息,这是否意味着我的 API 密钥无权使用此端点?如果是这样,我该如何解决?

确认您有 required services enabled

gcloud services enable servicemanagement.googleapis.com
gcloud services enable servicecontrol.googleapis.com
gcloud services enable endpoints.googleapis.com

同时启用您的端点服务gcloud services enable ENDPOINTS_SERVICE_NAME