S3 存储桶的 IAM 组策略:拒绝文件夹而不是文件
IAM Group Policy for S3 bucket: deny folders but not files
this question references the same aws blog 我一直在尝试利用杠杆来满足我的需求,但没有成功。我一直在研究该答案中的解决方案及其整天引用的示例策略,但没有任何成功。我基本上希望允许不同的 IAM 组完全访问存储桶中的公共子文件夹对象,同时根据组成员有选择地 allowing/denying 访问其他子文件夹对象。
桶结构:
我的财务桶\
my-finance-bucket\files
my-finance-bucket\Our-Finance-Team\
my-finance-bucket\Our-Finance-Team\文件
my-finance-bucket\Our-Finance-Team\报告\
my-finance-bucket\Our-Finance-Team\报告\文件
my-finance-bucket\Our-Finance-Team\Reports\report1-name\
my-finance-bucket\Our-Finance-Team\Reports\report1-name\files
my-finance-bucket\Our-Finance-Team\Reports\report2-名称\
my-finance-bucket\Our-Finance-Team\Reports\report2-name\files
my-finance-bucket\Our-Finance-Team\数据\
my-finance-bucket\Our-Finance-Team\数据\文件
my-finance-bucket\Our-Finance-Team\资料\
my-finance-bucket\Our-Finance-Team\资料\文件
我什至不确定我想做的事情是否可行,但我想创建 3 个组,分别命名为:finance-all、finance-data 和 finance-reports。
我希望所有 3 个组都可以访问:
我的财务桶\
my-finance-bucket\files
my-finance-bucket\Our-Finance-Team\
my-finance-bucket\Our-Finance-Team\文件
my-finance-bucket\Our-Finance-Team\资料\
my-finance-bucket\Our-Finance-Team\资料\文件
此外,我还有这些要求:
finance-all 组有 s3:* 允许访问 my-finance-bucket
下的所有内容
(我认为这很容易,并且可以作为单独的组策略独立存在,允许 s3:* 到 arn:aws:s3:::/my-finance-bucket 和 arn:aws:s3:::/my-finance-桶/*)
finance-data 组具有上面列出的共享访问权限加上 s3:*Object* 允许:
my-finance-bucket\Our-Finance-Team\数据\
my-finance-bucket\Our-Finance-Team\数据\文件
无法访问未指定的任何其他内容
finance-reports 具有上面列出的共享访问权限,加上 s3:*Object* 允许:
my-finance-bucket\Our-Finance-Team\报告\
my-finance-bucket\Our-Finance-Team\报告\文件
my-finance-bucket\Our-Finance-Team\Reports\report1-name\
my-finance-bucket\Our-Finance-Team\Reports\report1-name\files
my-finance-bucket\Our-Finance-Team\Reports\report2-名称\
my-finance-bucket\Our-Finance-Team\Reports\report2-name\files
无法访问未指定的任何其他内容
我知道我必须从允许 "ListAllMyBuckets" 开始,因此代表文件夹和文件的对象将对所有文件夹可见并可列出,递归地。虽然不是最理想的,但它不会阻止不在适当组中的用户查看、获取或放置文件。
我知道大多数人会问 "what have you done" 以试图帮助纠正我已经完成的任何工作 - 然而我已经经历了几十次迭代,甚至没有什么能接近我现在的寻找做。链接答案和链接 aws 博客 post 中列出的代码是我对此进行黑客攻击的起点,可以作为基准
{
"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:::yourbucketname"],
"Condition":{"StringEquals":{"s3:prefix":["","yourfoldername/"],"s3:delimiter":["/"]}}
},
{
"Sid": "AllowListingOfUserFolder",
"Action": ["s3:ListBucket"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::yourbucketname"],
"Condition":{"StringLike":{"s3:prefix":["yourfoldername/*"]}}
},
{
"Sid": "AllowAllS3ActionsInUserFolder",
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::yourbucketname/yourfoldername/*"]
},
{
"Action": [
"s3:*"
],
"Sid": "Stmt1375581921000",
"Resource": [
"arn:aws:s3:::yourbucketname/anotherfolder1/*",
"arn:aws:s3:::yourbucketname/anotherfolder2/*",
"arn:aws:s3:::yourbucketname/anotherfolder3/*",
"arn:aws:s3:::yourbucketname/anotherfolder4/*"
],
"Effect": "Deny"
}
]
}
我最终在这上面花了大约 3 天时间才放弃,并说服有业务需求的人说,如果他们让我重新组织存储桶,我可以在半小时内完成整个工作.他们同意了,所以我最终只是在存储桶中创建了 "subfolders",然后创建了 IAM 组,向每个人授予访问权限 "subfolder"。
所以我像这样重组了存储桶:
我的财务桶/
my-finance-bucket/files
my-finance-bucket/shared/
my-finance-bucket/shared/文件
我的财务桶/
my-finance-bucket/data/
my-finance-bucket/data/文件
my-finance-bucket/reports/
my-finance-bucket/reports/文件
按照这种模式,我浓缩了现有的"subfolders",例如
my-finance-bucket/some-report/*
my-finance-bucket/some-other-report/*
下降到
my-finance-bucket/reports/some-report/*
my-finance-bucket/reports/一些其他报告/*
在 /shared/ 和 /data/ 下压缩内容也是如此
完成此操作后,我能够依靠固有的拒绝功能并简单地允许使用 IAM 组策略访问各个顶级文件夹。通过简单地将用户添加到这些组,我能够有选择地授予对某些子文件夹的访问权限,而不是其他子文件夹。
我为访问每个单独的存储桶而创建的所有策略都遵循以下格式:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowListAllMyBuckets",
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::*"
]
},
{
"Sid": "AllowedListAccess",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketAcl",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::my-finance-bucket",
"arn:aws:s3:::my-finance-bucket/shared"
]
},
{
"Sid": "AllowedObjectAccess",
"Effect": "Allow",
"Action": [
"s3:*Object*"
],
"Resource": [
"arn:aws:s3:::my-finance-bucket/shared/*"
]
}
]
}
请注意,由于 /* 允许列表和对象访问,子文件夹也可供有权访问顶级子文件夹的人访问。如果需要嵌套的子文件夹访问权限,我相信这与原始问题是同一个问题。但是,我认为通过对这个存储桶进行简单直接的重组,我可以通过明确拒绝子文件夹,以及明确允许这些相同子文件夹的其他组来实现它。我相当肯定这也适用于最初的问题,但存储桶的组织方式会使创建和维护策略成为一项繁重的任务。
最后,值得注意的是,此方法无法拒绝对 "folders" 和 "files" 的列表访问。这意味着虽然共享组中的用户可以看到数据和报告文件夹中的文件和文件夹的名称,但他们不能执行任何其他操作(没有 get 或 put aka list access only, no read, no write)
this question references the same aws blog 我一直在尝试利用杠杆来满足我的需求,但没有成功。我一直在研究该答案中的解决方案及其整天引用的示例策略,但没有任何成功。我基本上希望允许不同的 IAM 组完全访问存储桶中的公共子文件夹对象,同时根据组成员有选择地 allowing/denying 访问其他子文件夹对象。
桶结构:
我的财务桶\
my-finance-bucket\files
my-finance-bucket\Our-Finance-Team\
my-finance-bucket\Our-Finance-Team\文件
my-finance-bucket\Our-Finance-Team\报告\
my-finance-bucket\Our-Finance-Team\报告\文件
my-finance-bucket\Our-Finance-Team\Reports\report1-name\
my-finance-bucket\Our-Finance-Team\Reports\report1-name\files
my-finance-bucket\Our-Finance-Team\Reports\report2-名称\
my-finance-bucket\Our-Finance-Team\Reports\report2-name\files
my-finance-bucket\Our-Finance-Team\数据\
my-finance-bucket\Our-Finance-Team\数据\文件
my-finance-bucket\Our-Finance-Team\资料\
my-finance-bucket\Our-Finance-Team\资料\文件
我什至不确定我想做的事情是否可行,但我想创建 3 个组,分别命名为:finance-all、finance-data 和 finance-reports。
我希望所有 3 个组都可以访问:
我的财务桶\
my-finance-bucket\files
my-finance-bucket\Our-Finance-Team\
my-finance-bucket\Our-Finance-Team\文件
my-finance-bucket\Our-Finance-Team\资料\
my-finance-bucket\Our-Finance-Team\资料\文件
此外,我还有这些要求:
finance-all 组有 s3:* 允许访问 my-finance-bucket
下的所有内容
(我认为这很容易,并且可以作为单独的组策略独立存在,允许 s3:* 到 arn:aws:s3:::/my-finance-bucket 和 arn:aws:s3:::/my-finance-桶/*)
finance-data 组具有上面列出的共享访问权限加上 s3:*Object* 允许:
my-finance-bucket\Our-Finance-Team\数据\
my-finance-bucket\Our-Finance-Team\数据\文件
无法访问未指定的任何其他内容
finance-reports 具有上面列出的共享访问权限,加上 s3:*Object* 允许:
my-finance-bucket\Our-Finance-Team\报告\
my-finance-bucket\Our-Finance-Team\报告\文件
my-finance-bucket\Our-Finance-Team\Reports\report1-name\
my-finance-bucket\Our-Finance-Team\Reports\report1-name\files
my-finance-bucket\Our-Finance-Team\Reports\report2-名称\
my-finance-bucket\Our-Finance-Team\Reports\report2-name\files
无法访问未指定的任何其他内容
我知道我必须从允许 "ListAllMyBuckets" 开始,因此代表文件夹和文件的对象将对所有文件夹可见并可列出,递归地。虽然不是最理想的,但它不会阻止不在适当组中的用户查看、获取或放置文件。
我知道大多数人会问 "what have you done" 以试图帮助纠正我已经完成的任何工作 - 然而我已经经历了几十次迭代,甚至没有什么能接近我现在的寻找做。链接答案和链接 aws 博客 post 中列出的代码是我对此进行黑客攻击的起点,可以作为基准
{
"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:::yourbucketname"],
"Condition":{"StringEquals":{"s3:prefix":["","yourfoldername/"],"s3:delimiter":["/"]}}
},
{
"Sid": "AllowListingOfUserFolder",
"Action": ["s3:ListBucket"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::yourbucketname"],
"Condition":{"StringLike":{"s3:prefix":["yourfoldername/*"]}}
},
{
"Sid": "AllowAllS3ActionsInUserFolder",
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::yourbucketname/yourfoldername/*"]
},
{
"Action": [
"s3:*"
],
"Sid": "Stmt1375581921000",
"Resource": [
"arn:aws:s3:::yourbucketname/anotherfolder1/*",
"arn:aws:s3:::yourbucketname/anotherfolder2/*",
"arn:aws:s3:::yourbucketname/anotherfolder3/*",
"arn:aws:s3:::yourbucketname/anotherfolder4/*"
],
"Effect": "Deny"
}
]
}
我最终在这上面花了大约 3 天时间才放弃,并说服有业务需求的人说,如果他们让我重新组织存储桶,我可以在半小时内完成整个工作.他们同意了,所以我最终只是在存储桶中创建了 "subfolders",然后创建了 IAM 组,向每个人授予访问权限 "subfolder"。
所以我像这样重组了存储桶:
我的财务桶/
my-finance-bucket/files
my-finance-bucket/shared/
my-finance-bucket/shared/文件
我的财务桶/
my-finance-bucket/data/
my-finance-bucket/data/文件
my-finance-bucket/reports/
my-finance-bucket/reports/文件
按照这种模式,我浓缩了现有的"subfolders",例如
my-finance-bucket/some-report/*
my-finance-bucket/some-other-report/*
下降到
my-finance-bucket/reports/some-report/*
my-finance-bucket/reports/一些其他报告/*
在 /shared/ 和 /data/ 下压缩内容也是如此
完成此操作后,我能够依靠固有的拒绝功能并简单地允许使用 IAM 组策略访问各个顶级文件夹。通过简单地将用户添加到这些组,我能够有选择地授予对某些子文件夹的访问权限,而不是其他子文件夹。
我为访问每个单独的存储桶而创建的所有策略都遵循以下格式:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowListAllMyBuckets",
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::*"
]
},
{
"Sid": "AllowedListAccess",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketAcl",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::my-finance-bucket",
"arn:aws:s3:::my-finance-bucket/shared"
]
},
{
"Sid": "AllowedObjectAccess",
"Effect": "Allow",
"Action": [
"s3:*Object*"
],
"Resource": [
"arn:aws:s3:::my-finance-bucket/shared/*"
]
}
]
}
请注意,由于 /* 允许列表和对象访问,子文件夹也可供有权访问顶级子文件夹的人访问。如果需要嵌套的子文件夹访问权限,我相信这与原始问题是同一个问题。但是,我认为通过对这个存储桶进行简单直接的重组,我可以通过明确拒绝子文件夹,以及明确允许这些相同子文件夹的其他组来实现它。我相当肯定这也适用于最初的问题,但存储桶的组织方式会使创建和维护策略成为一项繁重的任务。
最后,值得注意的是,此方法无法拒绝对 "folders" 和 "files" 的列表访问。这意味着虽然共享组中的用户可以看到数据和报告文件夹中的文件和文件夹的名称,但他们不能执行任何其他操作(没有 get 或 put aka list access only, no read, no write)