Skip to content

Commit

Permalink
fix: Limit iam:PassRole to the role passed (#376)
Browse files Browse the repository at this point in the history
* Limit policy iam:PassRole to the role passed

Co-authored-by: kayma <[email protected]>
  • Loading branch information
kayman-mk and kayman-mk authored Oct 6, 2021
1 parent 950f6b4 commit eb354d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,11 @@ resource "aws_iam_policy" "instance_docker_machine_policy" {
name = "${local.name_iam_objects}-docker-machine"
path = "/"
description = "Policy for docker machine."
policy = templatefile("${path.module}/policies/instance-docker-machine-policy.json", {})
tags = local.tags
policy = templatefile("${path.module}/policies/instance-docker-machine-policy.json",
{
docker_machine_role_arn = aws_iam_role.docker_machine.arn
})
tags = local.tags
}

resource "aws_iam_role_policy_attachment" "instance_docker_machine_policy" {
Expand Down
10 changes: 8 additions & 2 deletions policies/instance-docker-machine-policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
"ec2:RequestSpotInstances",
"ec2:CancelSpotInstanceRequests",
"ec2:DescribeSubnets",
"ec2:AssociateIamInstanceProfile",
"iam:PassRole"
"ec2:AssociateIamInstanceProfile"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"iam:PassRole"
],
"Effect": "Allow",
"Resource": "${docker_machine_role_arn}"
}
]
}

0 comments on commit eb354d0

Please sign in to comment.