Skip to content

Commit f881b2b

Browse files
github actions roles updated
1 parent 496a5dd commit f881b2b

File tree

2 files changed

+55
-42
lines changed

2 files changed

+55
-42
lines changed

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

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ resource "aws_iam_policy" "lambda_management" {
6262
"lambda:ListAliases",
6363
"lambda:AddPermission",
6464
"lambda:RemovePermission",
65-
"lambda:GetPolicy"
65+
"lambda:GetPolicy",
66+
"lambda:GetAlias",
67+
"lambda:GetFunction"
6668
],
6769
Resource = [
68-
"arn:aws:lambda:*:${data.aws_caller_identity.current.account_id}:function:*eligibility_signposting_api"
70+
"arn:aws:lambda:*:${data.aws_caller_identity.current.account_id}:function:eligibility_signposting_api",
71+
"arn:aws:lambda:*:${data.aws_caller_identity.current.account_id}:function:eligibility_signposting_api:*"
6972
]
7073
}
7174
]
@@ -440,8 +443,8 @@ resource "aws_iam_policy" "iam_management" {
440443
# Assume role policy document for GitHub Actions
441444
data "aws_iam_policy_document" "github_actions_assume_role" {
442445
statement {
443-
sid = "OidcAssumeRoleWithWebIdentity"
444-
effect = "Allow"
446+
sid = "OidcAssumeRoleWithWebIdentity"
447+
effect = "Allow"
445448
actions = ["sts:AssumeRoleWithWebIdentity"]
446449

447450
principals {
@@ -454,40 +457,17 @@ data "aws_iam_policy_document" "github_actions_assume_role" {
454457
condition {
455458
test = "StringLike"
456459
variable = "token.actions.githubusercontent.com:sub"
457-
values = ["repo:${var.github_org}/${var.github_repo}:*"]
460+
values = ["repo:${var.github_org}/${var.github_repo}:*"]
458461
}
459462

460463
condition {
461464
test = "StringEquals"
462465
variable = "token.actions.githubusercontent.com:aud"
463-
values = ["sts.amazonaws.com"]
466+
values = ["sts.amazonaws.com"]
464467
}
465468
}
466469
}
467470

468-
resource "aws_iam_policy" "cloudwatch_logging" {
469-
name = "cloudwatch-logging-management"
470-
description = "Allow access to logging resources"
471-
path = "/service-policies/"
472-
473-
policy = jsonencode({
474-
Version = "2012-10-17",
475-
Statement = [
476-
{
477-
Effect = "Allow",
478-
Action = [
479-
"logs:ListTagsForResource",
480-
"logs:DescribeLogGroups",
481-
"logs:PutRetentionPolicy"
482-
],
483-
Resource = "arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/kinesisfirehose/*"
484-
}
485-
]
486-
})
487-
488-
tags = merge(local.tags, { Name = "cloudwatch-logging-management" })
489-
}
490-
491471
resource "aws_iam_policy" "firehose_readonly" {
492472
name = "firehose-describe-access"
493473
description = "Allow GitHub Actions to describe Firehose delivery stream"
@@ -518,9 +498,9 @@ resource "aws_iam_policy" "firehose_readonly" {
518498
tags = merge(local.tags, { Name = "firehose-describe-access" })
519499
}
520500

521-
resource "aws_iam_policy" "cloudwatch_alarms" {
522-
name = "cloudwatch-alarms-management"
523-
description = "Allow GitHub Actions to manage CloudWatch alarms and SNS topics"
501+
resource "aws_iam_policy" "cloudwatch_management" {
502+
name = "cloudwatch-management"
503+
description = "Allow GitHub Actions to manage CloudWatch logs, alarms, and SNS topics"
524504
path = "/service-policies/"
525505

526506
policy = jsonencode({
@@ -529,15 +509,18 @@ resource "aws_iam_policy" "cloudwatch_alarms" {
529509
{
530510
Effect = "Allow",
531511
Action = [
532-
# CloudWatch Alarms management
512+
"logs:ListTagsForResource",
513+
"logs:DescribeLogGroups",
514+
"logs:PutRetentionPolicy",
515+
533516
"cloudwatch:PutMetricAlarm",
534517
"cloudwatch:DeleteAlarms",
535518
"cloudwatch:DescribeAlarms",
536519
"cloudwatch:DescribeAlarmsForMetric",
537520
"cloudwatch:ListTagsForResource",
538521
"cloudwatch:TagResource",
539522
"cloudwatch:UntagResource",
540-
# SNS Topic management for alarm notifications
523+
541524
"sns:CreateTopic",
542525
"sns:DeleteTopic",
543526
"sns:GetTopicAttributes",
@@ -552,14 +535,40 @@ resource "aws_iam_policy" "cloudwatch_alarms" {
552535
"sns:ListSubscriptionsByTopic"
553536
],
554537
Resource = [
538+
"arn:aws:logs:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/kinesisfirehose/*",
555539
"arn:aws:cloudwatch:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:alarm:*",
556540
"arn:aws:sns:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:cloudwatch-security-alarms*"
557541
]
558542
}
559543
]
560544
})
561545

562-
tags = merge(local.tags, { Name = "cloudwatch-alarms-management" })
546+
tags = merge(local.tags, { Name = "cloudwatch-management" })
547+
}
548+
549+
# SQS Management Policy for GetQueueAttributes
550+
resource "aws_iam_policy" "sqs_management" {
551+
name = "sqs-management"
552+
description = "Policy granting permissions to get SQS queue attributes"
553+
path = "/service-policies/"
554+
555+
policy = jsonencode({
556+
Version = "2012-10-17",
557+
Statement = [
558+
{
559+
Effect = "Allow",
560+
Action = [
561+
"sqs:GetQueueAttributes",
562+
"sqs:listqueuetags"
563+
],
564+
Resource = [
565+
"arn:aws:sqs:eu-west-2:${data.aws_caller_identity.current.account_id}:*"
566+
]
567+
}
568+
]
569+
})
570+
571+
tags = merge(local.tags, { Name = "sqs-management" })
563572
}
564573

565574
# Attach the policies to the role
@@ -598,17 +607,18 @@ resource "aws_iam_role_policy_attachment" "iam_management" {
598607
policy_arn = aws_iam_policy.iam_management.arn
599608
}
600609

601-
resource "aws_iam_role_policy_attachment" "cloudwatch_logging" {
610+
resource "aws_iam_role_policy_attachment" "firehose_readonly_attach" {
602611
role = aws_iam_role.github_actions.name
603-
policy_arn = aws_iam_policy.cloudwatch_logging.arn
612+
policy_arn = aws_iam_policy.firehose_readonly.arn
604613
}
605614

606-
resource "aws_iam_role_policy_attachment" "firehose_readonly_attach" {
615+
resource "aws_iam_role_policy_attachment" "cloudwatch_management" {
607616
role = aws_iam_role.github_actions.name
608-
policy_arn = aws_iam_policy.firehose_readonly.arn
617+
policy_arn = aws_iam_policy.cloudwatch_management.arn
609618
}
610619

611-
resource "aws_iam_role_policy_attachment" "cloudwatch_alarms" {
620+
resource "aws_iam_role_policy_attachment" "sqs_management" {
612621
role = aws_iam_role.github_actions.name
613-
policy_arn = aws_iam_policy.cloudwatch_alarms.arn
622+
policy_arn = aws_iam_policy.sqs_management.arn
614623
}
624+

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ data "aws_iam_policy_document" "permissions_boundary" {
150150
"lambda:AddPermission",
151151
"lambda:RemovePermission",
152152
"lambda:GetPolicy",
153+
"lambda:GetAlias",
153154

154155
# CloudWatch Logs - log management
155156
"logs:CreateLogGroup",
@@ -220,7 +221,9 @@ data "aws_iam_policy_document" "permissions_boundary" {
220221
"ssm:AddTagsToResource",
221222

222223
#SQS - message management
223-
"sqs:SendMessage"
224+
"sqs:SendMessage",
225+
"sqs:GetQueueAttributes",
226+
"sqs:listqueuetags"
224227
]
225228

226229
resources = ["*"]

0 commit comments

Comments
 (0)