【问题标题】:403 Response from Google Cloud Functions来自 Google Cloud Functions 的 403 响应
【发布时间】:2019-03-03 12:19:17
【问题描述】:

我在尝试从 Web 执行 Cloud Function 端点时收到以下错误:

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 403 (Forbidden)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5pxno-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>403.</b> <ins>That’s an error.</ins>
  <p>Access is forbidden.  <ins>That’s all we know.</ins>

我遵循了这个教程:https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/functions/helloworld/main.py

调用此处所述的函数时:https://cloud.google.com/functions/docs/writing/http,我收到 403 错误。我已登录 gcloud 项目并使用正确的用户。

部署命令:

gcloud beta functions deploy hello_get --runtime python37 --trigger-http

来自此文档:https://cloud.google.com/functions/docs/concepts/python-runtime

使用以下命令调用它: curl -X POST https://&lt;REGION-PROJECT_ID&gt;.cloudfunctions.net/hello_get

来自此文档:https://cloud.google.com/functions/docs/writing/http

这很奇怪,因为这发生在大约 3 周前。旧函数停止工作并返回 403 响应。我在 UI 中部署了示例函数,它仅在从 UI 部署时有效,但在通过 http 请求访问端点时失败并出现 403。

另外,使用命令时函数成功执行:gcloud functions call hello_get

过去几周 GCF 身份验证是否发生了变化?

更新 我能够确定问题所在。我参与的项目和用户在一个 beta 身份验证程序中。切换到不在程序中的用户和项目后,我能够访问端点。

感谢您的帮助。

【问题讨论】:

  • 问题不是由于身份验证。默认情况下,Cloud Functions 未经过身份验证,并且可供任何调用者使用。您的问题在其他地方,但从您的摘要中我不清楚这可能在哪里。相同的函数(重复调用)是否继续返回 403?当你使用 UI 进行部署时,是在同一个项目中吗?这特别令人好奇,因为它验证项目已启用,计费已启用并且功能已部署,因此很奇怪通过curl 调用将不起作用。你检查过日志吗?次要观点:POST 有效,但这可能是GET

标签: google-cloud-platform google-cloud-functions


【解决方案1】:

使用可以使用邮递员发送请求并获取 JWT

gcloud auth print-identity-token

【讨论】:

    【解决方案2】:

    在我看来,Google Cloud Functions 中添加了额外的 IAM 功能,因此,您可能没有打开 allUser 对该功能的访问权限(仅供参考,这可以访问整个网络)。

    1. 在 Cloud Functions 主页上,突出显示要添加所有访问权限的 Cloud Functions。

    2. 点击右上角的“显示信息面板”。

    3. 点击“添加成员”并输入“allUsers”,然后在角色框中的“云函数”下选择“云函数调用者”。

    4. 点击“保存”

    【讨论】:

    • 谢谢迈克。 GCP 已经添加了这个功能,现在很容易做到。
    • 谢谢。我应该将哪个服务帐户添加到 Cloud Function Invokers,以便我的 Cloud Function 只能由另一个云函数调用?
    • @KasparTr 取决于你如何调用它(例如,python 中的请求等)——为什么不打开 Pub/Sub 并让它触发它:)
    • @MikeKarp 我确实在 Pub/Sub 有意义的地方使用了 Pub/Sub 作为解决方案。当我需要直接调用函数时,添加 Pub/Sub 是一个很大的开销成本。这个问题在这里解决了:stackoverflow.com/questions/57994997/…
    【解决方案3】:

    我浏览了更多与同一错误相关的帖子。他们中的大多数人建议检查this 链接以获得许可。还提到使用this 文档使用稳定版本进行部署并重试。它始终建议不要使用 beta,直到您需要任何 beta 标志来使用该命令。在执行此操作之前,请确保您使用的是 current 版本的 Google Cloud SDK。有一点不清楚,如果您使用在 UI 中部署相同的功能,也应该使用端点工作。

    【讨论】:

      猜你喜欢
      • 2017-12-09
      • 2019-10-13
      • 2020-09-29
      • 2019-04-03
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      • 2018-06-26
      • 2021-06-17
      相关资源
      最近更新 更多