Skip to content

Commit 4f36f0f

Browse files
authored
CCM-10048: e2e test reliability (#536)
1 parent a70ebb8 commit 4f36f0f

File tree

35 files changed

+423
-893
lines changed

35 files changed

+423
-893
lines changed

infrastructure/terraform/components/acct/module_sandbox_kms.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,33 @@ data "aws_iam_policy_document" "kms" {
8585
]
8686
}
8787
}
88+
89+
statement {
90+
sid = "AllowEventBridgeAccessToLetterValidationQueue"
91+
effect = "Allow"
92+
93+
principals {
94+
type = "Service"
95+
identifiers = ["events.amazonaws.com"]
96+
}
97+
98+
actions = [
99+
"kms:GenerateDataKey*",
100+
"kms:Decrypt",
101+
]
102+
103+
resources = ["*"]
104+
105+
condition {
106+
test = "ArnLike"
107+
variable = "kms:EncryptionContext:aws:sqs:arn"
108+
values = ["arn:aws:sqs:${var.region}:${var.aws_account_id}:*-validate-letter-template-files-queue"]
109+
}
110+
111+
condition {
112+
test = "ArnLike"
113+
variable = "aws:SourceArn"
114+
values = ["arn:aws:events:${var.region}:${var.aws_account_id}:rule/*-quarantine-scan-passed-for-upload"]
115+
}
116+
}
88117
}

infrastructure/terraform/components/app/module_kms.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,37 @@ data "aws_iam_policy_document" "kms" {
106106
]
107107
}
108108
}
109+
110+
statement {
111+
sid = "AllowEventBridgeAccessToLetterValidationQueue"
112+
effect = "Allow"
113+
114+
principals {
115+
type = "Service"
116+
identifiers = ["events.amazonaws.com"]
117+
}
118+
119+
actions = [
120+
"kms:GenerateDataKey*",
121+
"kms:Decrypt",
122+
]
123+
124+
resources = ["*"]
125+
126+
condition {
127+
test = "ArnEquals"
128+
variable = "kms:EncryptionContext:aws:sqs:arn"
129+
values = [
130+
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${local.csi}-validate-letter-template-files-queue"
131+
]
132+
}
133+
134+
condition {
135+
test = "ArnEquals"
136+
variable = "aws:SourceArn"
137+
values = [
138+
"arn:aws:events:${var.region}:${var.aws_account_id}:rule/${local.csi}-api-quarantine-scan-passed-for-upload"
139+
]
140+
}
141+
}
109142
}

infrastructure/terraform/modules/backend-api/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ No requirements.
1616
| <a name="input_csi"></a> [csi](#input\_csi) | CSI from the parent component | `string` | n/a | yes |
1717
| <a name="input_enable_backup"></a> [enable\_backup](#input\_enable\_backup) | Enable Backups for the DynamoDB table? | `bool` | `true` | no |
1818
| <a name="input_enable_event_stream"></a> [enable\_event\_stream](#input\_enable\_event\_stream) | Enable DynamoDB streaming to SQS? | `bool` | `false` | no |
19-
| <a name="input_enable_guardduty"></a> [enable\_guardduty](#input\_enable\_guardduty) | Enable GuardDuty | `bool` | `true` | no |
2019
| <a name="input_enable_proofing"></a> [enable\_proofing](#input\_enable\_proofing) | Enable proofing feature flag | `bool` | n/a | yes |
2120
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
2221
| <a name="input_function_s3_bucket"></a> [function\_s3\_bucket](#input\_function\_s3\_bucket) | Name of S3 bucket to upload lambda artefacts to | `string` | n/a | yes |

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_guardduty_quarantine_scan_failed_for_proof.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_failed_for_proof
33
description = "Matches quarantine 'GuardDuty Malware Protection Object Scan Result' events where the scan result is not NO_THREATS_FOUND"
44

55
event_pattern = jsonencode({
6-
source = [local.guardduty_source]
6+
source = ["aws.guardduty"]
77
detail-type = ["GuardDuty Malware Protection Object Scan Result"]
8-
resources = [local.guardduty_resource]
8+
resources = [aws_guardduty_malware_protection_plan.quarantine.arn]
99
detail = {
1010
s3ObjectDetails = {
1111
bucketName = [module.s3bucket_quarantine.id]
@@ -21,11 +21,9 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_failed_for_proof
2121
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_process_proof" {
2222
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed_for_proof.name
2323
arn = module.lambda_process_proof.function_arn
24-
role_arn = aws_iam_role.quarantine_scan_failed_for_proof.arn
2524
}
2625

2726
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_delete_object_for_proof" {
2827
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed_for_proof.name
2928
arn = module.lambda_delete_failed_scanned_object.function_arn
30-
role_arn = aws_iam_role.quarantine_scan_failed_for_proof.arn
3129
}

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_guardduty_quarantine_scan_failed_for_upload.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_failed_for_uploa
33
description = "Matches quarantine 'GuardDuty Malware Protection Object Scan Result' events where the scan result is not NO_THREATS_FOUND"
44

55
event_pattern = jsonencode({
6-
source = [local.guardduty_source]
6+
source = ["aws.guardduty"]
77
detail-type = ["GuardDuty Malware Protection Object Scan Result"]
8-
resources = [local.guardduty_resource]
8+
resources = [aws_guardduty_malware_protection_plan.quarantine.arn]
99
detail = {
1010
s3ObjectDetails = {
1111
bucketName = [module.s3bucket_quarantine.id]
@@ -21,11 +21,9 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_failed_for_uploa
2121
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_set_file_status_for_upload" {
2222
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed_for_upload.name
2323
arn = module.lambda_set_file_virus_scan_status_for_upload.function_arn
24-
role_arn = aws_iam_role.quarantine_scan_failed_for_upload.arn
2524
}
2625

2726
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_delete_object_for_upload" {
2827
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed_for_upload.name
2928
arn = module.lambda_delete_failed_scanned_object.function_arn
30-
role_arn = aws_iam_role.quarantine_scan_failed_for_upload.arn
3129
}

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_guardduty_quarantine_scan_passed_for_proof.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_passed_for_proof
33
description = "Matches quarantine 'GuardDuty Malware Protection Object Scan Result' events where the scan result is NO_THREATS_FOUND"
44

55
event_pattern = jsonencode({
6-
source = [local.guardduty_source]
6+
source = ["aws.guardduty"]
77
detail-type = ["GuardDuty Malware Protection Object Scan Result"]
8-
resources = [local.guardduty_resource]
8+
resources = [aws_guardduty_malware_protection_plan.quarantine.arn]
99
detail = {
1010
s3ObjectDetails = {
1111
bucketName = [module.s3bucket_quarantine.id]
@@ -21,5 +21,4 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_passed_for_proof
2121
resource "aws_cloudwatch_event_target" "quarantine_scan_passed_process_proof" {
2222
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed_for_proof.name
2323
arn = module.lambda_process_proof.function_arn
24-
role_arn = aws_iam_role.quarantine_scan_passed_for_proof.arn
2524
}

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_guardduty_quarantine_scan_passed_for_upload.tf

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_passed_for_uploa
33
description = "Matches quarantine 'GuardDuty Malware Protection Object Scan Result' events where the scan result is NO_THREATS_FOUND"
44

55
event_pattern = jsonencode({
6-
source = [local.guardduty_source]
6+
source = ["aws.guardduty"]
77
detail-type = ["GuardDuty Malware Protection Object Scan Result"]
8-
resources = [local.guardduty_resource]
8+
resources = [aws_guardduty_malware_protection_plan.quarantine.arn]
99
detail = {
1010
s3ObjectDetails = {
1111
bucketName = [module.s3bucket_quarantine.id]
@@ -19,19 +19,16 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_passed_for_uploa
1919
}
2020

2121
resource "aws_cloudwatch_event_target" "quarantine_scan_passed_set_file_status_for_upload" {
22-
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed_for_upload.name
23-
arn = module.lambda_set_file_virus_scan_status_for_upload.function_arn
24-
role_arn = aws_iam_role.quarantine_scan_passed_for_upload.arn
22+
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed_for_upload.name
23+
arn = module.lambda_set_file_virus_scan_status_for_upload.function_arn
2524
}
2625

2726
resource "aws_cloudwatch_event_target" "quarantine_scan_passed_copy_object_for_upload" {
28-
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed_for_upload.name
29-
arn = module.lambda_copy_scanned_object_to_internal.function_arn
30-
role_arn = aws_iam_role.quarantine_scan_passed_for_upload.arn
27+
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed_for_upload.name
28+
arn = module.lambda_copy_scanned_object_to_internal.function_arn
3129
}
3230

3331
resource "aws_cloudwatch_event_target" "quarantine_scan_passed_validate_files" {
3432
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed_for_upload.name
3533
arn = module.sqs_validate_letter_template_files.sqs_queue_arn
36-
role_arn = aws_iam_role.quarantine_scan_passed_for_upload.arn
3734
}

infrastructure/terraform/modules/backend-api/data_iam_policy_document_events_assume_role.tf

Lines changed: 0 additions & 10 deletions
This file was deleted.

infrastructure/terraform/modules/backend-api/guardduty_malware_protection_plan_quarantine.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
resource "aws_guardduty_malware_protection_plan" "quarantine" {
2-
count = var.enable_guardduty ? 1 : 0
2+
depends_on = [
3+
aws_iam_role_policy_attachment.guardduty_quarantine
4+
]
35

46
role = aws_iam_role.guardduty_quarantine.arn
57

infrastructure/terraform/modules/backend-api/iam_role_quarantine_scan_failed_for_proof.tf

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)