我正在 VPC 中部署 lambda 函数 - StatusCheck
。该函数是使用 awscli 从在我的 k8s 集群中工作节点上运行的 pod 之一部署的。我将 AWSLambdaVPCAccessExecutionRole
策略附加到 k8s 工作节点,该策略看起来像
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface",
"ec2:AssignPrivateIpAddresses",
"ec2:UnassignPrivateIpAddresses"
],
"Resource": "*"
}
]
}
很明显,默认情况下它还允许 k8s 集群中的其他 pod 创建/删除不需要的网络接口。
更新上述政策以添加资源不起作用。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface",
"ec2:AssignPrivateIpAddresses",
"ec2:UnassignPrivateIpAddresses"
],
"Resource": "arn:aws:lambda:*:77777777:function:*StatusCheck*"
}
]
}
错误:
StatusCheck. Create Failed. Resource handler returned message: "The provided execution role does not have permissions to call CreateNetworkInterface on EC2 (Service: Lambda, Status Code: 400
是否可以将创建/删除 ENI 仅限于 lambda 函数 StatusCheck
?
答案 0 :(得分:0)
您的策略的问题在于您指定的操作不适用于 Lambda 函数资源。 Lambda 使用它们来调用其他服务(以及其他非 Lambda 资源)。
查看 IAM actions for EC2 页面上的 CreateNetworkInterface
条目(您收到错误)表明它针对网络接口和子网 em>(以及可选的安全组),因此如果您想将其限制为资源的子集,则需要制作多个资源名称(使用通配符,就像您尝试的那样)来匹配这些资源。
答案 1 :(得分:0)
在使用 AWS SAM 时遇到了同样的问题。我还必须添加“ec2:DescribeInstances”权限。 所以我的完整政策是:
- Effect: "Allow"
Action:
[
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
]
Resource: "arn:aws:logs:*:*:*"
- Effect: "Allow"
Action:
[
"ec2:DescribeNetworkInterfaces",
"ec2:CreateNetworkInterface",
"ec2:AttachNetworkInterface",
"ec2:DescribeInstances",
"ec2:DeleteNetworkInterface"
]
Resource: "arn:aws:ec2:*:*:*"