Amazon S3 权限问题 - 如何一次设置所有文件的权限?
我已使用 Amazon AWS 管理控制台上传了一些文件。
我收到 HTTP 403 访问被拒绝
错误。我发现我需要设置查看
权限。
我该如何对存储桶中的所有文件执行此操作?
我知道可以对每个文件设置权限,但是当有许多文件需要每个人都可以查看时,这很耗时。
I have uploaded some files using the Amazon AWS management console.
I got an HTTP 403 Access denied
error. I found out that I needed to set the permission to view
.
How would I do that for all the files on the bucket?
I know that it is possible to set permission on each file, but it's time-consuming when having many files that need to be viewable for everyone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我建议您对要存储公共内容的存储桶应用存储桶策略1。这样您就不必为每个对象设置 ACL。以下是一个策略示例,该策略将使存储桶 mybucket 中的所有文件公开。
"Resource": "arn:aws:s3:::mybucket/sub/dirs/are/supported/*"
中的*
允许递归。1 请注意,存储桶策略与 IAM 策略不同。 (如果您尝试在 IAM 策略中包含
Principal
,您将会收到错误消息。)可以通过在 AWS Web 控制台中转到存储桶的根目录并展开“属性”>“存储桶策略”来编辑存储桶策略。权限。存储桶的子目录也有属性>权限,但没有编辑存储桶策略的选项I suggest that you apply a bucket policy1 to the bucket where you want to store public content. This way you don't have to set ACL for every object. Here is an example of a policy that will make all the files in the bucket mybucket public.
That
*
in"Resource": "arn:aws:s3:::mybucket/sub/dirs/are/supported/*"
allows recursion.1 Note that a Bucket Policy is different than an IAM Policy. (For one you will get an error if you try to include
Principal
in an IAM Policy.) The Bucket Policy can be edit by going the root of the bucket in your AWS web console and expanding Properties > Permissions. Subdirectories of a bucket also have Properties > Permissions, but there is no option to Edit bucket policy您可以选择要公开的目录。
按“更多”并将其标记为公开;它将使得目录和所有文件都可以公开访问。
You can select which directory you want it to be public.
Press on "more" and mark it as public; it will make the directory and all the files to be accessible as public.
您只能修改唯一项目(存储桶或项目)的 ACL,因此您必须逐一更改它们。
某些 S3 管理应用程序允许您将相同的 ACL 应用于存储桶中的所有项目,但在内部,它会将 ACL 逐一应用于每个项目。
如果您以编程方式上传文件,则在上传文件时指定 ACL 非常重要,这样您以后就不必修改它。使用 S3 管理应用程序(如 Cloudberry、Transmit 等)的问题是,当您上传每个文件时,大多数应用程序都使用默认 ACL(私有只读)。
You can only modify ACLs for a unique item (bucket or item), soy you will have to change them one by one.
Some S3 management applications allows you to apply the same ACL to all items in a bucket, but internally, it applies the ACL to each one by one.
If you upload your files programmatically, it's important to specify the ACL as you upload the file, so you don't have to modify it later. The problem of using an S3 management application (like Cloudberry, Transmit, ...) is that most of them uses the default ACL (private read only) when you upload each file.
我使用 Cloudberry Explorer 来完成这项工作:)
I used Cloudberry Explorer to do the job :)
使用 S3 Browser 您可以使用 gui 递归地更新权限。它是一个有用的工具,并且免费供非商业用途。
Using S3 Browser you can update permissions using the gui, also recursively. It's a useful tool and free for non-commercial use.
Transmit 5
我想为已经拥有名为 Transmit 的精美 FTP 应用程序的潜在 macOS 用户添加此内容由恐慌。
我已经有了 Panic 并且它支持 S3 存储桶(不确定它是什么版本,但我认为升级是免费的)。它还支持递归更新读写权限。
您只需右键单击要更新的目录,然后选择要设置的读取和写入权限。
它看起来不是很快,但您可以通过“窗口”>“打开日志文件”。记录下来,这样你至少知道它正在做某事。
Transmit 5
I wanted to add this here for potential macOS users that already have the beautifully-crafted FTP app called Transmit by Panic.
I already had Panic and it supports S3 buckets (not sure what version this came in but I think the upgrades were free). It also supports recursively updating Read and Write permissions.
You simply right click the directory you want to update and select the Read and Write permissions you want to set them to.
It doesn't seem terribly fast but you can open up the log file by going Window > Transcript so you at least know that it's doing something.
要公开大量文件,请执行以下操作:
To make a bulk of files public, do the following:
您可以使用 aws cli 对每个文件设置 ACL:
You could set ACL on each file using aws cli:
我在通过程序(java)将文件上传到 s3 存储桶时遇到了同样的问题..
我添加了源身份并更改了存储桶策略和CORS 配置,然后一切正常。
I had same problem while uploading the files through program (java) to s3 bucket ..
I added the origin identity and changed the bucket policy and CORS configuration then everything worked fine.
使用 AWS 策略生成器 生成适合您需求的策略。策略生成器中的主体应该是您用于访问对象的 IAM 用户/角色。
资源 ARN 应为 arn:aws:s3:::mybucket/sub/dirs/are/supported/*
接下来,单击“添加语句”并执行操作。您最终将获得代表该策略的 JSON。将此粘贴到您的 s3 存储桶策略管理部分,该部分位于“AWS 中的 s3 存储桶页面 -> 权限 -> 存储桶策略”。
Use AWS policy generator to generate a policy which fits your need. The principal in the policy generator should be the IAM user/role which you'd be using for accessing the object(s).
Resource ARN should be
arn:aws:s3:::mybucket/sub/dirs/are/supported/*
Next, click on "Add statement" and follow through. You'll finally get a JSON representing the policy. Paste this in your s3 bucket policy management section which is at "your s3 bucket page in AWS -> permissions -> bucket policy".
这对我在 digital ocean 上有用,据称它具有与 s3 相同的 API:
上面将所有文件设置为公开。
This worked for me on digital ocean, which allegedly has the same API as s3:
The above sets all files to public.