Skip to content

Instantly share code, notes, and snippets.

@rdp-cloud
Created October 19, 2017 22:50
Show Gist options
  • Save rdp-cloud/16a4330282c251e6cace08f6a49a5135 to your computer and use it in GitHub Desktop.
Save rdp-cloud/16a4330282c251e6cace08f6a49a5135 to your computer and use it in GitHub Desktop.
Example AWS IAM Security Policy to enforce tag usage during deployment
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:RunInstances"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:CreateTags"
            ],
            "Resource": "arn:aws:ec2:*:*:instance/*",
            "Condition": {
                "StringEquals": {
                    "ec2:CreateAction": "RunInstances"
                }
            }
        },
        {
            "Effect": "Deny",
            "Action": [
                "ec2:RunInstances"
            ],
            "Resource": [
                "arn:aws:ec2:*:*:instance/*"
            ],
            "Condition": {
                "Null": {
                    "aws:RequestTag/costcenter": "true"
                }
            }
        },
        {
            "Effect": "Deny",
            "Action": "ec2:RunInstances",
            "Resource": "*",
            "Condition": {
                "ForAnyValue:StringNotEquals": {
                    "aws:RequestTag/costcenter": [
                        "1",
                        "2",
                        "3"
                    ]
                }
            }
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment