Skip to content

Commit e24ab24

Browse files
Fix/fire hose GitHub role (#200)
* fix : iam policy kms key * cicd fix * github actions role fix * testing * firehose policy for github actions * firehose ListTagsForDeliveryStream policy for github actions * Revert "testing" This reverts commit 392d082. * developer roles run in dev env * added feature to git deploy by commitsha
1 parent d744f6b commit e24ab24

File tree

6 files changed

+75
-8
lines changed

6 files changed

+75
-8
lines changed

.github/workflows/cicd-2-publish.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ jobs:
104104
# just planning for now for safety and until review
105105
run: |
106106
mkdir -p ./build
107+
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=iams-developer-roles tf-command=apply"
108+
make terraform env=$ENVIRONMENT stack=iams-developer-roles tf-command=apply workspace=$WORKSPACE
107109
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=networking tf-command=apply"
108110
make terraform env=$ENVIRONMENT stack=networking tf-command=apply workspace=$WORKSPACE
109111
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=apply"

.github/workflows/cicd-3-deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ jobs:
133133
# just planning for now for safety and until review
134134
run: |
135135
mkdir -p ./build
136+
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=iams-developer-roles tf-command=apply"
137+
make terraform env=$ENVIRONMENT stack=iams-developer-roles tf-command=apply workspace=$WORKSPACE
136138
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=networking tf-command=apply"
137139
make terraform env=$ENVIRONMENT stack=networking tf-command=apply workspace=$WORKSPACE
138140
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=apply"

.github/workflows/cicd-4-test.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
required: true
99
type: choice
1010
options: [dev, test, preprod]
11+
revision:
12+
description: Git revision (commit SHA or tag)
13+
required: false
1114

1215
jobs:
1316
listS3:
@@ -18,8 +21,10 @@ jobs:
1821
contents: read
1922

2023
steps:
21-
- name: Checkout
24+
- name: Checkout code
2225
uses: actions/checkout@v4
26+
with:
27+
ref: ${{ inputs.revision || 'main' }}
2328

2429
- name: Set up Python
2530
uses: actions/setup-python@v5

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ resource "aws_iam_policy" "iam_management" {
364364
Resource = [
365365
# Lambda role
366366
"arn:aws:iam::*:role/eligibility_lambda-role*",
367+
# Kinesis Role
368+
"arn:aws:iam::*:role/eligibility_audit_firehose-role*",
367369
# API Gateway role
368370
"arn:aws:iam::*:role/*-api-gateway-*-role",
369371
# External write role
@@ -374,7 +376,9 @@ resource "aws_iam_policy" "iam_management" {
374376
# VPC flow logs role
375377
"arn:aws:iam::*:role/vpc-flow-logs-role",
376378
# API role
377-
"arn:aws:iam::*:role/*eligibility-signposting-api-role"
379+
"arn:aws:iam::*:role/*eligibility-signposting-api-role",
380+
# Kinesis firehose role
381+
"arn:aws:iam::*:role/eligibility_audit_firehose-role*"
378382
]
379383
}
380384
]
@@ -410,6 +414,50 @@ data "aws_iam_policy_document" "github_actions_assume_role" {
410414
}
411415
}
412416

417+
resource "aws_iam_policy" "cloudwatch_logging" {
418+
name = "cloudwatch-logging-management"
419+
description = "Allow access to logging resources"
420+
path = "/service-policies/"
421+
422+
policy = jsonencode({
423+
Version = "2012-10-17",
424+
Statement = [
425+
{
426+
Effect = "Allow",
427+
Action = [
428+
"logs:ListTagsForResource",
429+
"logs:DescribeLogGroups"
430+
],
431+
Resource = "arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/kinesisfirehose/*"
432+
}
433+
]
434+
})
435+
436+
tags = merge(local.tags, { Name = "cloudwatch-logging-management" })
437+
}
438+
439+
resource "aws_iam_policy" "firehose_readonly" {
440+
name = "firehose-describe-access"
441+
description = "Allow GitHub Actions to describe Firehose delivery stream"
442+
path = "/service-policies/"
443+
444+
policy = jsonencode({
445+
Version = "2012-10-17",
446+
Statement = [
447+
{
448+
Effect = "Allow",
449+
Action = [
450+
"firehose:DescribeDeliveryStream",
451+
"firehose:ListTagsForDeliveryStream"
452+
],
453+
Resource = "arn:aws:firehose:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:deliverystream/eligibility-signposting-api*"
454+
}
455+
]
456+
})
457+
458+
tags = merge(local.tags, { Name = "firehose-describe-access" })
459+
}
460+
413461
# Attach the policies to the role
414462
resource "aws_iam_role_policy_attachment" "terraform_state" {
415463
role = aws_iam_role.github_actions.name
@@ -445,3 +493,13 @@ resource "aws_iam_role_policy_attachment" "iam_management" {
445493
role = aws_iam_role.github_actions.name
446494
policy_arn = aws_iam_policy.iam_management.arn
447495
}
496+
497+
resource "aws_iam_role_policy_attachment" "cloudwatch_logging" {
498+
role = aws_iam_role.github_actions.name
499+
policy_arn = aws_iam_policy.cloudwatch_logging.arn
500+
}
501+
502+
resource "aws_iam_role_policy_attachment" "firehose_readonly_attach" {
503+
role = aws_iam_role.github_actions.name
504+
policy_arn = aws_iam_policy.firehose_readonly.arn
505+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ resource "aws_iam_openid_connect_provider" "github" {
1717
resource "aws_iam_role" "github_actions" {
1818
name = "github-actions-api-deployment-role"
1919
description = "Role for GitHub Actions to deploy infrastructure via Terraform"
20-
permissions_boundary = aws_iam_policy.permissions_boundary.arn
20+
permissions_boundary = aws_iam_policy.permissions_boundary.arn
2121
path = "/service-roles/"
2222

2323
# Trust policy allowing GitHub Actions to assume the role

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
resource "aws_iam_role" "terraform_developer" {
2-
name = "terraform-developer-role"
3-
description = "Role for developers to plan and apply Terraform changes"
4-
assume_role_policy = data.aws_iam_policy_document.terraform_developer_assume_role.json
5-
permissions_boundary = aws_iam_policy.permissions_boundary.arn # Attach permissions boundary
6-
max_session_duration = 14400 # 4 hours
2+
name = "terraform-developer-role"
3+
description = "Role for developers to plan and apply Terraform changes"
4+
assume_role_policy = data.aws_iam_policy_document.terraform_developer_assume_role.json
5+
permissions_boundary = aws_iam_policy.permissions_boundary.arn # Attach permissions boundary
6+
max_session_duration = 14400 # 4 hours
77

88
tags = merge(
99
local.tags,

0 commit comments

Comments
 (0)