首页 > 解决方案 > S3 列出存储桶的所有子文件夹会产生 AccessDenied ,即使存储桶是公共的

问题描述

考虑 S3 中的以下策略:

{
    "Version": "2012-10-17",
    "Id": "AxelPolly12424242",
    "Statement": [
        {
            "Sid": "Stmt242554354",
            "Effect": "Allow",
            "Principal": "*",
            "Action": ["s3:ListBucket"],
            "Resource": "arn:aws:s3:::mycoolbucketname/*",
            "Condition":{"StringEquals":{"s3:prefix":["","examples"]}}
        }
    ]
}

当我尝试点击我的存储桶名称时 https://mycoolbucketname.s3-us-east-2.amazonaws.com/examples

我们得到:

<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <RequestId>KJLFSDHJJKGDFJKLGJDFKLGJLDF</RequestId>
    <HostId>GLKSFDNGJKLFDJGKLDFJGKLFDJGFDGEOT89GJROIGIKDSFSDJSD</HostId>
</Error>

Block public access (bucket settings)当我们在 Permissions 选项卡下也取消选中时,此策略有什么问题以及如何列出存储桶的所有子文件夹 。

标签: amazon-web-servicesamazon-s3bucket

解决方案


s3:prefix适用于存储桶资源,而不是对象。所以而不是:

"Resource": "arn:aws:s3:::mycoolbucketname/*",

你应该有:

"Resource": "arn:aws:s3:::mycoolbucketname",

推荐阅读