我正在使用AWS S3组件来存储文件。
我有一个名为“ mybucket ”的存储桶,其中包含以下文件夹:
+---Mybucket
\---toto1
\---toto2
+---toto3
| \--- subfolder
| \---subsubfolder
\---toto4
我有AWS控制台用户,只需要访问“toto3”文件夹。
我尝试限制对此文件夹的访问权限,但用户必须有权列出存储桶的根目录。如果我提供额外的权限来访问根文件夹,用户可以浏览“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": [
"*"
]
}
]
}
答案 0 :(得分:11)
这是一项适合您的政策:
{
"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
答案 1 :(得分:1)
我编辑你的代码以获得以下内容并且它有效!谢谢!!
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::mybucket/toto3/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::mybucket",
"Condition": {
"StringLike": {
"s3:prefix": [
"",
"toto3/",
"toto3*"
]
}
}
}
]
}
答案 2 :(得分:0)
我只需要授予外部供应商访问文件夹下某个子文件夹的权限,该文件夹位于存储桶(!!!)下。像这样:
存储桶/文件夹/子文件夹
这是我的实现方式:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"s3:DeleteObject",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::bucket/*",
"arn:aws:s3:::bucket"
]
"Condition": {
"StringLike": {
"s3:prefix": [
"bucket/folder/subfolder/*",
"bucket/folder/subfolder/",
"bucket/folder/subfolder",
"folder/subfolder/*",
"folder/subfolder/",
"folder/subfolder",
]
}
}
}
]
}
答案 3 :(得分:0)
是否可以限制以下规则,但授予特定的文件夹访问权限?我不希望用户在特定存储桶中看到目录名称/文件夹名称。
自动列出存储桶的根目录(如果用户看到目录名称,对我来说就可以了)