我有两个用户 User1 和 User2,每个用户在 AWS 中都有一个 IAM 账户。我有一个 s3 存储桶“external_bucket.frommycompany.com”。在该存储桶中是每个用户帐户“User1”和“User2”的文件夹。我想仅授予 User1 对 User1 文件夹的 R/W 访问权限,仅授予 User2 对 User2 文件夹的 R/W 访问权限。我不希望他们能够在 external_bucket.frommycompany.com 的根目录中看到彼此的文件夹。有没有办法设置他们的 IAM 策略,以便这是可能的?
我的目标是让我们的用户能够从 Cloudberry 等 S3 浏览器应用程序连接到 S3 存储桶,以便他们只能将文件上传和下载到他们的文件夹。
欢迎任何有关最佳设计的建议。
最佳答案
来自 here
这样的事情应该可以允许 User1 只访问 User1 的文件夹:
{
"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:::my-company"],
"Condition":{"StringEquals":{"s3:prefix":["","/"],"s3:delimiter":["/"]}}
},
{
"Sid": "AllowListingOfUserFolder",
"Action": ["s3:ListBucket"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::my-company"],
"Condition":{"StringLike":{"s3:prefix":["user1/*"]}}
},
{
"Sid": "AllowAllS3ActionsInUserFolder",
"Effect": "Allow",
"Action": ["s3:*"],
"Resource": ["arn:aws:s3:::user1/*"]
}
]
}
将其应用为 User1 的策略,他们应该只能访问
user1/
文件夹。 "s3:prefix":["","/"]...
部分可能可以更改,但我对策略语言不够熟悉,不知道如何更改。如果在 User2 的策略中将 user2 替换为 user1,则 User2 应该只能访问
user2/
文件夹,依此类推。关于amazon-web-services - 如何为多个 IAM 用户设置 S3 策略,以便每个人只能访问他们的个人存储桶文件夹?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39758851/