Skip to content

Commit

Permalink
fix: reduce permission required for session manager
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm committed Jul 26, 2021
1 parent 6278c17 commit 82c4ee1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/runners/policies-runner.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ resource "aws_iam_instance_profile" "runner" {
path = local.instance_profile_path
}

resource "aws_iam_role_policy_attachment" "runner_session_manager_aws_managed" {
count = var.enable_ssm_on_runners ? 1 : 0
role = aws_iam_role.runner.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
resource "aws_iam_role_policy" "runner_session_manager_aws_managed" {
name = "runner-ssm-session"
count = var.enable_ssm_on_runners ? 1 : 0
role = aws_iam_role.runner.name
policy = templatefile("${path.module}/policies/instance-ssm-policy.json", {})
}

resource "aws_iam_role_policy" "ssm_parameters" {
Expand Down
46 changes: 46 additions & 0 deletions modules/runners/policies/instance-ssm-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeAssociation",
"ssm:GetDeployablePatchSnapshotForInstance",
"ssm:GetDocument",
"ssm:DescribeDocument",
"ssm:GetManifest",
"ssm:ListAssociations",
"ssm:ListInstanceAssociations",
"ssm:PutInventory",
"ssm:PutComplianceItems",
"ssm:PutConfigurePackageResult",
"ssm:UpdateAssociationStatus",
"ssm:UpdateInstanceAssociationStatus",
"ssm:UpdateInstanceInformation"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ec2messages:AcknowledgeMessage",
"ec2messages:DeleteMessage",
"ec2messages:FailMessage",
"ec2messages:GetEndpoint",
"ec2messages:GetMessages",
"ec2messages:SendReply"
],
"Resource": "*"
}
]
}

0 comments on commit 82c4ee1

Please sign in to comment.