我最初设置 SES 来接收电子邮件,在此过程中,我创建了一个存储桶策略,允许该服务将电子邮件放入 S3。我现在有一个 lambda 函数,它应该能够使用 STS 承担角色并访问同一个存储桶。不幸的是,我无法找出正确的策略来允许服务和 IAM 角色访问同一个存储桶,现在我得到“拒绝访问”。我使用策略模拟器来验证其他一切是否正常运行,例如,我添加了一个通用策略,对目标角色有更多操作,如果我告诉模拟器忽略存储桶策略,那么它说它可以访问文件。
我试过有两个语句,一个将主体设置为“服务”,另一个设置为目标角色(添加两个只是为了看看是否可以工作)
{
"Version": "2012-10-17",
"Id": "Policy1478013193612",
"Statement": [
{
"Sid": "Stmt1478013187203",
"Effect": "Allow",
"Principal": {
"Service": "ses.amazonaws.com"
},
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::email-01-bucket/*"
},
{
"Sid": "Stmt55",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:sts::[id-num-with-no-dashes]:assumed-role/[role-name]/[session-name]",
"arn:aws:iam::[id-num-with-no-dashes]:role/[role-name]"
]
},
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::email-01-bucket/*"
}
]
}
我还尝试将其放入 1 个语句中:
{
"Version": "2012-10-17",
"Id": "Policy1478013193612",
"Statement": [
{
"Sid": "Stmt1478013187203",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:sts::[id-num-with-no-dashes]:assumed-role/[role-name]/[session-name]",
"arn:aws:iam::[id-num-with-no-dashes]:role/[role-name]"
],
"Service": "ses.amazonaws.com"
},
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::email-01-bucket/*"
}
]
}
顺便说一句,文件路径是:arn:aws:s3:::email-01-bucket/email/[file-id]
我不能放 ListBucket 因为它会引发错误。
任何帮助表示赞赏:D
让我知道我是否应该添加其他任何内容
[更新]
为了使找到正确的策略更容易,我将描述我目前在 IAM 策略模拟器中设置的内容,我假设如果我们可以让它在这里工作,那么它应该在 lambda 函数上工作。
角色:服务开发
此角色附加了两个策略。
1)服务FS:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:PutBucketLogging",
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::email-01-bucket/*"
}
]
}
2) AWSLambdaBasicExecutionRole
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
在策略模拟器中:
下拉菜单Select Service
设置为S3
下拉菜单Select Action
设置为GetObject
在Resource
>Object
我输入一个现有文件的路径arn:aws:s3:::email-01-bucket/email/u245hnt85uivpfkrrlhgo0jt86gfjgnca2fgocg1
(在仔细检查文件是否确实存在之后)
一旦我这样做了,现在Resource Policies
左侧有一个部分显示了附加到我的存储桶的存储桶策略,其中包含以下策略:
{
"Version": "2012-10-17",
"Id": "Policy1478013193612",
"Statement": [
{
"Sid": "Stmt1478013187203",
"Effect": "Allow",
"Principal": {
"Service": "ses.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::email-01-bucket/*"
}
]
}
现在这里是我迷路的地方,回到Resource
>Object
区域,我在其中指定现有文件的路径,有一个标记为 的复选框Include Resource Policy
,如果我取消选中它,那么模拟器说权限是允许的,但是如果我选中它然后我得到以下错误:
The simulation could not be performed! : Simulation failed!