In this Demo, we will:
Production
prod-account
learnpde+prod@gmail.com
learnpde+dev@gmail.com
dev-account
Development-Service-Control-Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "LimitEC2InstanceTypes",
"Effect": "Deny",
"Action": "ec2:RunInstances",
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"StringNotLike": {
"ec2:InstanceType": [
"t2.*",
"t3.*"
]
}
}
},
{
"Sid": "DenyNonApprovedRegions",
"Effect": "Deny",
"Action": "*",
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:RequestedRegion": [
"us-east-1",
"us-west-2"
]
}
}
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceProductionRegions",
"Effect": "Deny",
"Action": "*",
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:RequestedRegion": [
"us-east-1",
"us-west-2"
]
}
}
},
{
"Sid": "RequireEncryptedEBSVolumes",
"Effect": "Deny",
"Action": [
"ec2:RunInstances",
"ec2:CreateVolume"
],
"Resource": [
"arn:aws:ec2:*:*:volume/*",
"arn:aws:ec2:*:*:instance/*"
],
"Condition": {
"Bool": {
"ec2:Encrypted": "false"
}
}
},
{
"Sid": "DenyDeleteProductionTags",
"Effect": "Deny",
"Action": [
"ec2:DeleteTags",
"s3:DeleteObjectTagging",
"rds:RemoveTagsFromResource"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/Environment": "Production"
}
}
},
{
"Sid": "RequireResourceTags",
"Effect": "Deny",
"Action": [
"ec2:RunInstances",
"rds:CreateDBInstance",
"s3:CreateBucket"
],
"Resource": "*",
"Condition": {
"Null": {
"aws:RequestTag/Environment": "true",
"aws:RequestTag/CostCenter": "true",
"aws:RequestTag/Project": "true"
}
}
}
]
}
dev-tag-policy
{
"tags": {
"Environment": {
"tag_key": {
"@@assign": "Environment"
},
"tag_value": {
"@@assign": [
"dev"
]
},
"enforced_for": {
"@@assign": [
"ec2:instance",
"s3:bucket"
]
}
},
"Project": {
"tag_key": {
"@@assign": "Project"
},
"tag_value": {
"@@assign": [
"alpha",
"beta",
"demo"
]
},
"enforced_for": {
"@@assign": [
"ec2:instance",
"s3:bucket"
]
}
}
}
}
prod-tag-policy
{
"tags": {
"environment": {
"tag_key": {
"@@assign": "Environment"
},
"tag_value": {
"@@assign": [
"prod"
]
},
"enforced_for": {
"@@assign": [
"ec2:instance",
"s3:bucket"
]
}
},
"costcenter": {
"tag_key": {
"@@assign": "CostCenter"
},
"tag_value": {
"@@assign": [
"101",
"102",
"103"
]
},
"enforced_for": {
"@@assign": [
"ec2:instance",
"s3:bucket"
]
}
}
}
}
https://796973489092.signin.aws.amazon.com/console
T2-Large
M5-Large
aws organizations enable-aws-service-access --service-principal tagpolicies.tag.amazonaws.com
wrongtag
purpose
experiment
Environment
notinlist
dev
myownkey
myownvalue
{
"Sid": "RequireMandatoryTags",
"Effect": "Deny",
"Action": [
"ec2:RunInstances"
],
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"Null": {
"aws:RequestTag/Environment": "true",
"aws:RequestTag/Project": "true"
}
}
},
{
"Sid": "EnforceTagValues",
"Effect": "Deny",
"Action": [
"ec2:RunInstances"
],
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"ForAnyValue:StringNotLike": {
"aws:RequestTag/Environment": [
"dev"
],
"aws:RequestTag/Project": [
"alpha",
"beta",
"demo"
]
}
}
}
Environment
dev
project
alpha
Test-Tags