【发布时间】:2019-05-17 23:57:53
【问题描述】:
我正在尝试找出服务帐户将文件写入 GCS 存储桶所需的最低权限集。我在想我可以使用 storage.objectAdmin,但是使用为 Python SDK 提供的示例代码失败并出现错误:my-service-account@my-project.googleapis.com does not have storage.buckets.get access to my-bucket
client = _get_storage_client()
bucket = client.bucket(current_app.config['CLOUD_STORAGE_BUCKET'])
blob = bucket.blob(filename)
blob.upload_from_string(
file_stream,
content_type=content_type)
这是因为 client.bucket 调用实际上是从存储桶中读取元数据,而 storage.objectAdmin 不会授予该元数据。当我使用 storage.admin 权限时,它会自行修复,但这也允许帐户删除我不想要的整个存储桶。添加 storage.legacyBucketReader 也可以,但是我正在使用一个旧角色,我不确定我是否应该再做。
这里的最佳做法是什么?
【问题讨论】:
标签: python google-cloud-platform google-cloud-storage