我正在尝试创建AWS S3策略,以允许对特定S3子文件夹的完全访问权限,但不允许其他任何内容。在下面的示例中,有一个名为Bob的开发人员。我创建了一个完全专用于Bob的目录,并希望通过登录控制台为他提供对此S3文件夹(bob文件夹)的完全读/写访问权限。
这是我尝试过的,虽然在尝试访问bob目录时,我收到了拒绝访问错误。我很欣赏有关如何实现这一目标的任何建议。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::/mydir/devs/bob/*"
]
}
]
}
答案 0 :(得分:0)
请记住,S3对象是完整的密钥名称,因此您已授予以下权限:
/mydir/devs/bob/*
代表所有以/mydir/devs/bob/
为前缀的密钥,但不包含密钥/mydir/devs/bob
本身,这是您的"文件夹"。它还缺少一个存储桶名称(bucket-name/mydir/devs/bob/*
)这意味着用户无法在"文件夹中使用列表操作"或者它的父文件夹。因此,Bob无法导航到他的文件夹。
在AWS博客here上有一个关于创建用户特定子文件夹的精彩演练。我们可以打破这些信息以适合您的用例,语句ID看起来像这样:
{
"Sid": "AllowUserToSeeBucketListInTheConsole",
"Action": ["s3:ListAllMyBuckets", "s3:GetBucketLocation"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::*"]
}
{
"Sid": "AllowRootAndHomeListingOfCompanyBucket",
"Action": ["s3:ListBucket"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::bucket-name"],
"Condition":{"StringEquals":{"s3:prefix":["","mydir/","mydir/devs/","mydir/devs/bob"],"s3:delimiter":["/"]}}
}
{
"Sid": "AllowListingOfUserFolder",
"Action": ["s3:ListBucket"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::bucket-name"],
"Condition":{"StringLike":{"s3:prefix":["mydir/devs/bob/*"]}}
}
{
"Sid": "AllowAllS3ActionsInUserFolder",
"Action":["s3:*"],
"Effect":"Allow",
"Resource": ["arn:aws:s3:::bucket-name/mydir/devs/bob/*"]
}
{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "AllowUserToSeeBucketListInTheConsole",
"Action": ["s3:ListAllMyBuckets", "s3:GetBucketLocation"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::*"]
},
{
"Sid": "AllowRootAndHomeListingOfCompanyBucket",
"Action": ["s3:ListBucket"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::bucket-name"],
"Condition":{"StringEquals":{"s3:prefix":["","mydir/","mydir/devs/","mydir/devs/bob"],"s3:delimiter":["/"]}}
},
{
"Sid": "AllowListingOfUserFolder",
"Action": ["s3:ListBucket"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::bucket-name"],
"Condition":{"StringLike":{"s3:prefix":["mydir/devs/bob/*"]}}
},
{
"Sid": "AllowAllS3ActionsInUserFolder",
"Action":["s3:*"],
"Effect":"Allow",
"Resource": ["arn:aws:s3:::bucket-name/mydir/devs/bob/*"]
}
]
}
提供的文档还提供了一个很好的示例,通过在策略中使用${aws:username}
变量来执行此操作,以便可以将其应用于组。
答案 1 :(得分:0)
这就是我对完全相同的需求。有些组合似乎违反直觉(为什么我同时需要ListAllBuckets
和ListBucket
- 但如果没有它,它似乎无效):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Resource": [
"arn:aws:s3:::*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::mydir"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::mydir/devs/bob/*"
]
}
]
}
另外,我认为ListBucket
需要一个存储桶(即您的示例中为mydir
)。我认为它不适用于密钥(或文件夹),例如mydir/devs/bob