Skip to content

Commit eb354d0

Browse files
authored
fix: Limit iam:PassRole to the role passed (#376)
* Limit policy iam:PassRole to the role passed Co-authored-by: kayma <[email protected]>
1 parent 950f6b4 commit eb354d0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

main.tf

+5-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,11 @@ resource "aws_iam_policy" "instance_docker_machine_policy" {
350350
name = "${local.name_iam_objects}-docker-machine"
351351
path = "/"
352352
description = "Policy for docker machine."
353-
policy = templatefile("${path.module}/policies/instance-docker-machine-policy.json", {})
354-
tags = local.tags
353+
policy = templatefile("${path.module}/policies/instance-docker-machine-policy.json",
354+
{
355+
docker_machine_role_arn = aws_iam_role.docker_machine.arn
356+
})
357+
tags = local.tags
355358
}
356359

357360
resource "aws_iam_role_policy_attachment" "instance_docker_machine_policy" {

policies/instance-docker-machine-policy.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@
1717
"ec2:RequestSpotInstances",
1818
"ec2:CancelSpotInstanceRequests",
1919
"ec2:DescribeSubnets",
20-
"ec2:AssociateIamInstanceProfile",
21-
"iam:PassRole"
20+
"ec2:AssociateIamInstanceProfile"
2221
],
2322
"Effect": "Allow",
2423
"Resource": "*"
24+
},
25+
{
26+
"Action": [
27+
"iam:PassRole"
28+
],
29+
"Effect": "Allow",
30+
"Resource": "${docker_machine_role_arn}"
2531
}
2632
]
2733
}

0 commit comments

Comments
 (0)