google 云存储 - 即使我是项目所有者,我也无法编辑对象的权限
google cloud storage - I can't edit the permissions of my objects even though I am the project owner
我使用以下 Java 代码将对象添加到 google 具有 public 读取权限的云存储,以便任何人都可以读取该文件:
try {
gcsService.createOrReplace(file, new GcsFileOptions.Builder()
.mimeType("image/jpeg")
.acl("public-read").build(),
ByteBuffer.wrap(data));
} catch (IOException ex){
// catch error
}
但是当我在 GCP 控制台中转到云存储时,如果我尝试编辑文件的权限,我会收到此通知和此错误:
Since you are not authorized to know the public access status of this
object, it is possible that the public URL displayed is not valid.
当我将文件写入云存储时,我是否可以做些什么,使其既具有 public- 读取权限,又允许我(项目所有者)有权编辑它的权限?
当我是项目所有者时,我无法编辑我自己的对象的权限,这似乎有点愚蠢。
编辑:
我也在考虑使用新的云存储 api。这是我到目前为止的代码。我怎样才能使 ACL 适合项目所有者(我)并使其 public 易于阅读?
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of(bucket, object);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId)
.setContentType(mimeType)
.setAcl(Arrays.asList(Acl.of(Acl.User.ofAllUsers(), READER)))
.build();
Blob output = storage.create(blobInfo, data);
storage.buckets.getIamPolicy
用于读取存储桶IAM策略,storage.buckets.setIamPolicy
用于更新存储桶IAM策略。
The storage.objects.getIamPolicy and storage.objects.setIamPolicy permissions do not apply to buckets with uniform bucket-level access enabled. So when you enable uniform bucket-level access on a bucket, Access Control Lists (ACLs) are disabled, and only bucket-level Identity and Access Management (IAM) permissions grant access to that bucket and the objects it contains. So first check if you have enabled uniform bucket-level access / fine-grained permissions for your bucket when you created it using the various options to view bucket metadata(除了 XML API)
对 GCS 资源的访问不是递归的。拥有一个项目或该项目中的存储桶并不一定意味着您也对特定对象具有特定权限。拥有存储桶确实意味着您可以列出或删除该对象,仅此而已。
确定哪些 built-in IAM 角色可以做哪些事情的最佳资源是 Google 云平台 IAM Permissions Reference。
在该页面上,CTRL-F 以获得您感兴趣的其他权限,您将在 right-hand 列中看到授予它的角色。请注意,项目所有者 (roles/owner) 不在授予此权限的角色列表中。
关于如何使单个对象公开可读,请阅读此 Java code sample in documentation. Again, if your bucket uses uniform bucket-level access, you cannot use these steps. Instead, grant public readability to all objects in the bucket, or use signed URLs。也许这就是您收到错误的原因,因为您对存储桶拥有 uniform-bucket-level 访问权限,并且您正在尝试不可能的事情。
我使用以下 Java 代码将对象添加到 google 具有 public 读取权限的云存储,以便任何人都可以读取该文件:
try {
gcsService.createOrReplace(file, new GcsFileOptions.Builder()
.mimeType("image/jpeg")
.acl("public-read").build(),
ByteBuffer.wrap(data));
} catch (IOException ex){
// catch error
}
但是当我在 GCP 控制台中转到云存储时,如果我尝试编辑文件的权限,我会收到此通知和此错误:
Since you are not authorized to know the public access status of this object, it is possible that the public URL displayed is not valid.
当我将文件写入云存储时,我是否可以做些什么,使其既具有 public- 读取权限,又允许我(项目所有者)有权编辑它的权限?
当我是项目所有者时,我无法编辑我自己的对象的权限,这似乎有点愚蠢。
编辑:
我也在考虑使用新的云存储 api。这是我到目前为止的代码。我怎样才能使 ACL 适合项目所有者(我)并使其 public 易于阅读?
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of(bucket, object);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId)
.setContentType(mimeType)
.setAcl(Arrays.asList(Acl.of(Acl.User.ofAllUsers(), READER)))
.build();
Blob output = storage.create(blobInfo, data);
storage.buckets.getIamPolicy
用于读取存储桶IAM策略,storage.buckets.setIamPolicy
用于更新存储桶IAM策略。
The storage.objects.getIamPolicy and storage.objects.setIamPolicy permissions do not apply to buckets with uniform bucket-level access enabled. So when you enable uniform bucket-level access on a bucket, Access Control Lists (ACLs) are disabled, and only bucket-level Identity and Access Management (IAM) permissions grant access to that bucket and the objects it contains. So first check if you have enabled uniform bucket-level access / fine-grained permissions for your bucket when you created it using the various options to view bucket metadata(除了 XML API)
对 GCS 资源的访问不是递归的。拥有一个项目或该项目中的存储桶并不一定意味着您也对特定对象具有特定权限。拥有存储桶确实意味着您可以列出或删除该对象,仅此而已。 确定哪些 built-in IAM 角色可以做哪些事情的最佳资源是 Google 云平台 IAM Permissions Reference。 在该页面上,CTRL-F 以获得您感兴趣的其他权限,您将在 right-hand 列中看到授予它的角色。请注意,项目所有者 (roles/owner) 不在授予此权限的角色列表中。
关于如何使单个对象公开可读,请阅读此 Java code sample in documentation. Again, if your bucket uses uniform bucket-level access, you cannot use these steps. Instead, grant public readability to all objects in the bucket, or use signed URLs。也许这就是您收到错误的原因,因为您对存储桶拥有 uniform-bucket-level 访问权限,并且您正在尝试不可能的事情。