Skip to content

Instantly share code, notes, and snippets.

@scottnixonjr
Created April 16, 2020 18:10
Show Gist options
  • Select an option

  • Save scottnixonjr/e7262fd2798ea066bc7032c24f5d8e1f to your computer and use it in GitHub Desktop.

Select an option

Save scottnixonjr/e7262fd2798ea066bc7032c24f5d8e1f to your computer and use it in GitHub Desktop.
Individual Access Control based on Username for creating EC2 Instances. Policy for Solution 2 in Developer Sandboxes - https://github.com/stelligent/developer-sandboxes
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"StringEqualsIgnoreCase": {
"aws:RequestTag/username": "${aws:username}"
},
"ForAllValues:StringEquals": {
"aws:TagKeys": "username"
}
}
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "ec2:CreateTags",
"Resource": "arn:aws:ec2:*:*:*/*",
"Condition": {
"StringEquals": {
"ec2:CreateAction": "RunInstances"
}
}
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": "ec2:CreateTags",
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"StringEqualsIgnoreCase": {
"ec2:ResourceTag/username": "${aws:username}",
"aws:RequestTag/username": "${aws:username}"
},
"ForAllValues:StringEquals": {
"aws:TagKeys": "username"
}
}
},
{
"Sid": "VisualEditor3",
"Effect": "Allow",
"Action": [
"ec2:StartInstances",
"ec2:StopInstances",
"ec2:TerminateInstances"
],
"Resource": "*",
"Condition": {
"StringEqualsIgnoreCase": {
"ec2:ResourceTag/username": "${aws:username}"
}
}
},
{
"Sid": "VisualEditor4",
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": [
"arn:aws:ec2:*:*:subnet/*",
"arn:aws:ec2:*:*:key-pair/*",
"arn:aws:ec2:*:*:launch-template/*",
"arn:aws:ec2:*::snapshot/*",
"arn:aws:ec2:*:*:volume/*",
"arn:aws:ec2:*:*:security-group/*",
"arn:aws:ec2:*:*:placement-group/*",
"arn:aws:ec2:*:*:network-interface/*",
"arn:aws:ec2:*::image/*"
]
},
{
"Sid": "PermissionsForRunningTestsOnly",
"Effect": "Allow",
"Action": [
"cloudformation:ListExports",
"sts:DecodeAuthorizationMessage",
"iam:GetUser"
],
"Resource": "*"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment