在AWS S3中,限制用户仅访问其文件夹的一般做法是使用S3存储桶策略和IAM策略。
以下是一个基本的解决方案,用于将IAM用户限制为仅能访问其文件夹:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowUserFolderAccess",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:user/username"
},
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::example-bucket/user-folder",
"arn:aws:s3:::example-bucket/user-folder/*"
]
}
]
}
请将123456789012替换为你的AWS账户ID,username替换为你的IAM用户名。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::example-bucket/user-folder",
"arn:aws:s3:::example-bucket/user-folder/*"
]
}
]
}
请将example-bucket替换为你的存储桶名,user-folder替换为IAM用户的文件夹名。
通过这种方式,你可以限制IAM用户仅能访问其文件夹中的对象,并阻止访问其他文件夹和对象。