S3 存储桶策略 - 对象级别?

时间:2021-02-05 15:08:13

标签: amazon-web-services amazon-s3

是否可以仅授予特定对象级别的权限,即仅授予与 /file.txt 匹配但在给定存储桶内的任何位置的对象?

    {
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam:accountARN"
        },
        "Action": [
            "s3:GetObject",
            "s3:ListBucket",
            "s3:GetObjectVersion",
            "s3:GetBucketVersioning",
            "s3:ListBucketVersions"
        ],
        "Resource": [
            "arn:aws:s3:::bucket",
            "arn:aws:s3:::bucket/thing1/thing2/*/*/*/file.txt"            ]
    }

因为我的 S3 目录结构是:

bucket/thing1/thing2/2021/01/22/file.txt

所以我的目标是该用户应该有权访问的文件.txt 存在于thing2 下的任何地方(因为日期文件夹是动态的)。

不确定这样的事情是否可行?事实上我几乎可以肯定它不会

"arn:aws:s3:::bucket/thing1/thing2/*/*/*/file.txt"  

我尝试使用条件语句,但这对我的用例没有太大意义。

https://docs.aws.amazon.com/AmazonS3/latest/dev/amazon-s3-policy-keys.html#condition-key-bucket-ops-2

2 个答案:

答案 0 :(得分:0)

我认为以下方法可行。

arn:aws:s3:::bucket*/file.txt

答案 1 :(得分:0)

实际上这是最终奏效的:

"arn:aws:s3:::bucket/thing1/thing2/*/file.txt"