我正在使用 AWS S3 组件来存储文件。
我有一个名为“ mybucket ”的存储桶,其中包含以下文件夹:
+---Mybucket
\---toto1
\---toto2
+---toto3
| \--- subfolder
| \---subsubfolder
\---toto4
我有只需要访问“toto3”文件夹的 AWS 控制台用户。
我试图限制对该文件夹的访问,但用户必须有权列出存储桶的根目录。如果我赋予访问根文件夹的额外权限,用户可以浏览“toto1”和“toto2”文件夹,而我不想要。
我想配置这样的东西:
我尝试了这个 IAM 策略但没有成功:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:PutObject",
"s3:GetObject"
],
"Resource": ["arn:aws:s3:::mybucket/toto3/*"]
},
{
"Sid": "Stmt1457617383000",
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket"
],
"Resource": ["arn:aws:s3:::mybucket"]
},
{
"Sid": "Stmt1457617230000",
"Effect": "Deny",
"Action": ["s3:*"],
"Condition": {
"StringNotLike": {
"s3:prefix": "toto3*"
}
},
"Resource": [
"arn:aws:s3:::mybucket/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets"
],
"Resource": [
"*"
]
}
]
}
最佳答案
这是一项对您有用的政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::mybucket/toto3/*"
]
},
{
"Sid": "Stmt1457617230000",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Condition": {
"StringLike": {
"s3:prefix": [
"",
"toto3/"
]
}
},
"Resource": [
"arn:aws:s3:::mybucket*"
]
}
]
}
细节:
ListAllMyBuckets
是控制台要求的。它显示了所有存储桶的列表。 toto3/
内允许的任何操作小路。 ListBucket
(检索对象列表)在存储桶的根和 toto3/
中允许小路。 我成功地测试了这个解决方案。
AWS 文档引用:Allow Users to Access a Personal "Home Directory" in Amazon S3
关于amazon-web-services - IAM AWS S3 限制到特定的子文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35944349/