Google Cloud Functions Deploy“允许未经身份验证的调用......”

Posted

技术标签:

【中文标题】Google Cloud Functions Deploy“允许未经身份验证的调用......”【英文标题】:Google Cloud Functions Deploy "allow unauthenticated invocations..." 【发布时间】:2020-08-16 12:46:40 【问题描述】:

每当我必须使用 gcloud sdk 部署新的 python 函数时,我都会收到此消息

允许对新函数 [function-name] 进行未经身份验证的调用吗?

(是/否)?

警告:使用受限访问 IAM 策略创建的函数。要启用未经授权的访问,请考虑

“gcloud alpha 函数 add-iam-policy-binding function-name --region=europe-west1 --member=allUsers --role=roles/cloudfunctions.invoker”

在部署时我可以在命令中添加任何标志以使其成为NO

这是我用来部署一个功能的示例命令:

gcloud functions deploy function-name --region=europe-west1 --entry-point function-entry-point --trigger-resource "projects/my-project/databases/(default)/documents/user_ids/user_id" --trigger-event providers/cloud.firestore/eventTypes/document.create --runtime python37 --timeout 60 --project my-project

【问题讨论】:

如果您使用--service-account 标志指定服务帐户会发生什么? 添加了建议使用gcloud alpha 的完整警告消息。有:cloud.google.com/sdk/gcloud/reference/functions/…,但问题是我不想允许未经身份验证的呼叫。你建议如何使用--service-account 指定一个服务帐户以访问云功能。如果您没有提供有关权限的信息,可能会引发该错误。我正在阅读此线程上的 cmets:***.com/questions/57122047/… 我也有同样的问题。但问题是我不想设置任何 IAM 策略,除了不使用 deploy 命令访问未经授权的访问,我已经按照那里的建议尝试了 betaalpha 但仍然要求我使用 IAM政策。我正在寻找要添加到deploy 命令的标志。 你的用例是什么? 【参考方案1】:

来自https://cloud.google.com/sdk/docs/scripting-gcloud#disabling_prompts:

您可以通过将配置中的disable_prompts 属性设置为True 或使用全局--quiet-q 标志来禁用来自gcloud CLI 命令的提示。

因此,对于您的示例,您可以运行:

gcloud functions deploy function-name --quiet --region=europe-west1 --entry-point function-entry-point --trigger-resource "projects/my-project/databases/(default)/documents/user_ids/user_id" --trigger-event providers/cloud.firestore/eventTypes/document.create --runtime python37 --timeout 60 --project my-project

【讨论】:

我认为这只是一种解决方法,而不是解决方案。 这个答案似乎是官方推荐的回答这个问题的方法,而不是其他 cmets 建议的解决方法。来自文档:“一些 gcloud CLI 命令是交互式的,提示用户确认操作或为输入的命令请求额外输入。在大多数情况下,在脚本或其他自动化中运行命令时这是不可取的。您可以使用全局 --quiet-q 标志禁用来自 gcloud CLI 命令的提示 [...] ”。我认为不赞成投票是不合理的【参考方案2】:
    选择服务 单击“显示信息面板”以显示“权限”选项卡。 在添加成员字段中,所有用户 从角色中选择 Cloud Functions Invoker 添加

  gcloud functions add-iam-policy-binding FUNCTION \
  --member='serviceAccount:FUNCTION_IDENTITY' \
  --role='roles/cloudfunctions.invoker'

 gcloud run services add-iam-policy-binding [SERVICE_NAME] \
    --member="allUsers" \
    --role="roles/cloudfunctions.invoker"

【讨论】:

只是根据云函数的资源修改

以上是关于Google Cloud Functions Deploy“允许未经身份验证的调用......”的主要内容,如果未能解决你的问题,请参考以下文章