3

我构建了一个示例容器(Go 示例,https://cloud.google.com/run/docs/quickstarts/build-and-deploy)并部署到云运行(我未选中“允许未经身份验证的调用”)。

但是,当我打开服务的端点 URL 时,我得到一个 401 页面,

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unauthorized</h1>
<h2>Your client does not have permission to the requested URL <code>/</code>.</h2>
<h2></h2>
</body></html>
curl -H "Authorization: Bearer $(gcloud config config-helper --format 'value(credential.id_token)')" [SERVICE_URL]
  • 我的用户帐户有“roles/run.invoker”
  • 当我检查“允许未经身份验证的调用”时,我得到了预期的结果。

有什么可以打开端点的吗?

4

2 回答 2

0
  1. 请通过“gcloud --version”确保 gcloud 版本至少为 243.0.0

  2. 如果 gcloud 太旧,请使用“gcloud components update”进行更新

  3. [更新] 在 Cloud Shell 中使用 gcloud 调用需要身份验证的 Cloud Run 服务现在也可以使用了。

谢谢!

于 2019-04-26T03:00:32.787 回答
0

最后,在调用不允许未经身份验证的调用的云运行服务时,我设法从云功能连接了 15 分钟,并遇到了相同的 401 错误:

import google.auth

auth_req = google.auth.transport.requests.Request()
id_token = google.oauth2.id_token.fetch_id_token(auth_req, URL)

headers = {'Authorization': 'Bearer ' + id_token,
               "Content-Type": "application/json; charset=utf-8"}
response = requests.post(URL, json=request_json, headers=headers)
于 2021-09-10T01:27:24.863 回答