【发布时间】:2021-10-18 15:04:19
【问题描述】:
在 AWS S3 中上传对象时,您可以将“x-amz-acl=bucket-owner-full-control”添加到 url(作为查询参数)以使对象属于存储桶而不是上传者。使用 Cloud Storage 或 Azure Storage 时如何实现相同的目标?
【问题讨论】:
标签: amazon-s3 google-cloud-storage azure-storage
在 AWS S3 中上传对象时,您可以将“x-amz-acl=bucket-owner-full-control”添加到 url(作为查询参数)以使对象属于存储桶而不是上传者。使用 Cloud Storage 或 Azure Storage 时如何实现相同的目标?
【问题讨论】:
标签: amazon-s3 google-cloud-storage azure-storage
在使用 Cloud Storage 或 Azure Storage 时,您如何实现相同的目标?
在 Azure 存储中,您无需执行任何特殊操作。对象 (blob) 的所有权始终属于上传 blob 的存储帐户所有者。他们可以将管理 Blob 的权限委派给其他一些用户,但所有权始终属于帐户所有者。
【讨论】:
对于 Google Cloud Storage,上传带有x-amz-acl=bucket-owner-full-control 的对象相当于上传带有x-goog-acl=bucket-owner-full-control 标头的对象。将amz 切换为goog 适用于大多数标题。有一个translation table 的 S3 到 GCS 标头。
此外,如果您希望确保存储桶中的所有对象都只能由存储桶所有者访问,您会发现使用Uniform Bucket Level Access 会更方便。启用后,存储桶中的单个对象所有权将不再存在,并且您不再需要在每次上传时指定该标头。
您可以从 UI、API 或通过以下命令启用统一存储桶级别访问:gsutil uniformbucketlevelaccess set on gs://BUCKET_NAME
【讨论】:
Firebase 存储更接近 Dropbox 或 Google Drive,其所有者在技术上是存储桶,如果您想跟踪所有者是谁,您可以使用元数据
var newMetadata = {
customMetadata : {
'owner': auth().currentUser.uid
}
};
storageItemReference.updateMetadata(newMetadata)
.then((metadata) => {
// Updated metadata for your storage item is returned in the Promise
}).catch((error) => {
// Uh-oh, an error occurred!
});
如果您发现用户可以在不应该删除存储的情况下删除存储,您还可以从安全规则中控制此行为
service firebase.storage {
match /b/{bucket}/o {
// A read rule can be divided into read and list rules
match /images/{imageId} {
// Applies to single document read requests
allow get: if <condition>;
// Applies to list and listAll requests (Rules Version 2)
allow list: if <condition>;
// A write rule can be divided into create, update, and delete rules
match /images/{imageId} {
// Applies to writes to nonexistent files
allow create: if <condition>;
// Applies to updates to file metadata
allow update: if <condition>;
// Applies to delete operations
allow delete: if <condition>;
}
}
}
}
来源:https://firebase.google.com/docs/storage/security/core-syntax
【讨论】: