@@ -115,7 +115,7 @@ resource "aws_iam_policy" "dynamodb_management" {
115115 }
116116 ],
117117 # to create test users in preprod
118- var. environment == " preprod" ? [
118+ var. environment == " preprod" ? [
119119 {
120120 Effect = " Allow" ,
121121 Action = [
@@ -249,7 +249,11 @@ resource "aws_iam_policy" "api_infrastructure" {
249249 # CloudWatch Logs creation and management
250250 " logs:CreateLogGroup" ,
251251 " logs:CreateLogStream" ,
252- " logs:PutLogEvents"
252+ " logs:PutLogEvents" ,
253+ # CloudWatch Logs subscription filters for CSOC forwarding
254+ " logs:PutSubscriptionFilter" ,
255+ " logs:DeleteSubscriptionFilter" ,
256+ " logs:DescribeSubscriptionFilters"
253257 ],
254258 Resource = [
255259 # VPC Flow Logs
@@ -262,6 +266,17 @@ resource "aws_iam_policy" "api_infrastructure" {
262266 " arn:aws:logs:${ var . default_aws_region } :${ data . aws_caller_identity . current . account_id } :log-group:/aws/kinesisfirehose/*"
263267 ]
264268 },
269+ {
270+ Effect = " Allow" ,
271+ Action = [
272+ # CloudWatch Logs subscription to CSOC cross-account destination
273+ " logs:PutSubscriptionFilter"
274+ ],
275+ Resource = [
276+ # CSOC cross-account destination for API Gateway logs
277+ " arn:aws:logs:${ var . default_aws_region } :693466633220:destination:api_gateway_log_destination"
278+ ]
279+ },
265280 {
266281 Effect = " Allow" ,
267282 Action = [
@@ -279,7 +294,9 @@ resource "aws_iam_policy" "api_infrastructure" {
279294 " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :role/eventbridge-firehose-role*" ,
280295 # Kinesis Firehose S3 backup roles
281296 " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :role/*firehose*role*" ,
282- " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :role/splunk-firehose-assume-role*"
297+ " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :role/splunk-firehose-assume-role*" ,
298+ # CSOC CloudWatch Logs subscription role
299+ " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :role/*-CWLogsSubscriptionRole"
283300 ],
284301 Condition = {
285302 StringEquals = {
@@ -288,7 +305,8 @@ resource "aws_iam_policy" "api_infrastructure" {
288305 " apigateway.amazonaws.com" ,
289306 " vpc-flow-logs.amazonaws.com" ,
290307 " events.amazonaws.com" ,
291- " firehose.amazonaws.com"
308+ " firehose.amazonaws.com" ,
309+ " logs.amazonaws.com"
292310 ]
293311 }
294312 }
@@ -457,12 +475,15 @@ resource "aws_iam_policy" "iam_management" {
457475 " iam:CreateRole" ,
458476 " iam:DeleteRole" ,
459477 " iam:UpdateRole" ,
478+ " iam:UpdateAssumeRolePolicy" ,
460479 " iam:PutRolePolicy" ,
461480 " iam:PutRolePermissionsBoundary" ,
462481 " iam:AttachRolePolicy" ,
463482 " iam:DetachRolePolicy" ,
464483 " iam:CreatePolicy" ,
465484 " iam:CreatePolicyVersion" ,
485+ " iam:DeletePolicy" ,
486+ " iam:DeletePolicyVersion" ,
466487 " iam:TagRole" ,
467488 " iam:PassRole" ,
468489 " iam:TagPolicy" ,
@@ -477,9 +498,13 @@ resource "aws_iam_policy" "iam_management" {
477498 " arn:aws:iam::*:role/*-api-gateway-*-role" ,
478499 # External write role
479500 " arn:aws:iam::*:role/eligibility-signposting-api-*-external-write-role" ,
501+ # CSOC CloudWatch Logs subscription role
502+ " arn:aws:iam::*:role/*-CWLogsSubscriptionRole" ,
480503 # Project policies
481504 " arn:aws:iam::*:policy/*api-gateway-logging-policy" ,
482505 " arn:aws:iam::*:policy/*PermissionsBoundary" ,
506+ " arn:aws:iam::*:policy/*PutSubscriptionFilterPolicy" ,
507+ " arn:aws:iam::*:policy/*CWLogsToCSOCDestinationPolicy" ,
483508 # VPC flow logs role
484509 " arn:aws:iam::*:role/vpc-flow-logs-role" ,
485510 # API role
@@ -500,8 +525,8 @@ resource "aws_iam_policy" "iam_management" {
500525# Assume role policy document for GitHub Actions
501526data "aws_iam_policy_document" "github_actions_assume_role" {
502527 statement {
503- sid = " OidcAssumeRoleWithWebIdentity"
504- effect = " Allow"
528+ sid = " OidcAssumeRoleWithWebIdentity"
529+ effect = " Allow"
505530 actions = [" sts:AssumeRoleWithWebIdentity" ]
506531
507532 principals {
@@ -514,13 +539,13 @@ data "aws_iam_policy_document" "github_actions_assume_role" {
514539 condition {
515540 test = " StringLike"
516541 variable = " token.actions.githubusercontent.com:sub"
517- values = [" repo:${ var . github_org } /${ var . github_repo } :*" ]
542+ values = [" repo:${ var . github_org } /${ var . github_repo } :*" ]
518543 }
519544
520545 condition {
521546 test = " StringEquals"
522547 variable = " token.actions.githubusercontent.com:aud"
523- values = [" sts.amazonaws.com" ]
548+ values = [" sts.amazonaws.com" ]
524549 }
525550 }
526551}
0 commit comments