Amazon S3 权限问题 - 如何一次设置所有文件的权限?

发布于 2024-12-04 11:32:40 字数 184 浏览 2 评论 0原文

我已使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

寂寞花火° 2024-12-11 11:32:40

我建议您对要存储公共内容的存储桶应用存储桶策略1。这样您就不必为每个对象设置 ACL。以下是一个策略示例,该策略将使存储桶 mybucket 中的所有文件公开。

{
    "Version": "2008-10-17",
    "Id": "http better policy",
    "Statement": [
        {
            "Sid": "readonly policy",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mybucket/sub/dirs/are/supported/*"
        }
    ]
}

"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.

{
    "Version": "2008-10-17",
    "Id": "http better policy",
    "Statement": [
        {
            "Sid": "readonly policy",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mybucket/sub/dirs/are/supported/*"
        }
    ]
}

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

梦开始←不甜 2024-12-11 11:32:40

您可以选择要公开的目录。

按“更多”并将其标记为公开;它将使得目录和所有文件都可以公开访问。

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.

秋日私语 2024-12-11 11:32:40

您只能修改唯一项目(存储桶或项目)的 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.

梨涡 2024-12-11 11:32:40

我使用 Cloudberry Explorer 来完成这项工作:)

I used Cloudberry Explorer to do the job :)

猫腻 2024-12-11 11:32:40

使用 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.

森林散布 2024-12-11 11:32:40

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.

雪落纷纷 2024-12-11 11:32:40

要公开大量文件,请执行以下操作:

  1. 转到 S3 Web 界面
  2. 打开所需的存储桶
  3. 通过单击列表左侧的复选框选择所需的文件和文件夹
  4. 单击列表顶部的“更多”按钮,单击“公开”
  5. 单击“公开”确认。尽管警告显示“...读取此对象,读取和写入权限”,但这些文件不会具有公共写入权限。

To make a bulk of files public, do the following:

  1. Go to S3 web interface
  2. Open the required bucket
  3. Select the required files and folders by clicking the checkboxes at the left of the list
  4. Click «More» button at the top of the list, click «Make public»
  5. Confirm by clicking «Make public». The files won't have a public write access despite the warning says «...read this object, read and write permissions».
晨曦慕雪 2024-12-11 11:32:40

您可以使用 aws cli 对每个文件设置 ACL:

BUCKET_NAME=example
BUCKET_DIR=media
NEW_ACL=public-read

aws s3 ls $BUCKET_NAME/$BUCKET_DIR/ | \
awk '{$1=$2=$3=""; print $0}' | \
xargs -t -I _ \
aws s3api put-object-acl --acl $NEW_ACL --bucket $BUCKET_NAME --key "$BUCKET_DIR/_"

You could set ACL on each file using aws cli:

BUCKET_NAME=example
BUCKET_DIR=media
NEW_ACL=public-read

aws s3 ls $BUCKET_NAME/$BUCKET_DIR/ | \
awk '{$1=$2=$3=""; print $0}' | \
xargs -t -I _ \
aws s3api put-object-acl --acl $NEW_ACL --bucket $BUCKET_NAME --key "$BUCKET_DIR/_"
昨迟人 2024-12-11 11:32:40

我在通过程序(java)将文件上传到 s3 存储桶时遇到了同样的问题..

错误:请求的资源上不存在“Access-Control-Allow-Origin”标头。
因此,不允许访问源 'http://localhost:9000'。响应的 HTTP 状态代码为 403

我添加了源身份并更改了存储桶策略CORS 配置,然后一切正常。

I had same problem while uploading the files through program (java) to s3 bucket ..

Error: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:9000' is therefore not allowed access. The response had HTTP status code 403

I added the origin identity and changed the bucket policy and CORS configuration then everything worked fine.

因为看清所以看轻 2024-12-11 11:32:40

使用 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".

朦胧时间 2024-12-11 11:32:40

这对我在 digital ocean 上有用,据称它具有与 s3 相同的 API:

s3cmd modify s3://[BUCKETNAME]/[DIRECTORY] --recursive --acl-public

上面将所有文件设置为公开。

This worked for me on digital ocean, which allegedly has the same API as s3:

s3cmd modify s3://[BUCKETNAME]/[DIRECTORY] --recursive --acl-public

The above sets all files to public.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文