【问题标题】:Google cloud storage bucket not accessible by workspace domain users工作区域用户无法访问 Google 云存储桶
【发布时间】:2022-03-11 20:35:52
【问题描述】:

我正在尝试使用以下代码使用 python webapp2 在谷歌云存储桶上创建一个 csv 文件:

 full_filename = '/' + TEST_BUCKET + "/" + DATA + "/" + 'employee.csv'
    logging.info("full_filename is %s ", full_filename)
    gcs_file = cloudstorage.open(full_filename,
                                 'w',
                                 content_type='text/plain',
                                 retry_params=cloudstorage.RetryParams(backoff_factor=1.1))
    gcs_file.write(file_obj.getvalue())
    gcs_file.close()
    logging.info("done writing into cloud storage !!")

创建成功,GAE控制台的开发者可以看到文件内容。

但不属于GAE 控制台的员工无法看到此内容并获得403 Forbidden

这个想法是,属于同一组织的员工(让我们以 google 工作区域为:example.com)应该能够访问此文件,无论他们是否是 GAE 控制台的一部分。 因此,为此我尝试授予存储桶级别权限(uniform access control)并将 example.com 添加为新主体和角色:Storage Legacy Bucket Reader 但它们仍然得到相同的403 Forbidden

资源: https://cloud.google.com/iam/docs/overview#g_suite_domain

https://cloud.google.com/storage/docs/access-control

GSuite Permissions on Google Cloud Storage

https://cloud.google.com/storage/docs/access-control/lists

【问题讨论】:

  • 成为 Workspace 的成员不会自动授予 Cloud Storage 权限。您的代码如何向 API 调用添加授权?您的问题没有显示这些细节。

标签: python google-cloud-storage google-cloud-iam


【解决方案1】:

此错误 (403) 表示用户未获得 Google Cloud Storage 的授权以提出请求。

  • Google Cloud Storage 错误documentation for 403-Forbidden 中列出了导致此错误的各种可能原因。
  • 此错误的常见来源是存储桶权限(存储桶 ACL)未正确设置以允许您的应用访问。

由于您提到作为 GAE 一部分的开发人员可以访问存储桶内容,因此我们可以排除上述 ACL 场景。

但是,您可以尝试以下方法:

  • 将域用户添加到组。

  • 在 Google Cloud Platform Console 上转到“存储 -> 浏览器”,然后在您的存储桶上,在右侧的菜单中选择“编辑存储桶权限”。

  • 在“添加成员”上放置组并赋予“存储 -> 存储对象查看器”的角色,以便在通过身份验证或您需要的任何其他权限组合时为整个组授予只读权限。

或者,您也可以查看documentation 了解更多详情。

【讨论】:

  • 我已经发布了答案。你能检查一下这是否有帮助吗?
猜你喜欢
  • 1970-01-01
  • 2018-01-28
  • 2019-08-24
  • 1970-01-01
  • 2022-01-10
  • 2019-09-20
  • 2016-12-19
  • 2020-10-10
  • 1970-01-01
相关资源
最近更新 更多