【发布时间】:2019-04-05 23:30:27
【问题描述】:
我需要第三方将一些文件上传到 Google Cloud Storage 存储分区。授予他们访问权限的最佳(或最简单)方法是什么?
【问题讨论】:
标签: google-app-engine google-cloud-storage
我需要第三方将一些文件上传到 Google Cloud Storage 存储分区。授予他们访问权限的最佳(或最简单)方法是什么?
【问题讨论】:
标签: google-app-engine google-cloud-storage
前两种方法要求用户拥有有效的Google Account。我在这个答案中忽略了Google Identity Platform。如果用户有一个Gmail Account,那么这意味着他们也有一个Google Account。第三种方法使用 Google 服务帐户。
方法一:使用谷歌云存储控制台:
转到Storage -> Browser。
检查所需的存储桶。在permissions 下的右侧面板中,单击Add 按钮。
添加用户的 Google 帐户电子邮件地址。选择Storage Object Creator。
授予的角色是roles/storage.objectCreator。该角色授予用户在存储桶中创建对象的权限,但用户不能删除或覆盖对象。
方法2:使用gsutl CLI:
gsutil iam ch user:username@example.com:ObjectCreator gs://examplebucket
读取当前存储桶 IAM 策略的命令:
gsutil iam get gs://examplebucket
方法 3:使用 Google 服务帐号
在 Google Cloud Console 中创建 Google 服务帐号
IAM & admin -> Service accounts
CREATE SERVICE ACCOUNT
Service account name 和Service account description
CREATE
Service account permissions 中,选择一个角色。Storage -> Storage Object Creator
CONTINUE
Create key
JSON 单选按钮以获取Key type
您现在拥有Google Service Account 凭据,可以使用gsutil、gcloud 和软件程序进行设置。
【讨论】:
您授予第三方客户将文件上传到 Google Cloud Storage 存储分区的访问权限的方式因一种编程语言而异。在 PHP 中,您可以编写如下内容:
$options = ['gs_bucket_name' => $my_bucket]; $upload_url = CloudStorageTools::createUploadUrl('/upload/handler', $options);
并因此获得一个上传 URL。您可以在“允许用户上传文件”在线document 中找到有关此解决方案的更多详细信息。
【讨论】: