我正在使用该策略将RunIstances仅限制为特定的实例类型和特定区域。当我在测试用户下运行启动向导或模拟时,我收到“隐式拒绝”错误。
这是政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": [
"arn:aws:ec2:us-east-1::instance/*"
],
"Condition": {
"StringEquals": {
"ec2:InstanceType": [
"t1.micro",
"m1.small"
]
}
}
},
{
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": [
"arn:aws:ec2:us-east-1::image/ami-*",
"arn:aws:ec2:us-east-1::subnet/*",
"arn:aws:ec2:us-east-1::network-interface/*",
"arn:aws:ec2:us-east-1::volume/*",
"arn:aws:ec2:us-east-1::key-pair/*",
"arn:aws:ec2:us-east-1::security-group/*"
]
},
{
"Effect": "Allow",
"Action": [
"ec2:Describe*",
"ec2:CreateSecurityGroup",
"ec2:DeleteSecurityGroup",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:AuthorizeSecurityGroupEgress",
"ec2:CreateKeyPair"
],
"Resource": [
"*"
]
}
]
}
有人可以指出这个问题吗?
答案 0 :(得分:2)
在资源块中,在两个"之间插入一个星号:"在arn行中,指定所有帐户,或将其替换为您的帐号。
"arn:aws:ec2:us-east-1:*:instance/*"
"arn:aws:ec2:us-east-1:*:image/ami-*",
"arn:aws:ec2:us-east-1:*:subnet/*",
"arn:aws:ec2:us-east-1:*:network-interface/*",
"arn:aws:ec2:us-east-1:*:volume/*",
"arn:aws:ec2:us-east-1:*:key-pair/*",
"arn:aws:ec2:us-east-1:*:security-group/*"
答案 1 :(得分:1)
请参阅IAM政策生成工具。您的代码看起来不正确。
首先,允许EC2中的所有操作。接下来,拒绝EC2中的特定操作。
允许EC2中所有操作的示例:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"NotAction": "ec2:*",
"Resource": "*"
}
]
}
拒绝在特定区域中创建资源的示例:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyTheseActions",
"Effect": "Deny",
"Action": [
"ec2:RunInstances",
"ec2:StartInstances"
],
"Resource": "arn:aws:ec2:us-west-1",
"Resource": "arn:aws:ec2:us-east-1",
"Resource": "arn:aws:ec2:eu-west-1",
"Resource": "arn:aws:ec2:sa-east-1",
"Resource": "arn:aws:ec2:ap-northeast-1",
"Resource": "arn:aws:ec2:ap-southeast-1",
"Resource": "arn:aws:ec2:ap-southeast-2"
}
]
}
答案 2 :(得分:0)
当前控制访问AWS区域,EC2和RDS实例大小和类型的更简单方法可能是将IAM策略与"target": "es2020"
(可选)策略元素一起使用– 让您指定何时政策有效。
我们将使用Condition
语句设置 AWS IAM策略,这将允许完整的AWS EC2 和 RDS 服务,严格来说是3 more cost effective-> AWS regions,
将不允许所有其他区域,此策略还设置了用于启动 EC2 和 RDS实例的条件访问控制。而不是指定所有可能的type/class实例运行,我们在语句中使用Condition
效果,这允许通过实例大小(Deny
,{{1 }},micro
和small
)。这具有防止其他任何策略覆盖该阻止的进一步效果。
medium