Skip to content

Commit b90318e

Browse files
[odin-297] condensing to fewer policies
1 parent c45ebae commit b90318e

File tree

3 files changed

+61
-168
lines changed

3 files changed

+61
-168
lines changed

.github/workflows/deploy-sandbox.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ jobs:
5757
aws-region: ${{ vars.AWS_REGION }}
5858
mask-aws-account-id: true
5959

60-
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
6160
- name: Setup Terraform
6261
uses: hashicorp/setup-terraform@v3
6362
with:
@@ -148,7 +147,7 @@ jobs:
148147
- name: Configure AWS Credentials
149148
uses: aws-actions/configure-aws-credentials@v5
150149
with:
151-
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
150+
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }} # TODO: Needs to be new rule
152151
role-skip-session-tagging: true
153152
aws-region: ${{ vars.AWS_REGION }}
154153
mask-aws-account-id: true

.github/workflows/tear-down-sandbox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
- name: Configure AWS Credentials
9191
uses: aws-actions/configure-aws-credentials@v5
9292
with:
93-
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
93+
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }} # TODO: Needs to be new rule
9494
aws-region: ${{ vars.AWS_REGION }}
9595
mask-aws-account-id: true
9696

pre_core/iam_github_dev.tf

Lines changed: 59 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ resource "aws_iam_role" "github_role_dev" {
3636
description = "This role is to provide access for GitHub actions to the development environment. "
3737
force_detach_policies = false
3838
managed_policy_arns = [
39-
aws_iam_policy.config_policy_dev[0].arn,
40-
aws_iam_policy.ecr_github_access_policy_dev[0].arn,
41-
aws_iam_policy.github_actions_terraform_full_dev[0].arn,
42-
aws_iam_policy.github_mtls_gateway_dev[0].arn,
43-
aws_iam_policy.github_terraform_tagging_policy_dev[0].arn,
44-
aws_iam_policy.lambda_github_access_policy_dev[0].arn,
45-
aws_iam_policy.repo_app_config_dev[0].arn,
46-
aws_iam_policy.terraform_github_dynamodb_access_policy_dev[0].arn,
47-
aws_iam_policy.terraform_github_s3_access_policy_dev[0].arn,
39+
# aws_iam_policy.config_policy_dev[0].arn,
40+
# aws_iam_policy.ecr_github_access_policy_dev[0].arn,
41+
# aws_iam_policy.github_actions_terraform_full_dev[0].arn,
42+
# aws_iam_policy.github_mtls_gateway_dev[0].arn,
43+
# aws_iam_policy.github_terraform_tagging_policy_dev[0].arn,
44+
# aws_iam_policy.lambda_github_access_policy_dev[0].arn,
45+
# aws_iam_policy.repo_app_config_dev[0].arn,
46+
# aws_iam_policy.terraform_github_dynamodb_access_policy_dev[0].arn,
47+
# aws_iam_policy.terraform_github_s3_access_policy_dev[0].arn,
48+
aws_iam_policy.github_actions_extended[0].arn,
4849
"arn:aws:iam::aws:policy/ReadOnlyAccess",
4950
]
5051
max_session_duration = 3600
51-
name = "${terraform.workspace}-github-role"
52+
name = "${terraform.workspace}-github-actions-role"
5253
name_prefix = null
5354
path = "/"
5455
permissions_boundary = null
@@ -269,72 +270,6 @@ resource "aws_iam_role" "github_role_dev" {
269270
}
270271

271272

272-
# aws_iam_policy.config_policy_dev[0]:
273-
resource "aws_iam_policy" "config_policy_dev" {
274-
count = local.is_sandbox_or_dev ? 1 : 0
275-
description = null
276-
name = "${terraform.workspace}-config-policy"
277-
name_prefix = null
278-
path = "/"
279-
policy = jsonencode(
280-
{
281-
Statement = [
282-
{
283-
Action = [
284-
"config:DeleteDeliveryChannel",
285-
"config:PutConfigurationRecorder",
286-
"config:StopConfigurationRecorder",
287-
"config:StartConfigurationRecorder",
288-
"config:PutDeliveryChannel",
289-
"config:DeleteConfigurationRecorder",
290-
"config:DescribeConfigurationRecorderStatus",
291-
]
292-
Effect = "Allow"
293-
Resource = "*"
294-
Sid = "VisualEditor0"
295-
},
296-
]
297-
Version = "2012-10-17"
298-
}
299-
)
300-
tags = {}
301-
tags_all = {}
302-
}
303-
304-
305-
# aws_iam_policy.ecr_github_access_policy_dev[0]:
306-
resource "aws_iam_policy" "ecr_github_access_policy_dev" {
307-
count = local.is_sandbox_or_dev ? 1 : 0
308-
description = null
309-
name = "${terraform.workspace}-ecr-github-access-policy"
310-
name_prefix = null
311-
path = "/"
312-
policy = jsonencode(
313-
{
314-
Statement = [
315-
{
316-
Action = [
317-
"ecr:GetDownloadUrlForLayer",
318-
"ecr:BatchGetImage",
319-
"ecr:CompleteLayerUpload",
320-
"ecr:UploadLayerPart",
321-
"ecr:InitiateLayerUpload",
322-
"ecr:BatchCheckLayerAvailability",
323-
"ecr:PutImage",
324-
]
325-
Effect = "Allow"
326-
Resource = "arn:aws:ecr:eu-west-2:*:repository/*"
327-
Sid = "VisualEditor0"
328-
},
329-
]
330-
Version = "2012-10-17"
331-
}
332-
)
333-
tags = {}
334-
tags_all = {}
335-
}
336-
337-
338273
# aws_iam_policy.github_actions_terraform_full_dev[0]:
339274
resource "aws_iam_policy" "github_actions_terraform_full_dev" {
340275
count = local.is_sandbox_or_dev ? 1 : 0
@@ -591,16 +526,58 @@ resource "aws_iam_policy" "github_actions_terraform_full_dev" {
591526
}
592527

593528

594-
# aws_iam_policy.github_mtls_gateway_dev[0]:
595-
resource "aws_iam_policy" "github_mtls_gateway_dev" {
529+
530+
# aws_iam_policy.
531+
# Incorporates permissions from:
532+
# config_policy
533+
# ecr_github_access_policy
534+
# github_mtls_gateway
535+
# github_terraform_tagging_policy
536+
# lambda_github_access_policy
537+
# repo_app_config
538+
# terraform_github_dynamodb_access_policy
539+
# terraform_github_s3_access_policy
540+
resource "aws_iam_policy" "github_actions_extended" {
596541
count = local.is_sandbox_or_dev ? 1 : 0
597542
description = null
598-
name = "${terraform.workspace}-github_mtls_gateway"
543+
name = "${terraform.workspace}-github_actions_extended"
599544
name_prefix = null
600545
path = "/"
601546
policy = jsonencode(
602547
{
603548
Statement = [
549+
{
550+
Action = [
551+
"config:DeleteDeliveryChannel",
552+
"config:PutConfigurationRecorder",
553+
"config:StopConfigurationRecorder",
554+
"config:StartConfigurationRecorder",
555+
"config:PutDeliveryChannel",
556+
"config:DeleteConfigurationRecorder",
557+
"config:DescribeConfigurationRecorderStatus",
558+
]
559+
Effect = "Allow"
560+
Resource = "*"
561+
Sid = "VisualEditor0"
562+
},
563+
564+
565+
{
566+
Action = [
567+
"ecr:GetDownloadUrlForLayer",
568+
"ecr:BatchGetImage",
569+
"ecr:CompleteLayerUpload",
570+
"ecr:UploadLayerPart",
571+
"ecr:InitiateLayerUpload",
572+
"ecr:BatchCheckLayerAvailability",
573+
"ecr:PutImage",
574+
]
575+
Effect = "Allow"
576+
Resource = "arn:aws:ecr:eu-west-2:*:repository/*"
577+
Sid = "VisualEditor0"
578+
},
579+
580+
604581
{
605582
Action = [
606583
"acm:RequestCertificate",
@@ -656,25 +633,8 @@ resource "aws_iam_policy" "github_mtls_gateway_dev" {
656633
Resource = "arn:aws:apigateway:eu-west-2::/domainnames"
657634
Sid = "VisualEditor4"
658635
},
659-
]
660-
Version = "2012-10-17"
661-
}
662-
)
663-
tags = {}
664-
tags_all = {}
665-
}
666636

667637

668-
# aws_iam_policy.github_terraform_tagging_policy_dev[0]:
669-
resource "aws_iam_policy" "github_terraform_tagging_policy_dev" {
670-
count = local.is_sandbox_or_dev ? 1 : 0
671-
description = null
672-
name = "${terraform.workspace}-github_terraform_tagging_policy"
673-
name_prefix = null
674-
path = "/"
675-
policy = jsonencode(
676-
{
677-
Statement = [
678638
{
679639
Action = [
680640
"sns:TagResource",
@@ -768,25 +728,8 @@ resource "aws_iam_policy" "github_terraform_tagging_policy_dev" {
768728
Resource = "*"
769729
Sid = "VisualEditor2"
770730
},
771-
]
772-
Version = "2012-10-17"
773-
}
774-
)
775-
tags = {}
776-
tags_all = {}
777-
}
778731

779732

780-
# aws_iam_policy.lambda_github_access_policy_dev[0]:
781-
resource "aws_iam_policy" "lambda_github_access_policy_dev" {
782-
count = local.is_sandbox_or_dev ? 1 : 0
783-
description = "These permissions allow GitHub to push to a Lambda function."
784-
name = "${terraform.workspace}-lambda-github-access-policy"
785-
name_prefix = null
786-
path = "/"
787-
policy = jsonencode(
788-
{
789-
Statement = [
790733
{
791734
Action = [
792735
"lambda:CreateFunction",
@@ -816,25 +759,8 @@ resource "aws_iam_policy" "lambda_github_access_policy_dev" {
816759
Resource = "arn:aws:lambda:eu-west-2:*:function:*"
817760
Sid = "VisualEditor1"
818761
},
819-
]
820-
Version = "2012-10-17"
821-
}
822-
)
823-
tags = {}
824-
tags_all = {}
825-
}
826762

827763

828-
# aws_iam_policy.repo_app_config_dev[0]:
829-
resource "aws_iam_policy" "repo_app_config_dev" {
830-
count = local.is_sandbox_or_dev ? 1 : 0
831-
description = null
832-
name = "${terraform.workspace}-repo_app_config"
833-
name_prefix = null
834-
path = "/"
835-
policy = jsonencode(
836-
{
837-
Statement = [
838764
{
839765
Action = [
840766
"appconfig:ListTagsForResource",
@@ -881,25 +807,8 @@ resource "aws_iam_policy" "repo_app_config_dev" {
881807
Resource = "*"
882808
Sid = "VisualEditor0"
883809
},
884-
]
885-
Version = "2012-10-17"
886-
}
887-
)
888-
tags = {}
889-
tags_all = {}
890-
}
891810

892811

893-
# aws_iam_policy.terraform_github_dynamodb_access_policy_dev[0]:
894-
resource "aws_iam_policy" "terraform_github_dynamodb_access_policy_dev" {
895-
count = local.is_sandbox_or_dev ? 1 : 0
896-
description = "Dynamo DB specific access policies required by terraform via GitHub"
897-
name = "${terraform.workspace}-terraform-github-dynamodb-access-policy"
898-
name_prefix = null
899-
path = "/"
900-
policy = jsonencode(
901-
{
902-
Statement = [
903812
{
904813
Action = [
905814
"dynamodb:DescribeTable",
@@ -911,26 +820,9 @@ resource "aws_iam_policy" "terraform_github_dynamodb_access_policy_dev" {
911820
Effect = "Allow"
912821
Resource = "arn:aws:dynamodb:*:*:table/ndr-terraform-locks"
913822
},
914-
]
915-
Version = "2012-10-17"
916-
}
917-
)
918-
tags = {}
919-
tags_all = {}
920-
}
921823

922824

923-
# aws_iam_policy.terraform_github_s3_access_policy_dev[0]:
924-
resource "aws_iam_policy" "terraform_github_s3_access_policy_dev" {
925-
count = local.is_sandbox_or_dev ? 1 : 0
926-
description = "S3 specific access policies required by terraform via GitHub"
927-
name = "${terraform.workspace}-terraform-github-s3-access-policy"
928-
name_prefix = null
929-
path = "/"
930-
policy = jsonencode(
931-
{
932-
Statement = [
933-
{
825+
{
934826
Action = "s3:ListBucket"
935827
Effect = "Allow"
936828
Resource = "arn:aws:s3:::ndr-dev-terraform-state-${data.aws_caller_identity.current.account_id}"
@@ -946,6 +838,8 @@ resource "aws_iam_policy" "terraform_github_s3_access_policy_dev" {
946838
Effect = "Allow"
947839
Resource = "arn:aws:s3:::ndr-dev-terraform-state-${data.aws_caller_identity.current.account_id}/ndr/terraform.tfstate"
948840
},
841+
842+
949843
]
950844
Version = "2012-10-17"
951845
}

0 commit comments

Comments
 (0)