云功能的端点返回403禁止

我正在遵循Google的tutorial为我的云功能设置端点。

当我尝试使用URL service_name.a.run.app/function1从浏览器访问端点时,会得到

Error: Forbidden
Your client does not have permission to get URL /function1GET from this server

作为上述教程的一部分和Google产品经理的answer,我通过授予ESP调用我的功能的权限来保护自己的功能。

gcloud beta functions add-iam-policy-binding function1 --member "serviceaccount:id-compute@developer.gserviceaccount.com" --role "roles/cloudfunctions.invoker" --project "project_id"

我的openapi-functions.yaml

swagger: '2.0'
info:
  title: Cloud Endpoints + GCF
  description: Sample API on Cloud Endpoints with a Google Cloud Functions backend
  version: 1.0.0
host: HOST
x-google-endpoints:
- name: "HOST"
  allowCors: "true
schemes:
  - https
produces:
  - application/json
paths:
  /function1:
    get:
      operationId: function1
      x-google-backend:
        address: https://REGION-FUNCTIONS_PROJECT_ID.cloudfunctions.net/function1GET
      responses:
        '200':
          description: A successful response
          schema:
            type: string

请注意,我已添加

- name: "HOST"
  allowCors: "true'

到我的.yaml文件,因为我需要从Firebase上托管的静态站点访问终结点。

cd773213220 回答:云功能的端点返回403禁止

我已经按照您提到的教程进行操作,确实遇到了完全相同的错误。

关于权限和角色的一切似乎都没错。

深入研究后,解决了该问题的方法是删除地址末尾的“ GET”。

所以openapi-functions.yaml像这样:

swagger: '2.0'
info:
  title: Cloud Endpoints + GCF
  description: Sample API on Cloud Endpoints with a Google Cloud Functions backend
  version: 1.0.0
host: [HOST]
schemes:
  - https
produces:
  - application/json
paths:
  /function-1:
    get:
      summary: Greet a user
      operationId: function-1
      x-google-backend:
        address: https://[REGION]-[PROJECT_ID].cloudfunctions.net/function-1
      responses:
        '200':
          description: A successful response
          schema:
            type: string

然后确保您正确地遵循了教程中提到的所有步骤(上述部分除外)。

如果在执行任何步骤时遇到权限拒绝错误,请尝试以sudo的身份再次运行。

我也尝试过添加与您相同的内容:

host: [HOST]
x-google-endpoints:
- name: [HOST]
  allowCors: "true"

一切正常。

要特别注意CONFIG_ID随新部署而变化的情况 示例:

2019-12-03r0

然后它会像这样:

2019-12-03r1

万一部署步骤失败(它显示了一些成功的消息,但最终可能会失败),请确保删除现有的终结点服务以避免问题:

gcloud endpoints services delete [SERVICE_ID]

您还可以使用以下内容为所有用户提供cloudfunctions.invoker角色(仅供测试)

gcloud functions add-iam-policy-binding function-1 \
 --member="allUsers" \
 --role="roles/cloudfunctions.invoker"
本文链接:https://www.f2er.com/3055319.html

大家都在问