自动允许未经身份验证的用户云 运行 个实例

Automatically allow-unauthenticated users to cloud run instances

您好,我正在开发一个解决方案,该解决方案使用其 REST API 和 OAuth 作为 服务帐户[=29= 创建和部署服务到 Google 云 运行 ] 为此目的而创建。

我坚持让创建的服务公开可用。

我无法从 API.

中找到与 gcloud 对应的 --allow-unauthenticated 参数

我发现的唯一方法是在我希望公开访问的每个服务上手动添加 allUsers 作为 Cloud 运行 Invoker。但是,我希望 service-account 中的所有服务都可以自动公开访问。

我想知道是否有更好(更自动化)的方法来实现这个。

提前致谢。

首先,您不能只用一个命令来完成此操作。您必须部署该服务,然后授予该服务的所有用户。 CLI 为您方便地完成这 2 个步骤。

无论如何,当你遇到这样的问题时,有一个有用的技巧:在你的 gcloud 命令中添加 --log-http。像这样,您将看到 CLI 执行的所有 HTTP API 调用。

如果您在部署新的云 运行 服务时执行此操作,您将有大量的线路,而现在,您有这个

==== request start ====
uri: https://run.googleapis.com/v1/projects/gbl-imt-homerider-basguillaueb/locations/us-central1/services/predict2:setIamPolicy?alt=json
method: POST
== headers start ==
b'Authorization': --- Token Redacted ---
b'X-Goog-User-Project': b'gbl-imt-homerider-basguillaueb'
b'accept': b'application/json'
b'accept-encoding': b'gzip, deflate'
b'content-length': b'98'
b'content-type': b'application/json'
b'user-agent': b'google-cloud-sdk gcloud/299.0.0 command/gcloud.run.deploy invocation-id/61070d063a604fdda8e87ad63777e3ae environment/devshell environment-version/None interactive/True from-script/False python/3.7.3 term/screen (Linux 4.19.112+
)'
== headers end ==
⠹ Deploying new service...
{"policy": {"bindings": [{"members": ["allUsers"], "role": "roles/run.invoker"}], "etag": "ACAB"}}
== body end ==
  ⠹ Setting IAM Policy...
---- response start ----
status: 200
-- headers start --
-content-encoding: gzip
cache-control: private
content-length: 159
content-type: application/json; charset=UTF-8
date: Wed, 08 Jul 2020 11:37:11 GMT
server: ESF
transfer-encoding: chunked
vary: Origin, X-Origin, Referer
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 0
-- headers end --
-- body start --
{
  "version": 1,
  "etag": "BwWp7IdZGHs=",
  "bindings": [
    {
      "role": "roles/run.invoker",
      "members": [
        "allUsers"
      ]
    }
  ]
}

因此,这是一个为您执行 CLI 的附加 API 调用。你可以找到 here the API definition

如果你想手动执行调用,你可以这样请求

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "content-type: application/json" -X POST \
     -d '{"policy": {"bindings": [{"members": ["allUsers"], "role": "roles/run.invoker"}]}}' \     
     "https://run.googleapis.com/v1/projects/<PROJECT_ID>/locations/<REGION>/services/<SERVICE_NAME>:setIamPolicy"