Google cloud platform 云函数的端点返回403禁止

Google cloud platform 云函数的端点返回403禁止,google-cloud-platform,google-cloud-functions,google-cloud-endpoints,google-cloud-run,google-cloud-iam,Google Cloud Platform,Google Cloud Functions,Google Cloud Endpoints,Google Cloud Run,Google Cloud Iam,我正在遵循谷歌为我的云功能设置端点的建议 gcloud beta functions add-iam-policy-binding function1 --member "serviceAccount:id-compute@developer.gserviceaccount.com" --role "roles/cloudfunctions.invoker" --project "project_id" 当我尝试使用URLservice\u name.a.run.app/function1从浏

我正在遵循谷歌为我的云功能设置端点的建议

gcloud beta functions add-iam-policy-binding function1 --member "serviceAccount:id-compute@developer.gserviceaccount.com" --role "roles/cloudfunctions.invoker" --project "project_id"
当我尝试使用URL
service\u name.a.run.app/function1
从浏览器访问端点时,我得到

Error: Forbidden
Your client does not have permission to get URL /function1GET from this server
作为上述教程的一部分,我将通过授予ESP调用我的函数的权限来保护我的函数

gcloud beta functions add-iam-policy-binding function1 --member "serviceAccount:id-compute@developer.gserviceaccount.com" --role "roles/cloudfunctions.invoker" --project "project_id"
My
openapi函数.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'

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

我遵循了您提到的教程,实际上我遇到了完全相同的错误

权限和角色方面似乎没有任何问题

挖掘了一点之后,解决问题的方法是删除地址末尾的“
GET

因此,
openapi函数.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"
一切都很顺利

请特别注意随每次新部署而变化的
配置ID
例如:

然后是这样的:

2019-12-03r1
如果部署步骤失败(显示一些成功消息,但最终可能失败),请确保删除现有端点服务以避免出现问题:

gcloud endpoints services delete [SERVICE_ID]
您还可以使用以下命令为所有用户提供
cloudfunctions.invoker
角色(仅用于测试)


您的ESP托管在哪里?我的ESP位于云端,使用类似于gateway-12345-uc.a.Run.app的URL运行。您可以运行此命令并将结果添加到此处吗
gcloud运行服务描述
打开浏览器调试器。发布包含标题的请求的输出。请注意,请求需要HTTP
Authorization:TOKEN
头。如果没有该标题,您将收到权限错误。allowCors:true inside x-google-endpoints不适用于云运行ESP。您需要使用ESP_ARGS标志指定ESP的CORS标志。请检查文档底部:顺便说一句,我为谷歌云支持工作,因此我会确保将此报告给文档团队进行审查,避免将来可能出现的混淆。感谢Waelmas,这解决了我的CORS问题。我现在在我的
openapi中传递
path参数时遇到了一个问题。yaml
——不知道您是否可以看一下
gcloud functions add-iam-policy-binding function-1 \
 --member="allUsers" \
 --role="roles/cloudfunctions.invoker"