Final Policy = [SCP] AND ([IAM Policies] OR [Resource-based Policies]) where: [IAM Policies] = ?[Permission Boundary] AND [Permission Policy (managed / inline)] AND [Scope-down Policy]
Final Policy = [SCP] AND ([IAM Policies] AND [Resource-based Policies]) where: [IAM Policies] = ?[Permission Boundary] AND [Permission Policy (managed / inline)] AND [Scope-down Policy]
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyUnapprovedAction",
"Effect": "Deny",
"Action" : [
"ds:*",
"iam:createUser",
"cloudtrail:stopLogging"
],
"Resource": [
"*"
]
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action" : [
"secretsmanager:*",
"lambda:*",
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
],
"Resource": [
"*"
],
"Condition": {
"StringEquals": {
"aws:RequestedRegion": ["us-west-1", "us-west-2"]
}
}
},
{
"Effect": "Allow",
"Action" : [
"ec2:RunInstances"
],
"Resource": [
"arn:aws:ec2:*:*::subnet/*",
"arn:aws:ec2:*:*::key-pair/*",
"arn:aws:ec2:*:*::instance/*",
"arn:aws:ec2:*:*::snapshot/*",
"arn:aws:ec2:*:*::launch-template/*",
"arn:aws:ec2:*:*::volume/*",
"arn:aws:ec2:*:*::security-group/*",
"arn:aws:ec2:*:*::placement-group/*",
"arn:aws:ec2:*:*::network-interface/*",
"arn:aws:ec2:*:*::image/*",
],
"Condition": {
"StringEquals": {
"aws:RequestedRegion": ["us-west-1", "us-west-2"]
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:Describe",
"ec2:Get",
"s3:ListBucket",
"s3:ListAllBuckets",
"iam:list"
],
"Resource": "*"
}
]
}
Enable your developers to create IAM roles and pass to EC2 and Lambda, but ensure they cannot exceed their own permissions
Solution (using Permission Boundaries):
In this example, the role created should have unicorns prefix
{
"Effect": "Allow",
"Action": [
"iam:CreatePolicy",
"iam:CreatePolicyVersion",
"iam:DeletePolicyVersion"
],
"Resource": "arn:aws:iam::1234567890:policy/unicorns-*"
}
{
"Effect": "Allow",
"Action": [
"iam:DetachRolePolicy",
"iam:CreateRole",
"iam:AttachRolePolicy"
],
"Resource": "arn:aws:iam::1234567890:role/unicorns-*",
"Condition": {
"StringEquals": {
"iam:PermissionsBoundary": "arn:aws:iam:1234567890:policy/region-restriction"
}
}
}
Enable developers working on Dorky project and the sneaky project to manage their own resources without also managing the other project’s.
Solution:
Use:
RequestTag
- condition to require tag value during create actionsResourceTag
- control access to resources based on a tag that exists on resourcearn:aws:ec2:*:*::instance/*
Resource was removed from first policy and expanded in the one below
{
"Effect": "Allow",
"Action" : [
"ec2:RunInstances"
],
"Resource": [
"arn:aws:ec2:*:*::subnet/*",
"arn:aws:ec2:*:*::key-pair/*",
"arn:aws:ec2:*:*::snapshot/*",
"arn:aws:ec2:*:*::launch-template/*",
"arn:aws:ec2:*:*::volume/*",
"arn:aws:ec2:*:*::security-group/*",
"arn:aws:ec2:*:*::placement-group/*",
"arn:aws:ec2:*:*::network-interface/*",
"arn:aws:ec2:*:*::image/*",
],
"Condition": {
"StringEquals": {
"aws:RequestedRegion": ["us-west-1", "us-west-2"]
}
}
}
{
"Effect": "Allow",
"Action" : [
"ec2:CreateTags"
],
"Resource": [
"*"
],
"Condition": {
"StringEquals": {
"ec2:CreateAction": "RunInstances"
}
}
}
{
"Effect": "Allow",
"Action" : [
"ec2:RunInstances"
],
"Resource": [
"arn:aws:ec2:*:*:instance/*"
],
"Condition": {
"ForAllValues:StringEquals": {
"aws:TagKeys": ["project", "name"]
},
"StringEquals": {
"aws:RequestTag/project": ["dorky"],
"aws:RequestedRegion": ["us-west-1", "us-west-2"]
}
}
}
2. Control which existing resources and values developers can tag
{
"Effect": "Allow",
"Action" : [
"ec2:createTags"
],
"Resource": [
"*"
],
"Condition": {
"StringEquals": {
"ec2:ResourceTag/project": ["dorky"]
},
"ForAllValues:StringEquals": {
"aws:TagKeys": ["project", "name"]
},
"StringEqualsIfExists": {
"aws:RequestTag/project": ["dorky"]
}
}
}
3. Control resources users can manage based on tag values
Users with dorky tag can start/stop instances:
{
"Effect": "Allow",
"Action" : [
"ec2:StartInstances",
"ec2:StopInstances"
],
"Resource": [
"*"
],
"Condition": {
"StringEquals": {
"ec2:ResourceTag/project": ["dorky"]
}
}
}
Policies can be adjusted to have a single general policy and tagging users. This can be achieved using ${aws:PrincipalTag/project}
.
{
"Effect": "Allow",
"Action" : [
"ec2:RunInstances"
],
"Resource": [
"arn:aws:ec2:*:*:instance/*"
],
"Condition": {
"ForAllValues:StringEquals": {
"aws:TagKeys": ["project", "name"]
},
"StringEquals": {
"aws:RequestTag/project": ["${aws:PrincipalTag/project}"],
"aws:RequestedRegion": ["us-west-1", "us-west-2"]
}
}
}