Skip to content

Commit 3a5ec98

Browse files
committed
eli-279 multiple changes to fix deployment issues
1 parent 8ce2fbc commit 3a5ec98

1 file changed

Lines changed: 110 additions & 11 deletions

File tree

infrastructure/stacks/iams-developer-roles/github_actions_policies.tf

Lines changed: 110 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,47 +158,87 @@ resource "aws_iam_policy" "s3_management" {
158158

159159
# API Infrastructure Management Policy
160160
resource "aws_iam_policy" "api_infrastructure" {
161-
#checkov:skip=CKV_AWS_355 EC2 permissions allow all actions on all resources
162-
#checkov:skip=CKV_AWS_288 Role needs access to SSM and logs
163-
#checkov:skip=CKV_AWS_290 Write access limited to tags and network ACL entries
164-
165161
name = "api-infrastructure-management"
166162
description = "Policy granting permissions to manage API infrastructure"
167163
path = "/service-policies/"
168164

169165
policy = jsonencode({
170166
Version = "2012-10-17",
171167
Statement = [
168+
{
169+
Effect = "Allow",
170+
Action = [
171+
"logs:Describe*",
172+
"ssm:DescribeParameters",
173+
"ec2:Describe*",
174+
"ec2:DescribeVpcs",
175+
],
176+
Resource = "*"
177+
#checkov:skip=CKV_AWS_289: Actions require wildcard resource
178+
},
172179
{
173180
Effect = "Allow",
174181
Action = [
175182

176183
# Cloudwatch permissions
177-
"logs:Describe*",
178184
"logs:ListTagsForResource",
179185
"logs:PutRetentionPolicy",
180186
"logs:AssociateKmsKey",
187+
"logs:CreateLogGroup",
181188

182-
#EC2 permissions
183-
"ec2:Describe*",
189+
# EC2 permissions
184190
"ec2:CreateTags",
185191
"ec2:CreateNetworkAclEntry",
192+
"ec2:CreateNetworkAcl",
193+
"ec2:AssociateRouteTable",
194+
"ec2:CreateVpc",
195+
"ec2:ModifyVpcAttribute",
196+
"ec2:DeleteVpc",
197+
"ec2:CreateRouteTable",
198+
"ec2:CreateSubnet",
199+
"ec2:RevokeSecurityGroupIngress",
200+
"ec2:CreateSecurityGroup",
201+
"ec2:RevokeSecurityGroupEgress",
202+
"ec2:AuthorizeSecurityGroupIngress",
203+
"ec2:AuthorizeSecurityGroupEgress",
204+
"ec2:CreateVpcEndpoint",
205+
"ec2:CreateFlowLogs",
206+
"ec2:ReplaceNetworkAclAssociation",
207+
"ec2:DeleteSecurityGroup",
208+
"ec2:DeleteNetworkAcl",
186209

187210
# ssm
188211
"ssm:GetParameter",
189212
"ssm:GetParameters",
190-
"ssm:DescribeParameters",
191213
"ssm:ListTagsForResource",
214+
"ssm:PutParameter",
215+
"ssm:AddTagsToResource",
192216

193217
# acm
194218
"acm:ListCertificates",
195219
"acm:DescribeCertificate",
196220
"acm:GetCertificate",
197221
"acm:ListTagsForCertificate",
222+
"acm:RequestCertificate",
223+
"acm:AddTagsToCertificate",
224+
"acm:ImportCertificate",
198225
],
199226

200227

201-
Resource = "*"
228+
Resource = [
229+
"arn:aws:ec2:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:vpc/*",
230+
"arn:aws:ec2:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:vpc-endpoint/*",
231+
"arn:aws:ec2:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:vpc-flow-log/*",
232+
"arn:aws:ec2:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:subnet/*",
233+
"arn:aws:ec2:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:route-table/*",
234+
"arn:aws:ec2:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:network-acl/*",
235+
"arn:aws:ec2:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:security-group/*",
236+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/vpc/*",
237+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/*",
238+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/apigateway/*",
239+
"arn:aws:ssm:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.environment}/*",
240+
"arn:aws:acm:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:certificate/*",
241+
]
202242
}
203243
]
204244
})
@@ -211,6 +251,56 @@ resource "aws_iam_policy" "api_infrastructure" {
211251
)
212252
}
213253

254+
# Create KMS keys policy for GitHub Actions
255+
resource "aws_iam_policy" "kms_creation" {
256+
name = "github-actions-kms-creation"
257+
description = "Policy allowing GitHub Actions to manage KMS keys"
258+
path = "/service-policies/"
259+
260+
policy = jsonencode({
261+
Version = "2012-10-17",
262+
Statement = [
263+
{
264+
Effect = "Allow",
265+
Action = [
266+
"kms:CreateKey",
267+
"kms:CreateAlias",
268+
"kms:List*",
269+
"kms:ListAliases",
270+
],
271+
Resource = "*"
272+
#checkov:skip=CKV_AWS_289: Actions require wildcard resource
273+
},
274+
{
275+
Effect = "Allow",
276+
Action = [
277+
"kms:Describe*",
278+
"kms:GetKeyPolicy*",
279+
"kms:GetKeyRotationStatus",
280+
"kms:Decrypt*",
281+
"kms:DeleteAlias",
282+
"kms:UpdateKeyDescription",
283+
"kms:CreateGrant",
284+
"kms:TagResource",
285+
"kms:EnableKeyRotation",
286+
"kms:ScheduleKeyDeletion",
287+
"kms:PutKeyPolicy",
288+
"kms:Encrypt",
289+
"kms:TagResource",
290+
"kms:GenerateDataKey",
291+
],
292+
Resource = [
293+
"arn:aws:kms:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:key/*",
294+
"arn:aws:kms:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:alias/*"
295+
]
296+
}
297+
]
298+
})
299+
300+
tags = merge(local.tags, { Name = "github-actions-kms-creation" })
301+
}
302+
303+
214304
# IAM Management Policy
215305
resource "aws_iam_policy" "iam_management" {
216306
name = "iam-management"
@@ -234,7 +324,9 @@ resource "aws_iam_policy" "iam_management" {
234324
"iam:PutRolePermissionsBoundary",
235325
"iam:AttachRolePolicy",
236326
"iam:DetachRolePolicy",
237-
"iam:CreatePolicyVersion"
327+
"iam:CreatePolicyVersion",
328+
"iam:TagRole",
329+
"iam:PassRole",
238330
],
239331
Resource = [
240332
# Lambda role
@@ -245,7 +337,9 @@ resource "aws_iam_policy" "iam_management" {
245337
"arn:aws:iam::*:role/eligibility-signposting-api-*-external-write-role",
246338
# Project policies
247339
"arn:aws:iam::*:policy/*api-gateway-logging-policy",
248-
"arn:aws:iam::*:policy/*PermissionsBoundary"
340+
"arn:aws:iam::*:policy/*PermissionsBoundary",
341+
# VPC flow logs role
342+
"arn:aws:iam::*:role/vpc-flow-logs-role",
249343
]
250344
}
251345
]
@@ -307,6 +401,11 @@ resource "aws_iam_role_policy_attachment" "s3_management" {
307401
policy_arn = aws_iam_policy.s3_management.arn
308402
}
309403

404+
resource "aws_iam_role_policy_attachment" "kms_creation" {
405+
role = aws_iam_role.github_actions.name
406+
policy_arn = aws_iam_policy.kms_creation.arn
407+
}
408+
310409
resource "aws_iam_role_policy_attachment" "iam_management" {
311410
role = aws_iam_role.github_actions.name
312411
policy_arn = aws_iam_policy.iam_management.arn

0 commit comments

Comments
 (0)