I can’t find a valid way to restrict this permission. I would ideally like to restrict the permission to work in a particular VPC and/or subnet. I’m unsure where in the documentation to look & have tried numerous approaches with all failing.
My JSON is like this roughly & have tried lots of things in the resource and condition fields:
{
"Effect": "Allow",
"Action": [
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface"
],
"Resource": [
"*"
],
"Condition": {
"StringLike": {
"ec2:XXXXX": "*"
}
}
}
}
EDIT: Key detail I missed, I am using a role with these permissions to attach to an AWS Glue job. When I restrict in the normal way, the job fails and says it doesn’t have the required permissions.
2
Answers
According to Actions, resources, and condition keys for Amazon EC2 – Service Authorization Reference, the
CreateNetworkInterface
Action allows a Condition ofec2:Vpc
that "Filters access by the ARN of the VPC".There is an example policy on Amazon VPC policy examples – Amazon Virtual Private Cloud that uses it in this way:
Create an IAM policy with the ec2:CreateNetworkInterface action.
Within the policy statement, add a Condition block.
Inside the Condition block, use the StringEqualsIfExists key with the following structure: