Skip to content

Commit 965e967

Browse files
CCM-9247: Link proofs to database entries (#448)
1 parent 9cf307d commit 965e967

File tree

71 files changed

+12135
-11031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+12135
-11031
lines changed

infrastructure/terraform/components/sandbox/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ No requirements.
3636
| <a name="output_send_proof_queue_url"></a> [send\_proof\_queue\_url](#output\_send\_proof\_queue\_url) | n/a |
3737
| <a name="output_sftp_environment"></a> [sftp\_environment](#output\_sftp\_environment) | n/a |
3838
| <a name="output_sftp_mock_credential_path"></a> [sftp\_mock\_credential\_path](#output\_sftp\_mock\_credential\_path) | n/a |
39+
| <a name="output_sftp_poll_lambda_name"></a> [sftp\_poll\_lambda\_name](#output\_sftp\_poll\_lambda\_name) | n/a |
3940
| <a name="output_templates_table_name"></a> [templates\_table\_name](#output\_templates\_table\_name) | n/a |
4041
<!-- vale on -->
4142
<!-- markdownlint-enable -->

infrastructure/terraform/components/sandbox/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ output "internal_bucket_name" {
3333
output "quarantine_bucket_name" {
3434
value = module.backend_api.quarantine_bucket_name
3535
}
36+
37+
output "sftp_poll_lambda_name" {
38+
value = module.backend_api.sftp_poll_lambda_name
39+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,21 @@ No requirements.
4141
| <a name="module_get_template_lambda"></a> [get\_template\_lambda](#module\_get\_template\_lambda) | ../lambda-function | n/a |
4242
| <a name="module_lambda_copy_scanned_object_to_internal"></a> [lambda\_copy\_scanned\_object\_to\_internal](#module\_lambda\_copy\_scanned\_object\_to\_internal) | ../lambda-function | n/a |
4343
| <a name="module_lambda_delete_failed_scanned_object"></a> [lambda\_delete\_failed\_scanned\_object](#module\_lambda\_delete\_failed\_scanned\_object) | ../lambda-function | n/a |
44+
| <a name="module_lambda_process_proof"></a> [lambda\_process\_proof](#module\_lambda\_process\_proof) | ../lambda-function | n/a |
4445
| <a name="module_lambda_send_letter_proof"></a> [lambda\_send\_letter\_proof](#module\_lambda\_send\_letter\_proof) | ../lambda-function | n/a |
45-
| <a name="module_lambda_set_file_virus_scan_status"></a> [lambda\_set\_file\_virus\_scan\_status](#module\_lambda\_set\_file\_virus\_scan\_status) | ../lambda-function | n/a |
46+
| <a name="module_lambda_set_file_virus_scan_status_for_upload"></a> [lambda\_set\_file\_virus\_scan\_status\_for\_upload](#module\_lambda\_set\_file\_virus\_scan\_status\_for\_upload) | ../lambda-function | n/a |
4647
| <a name="module_lambda_sftp_poll"></a> [lambda\_sftp\_poll](#module\_lambda\_sftp\_poll) | ../lambda-function | n/a |
4748
| <a name="module_lambda_validate_letter_template_files"></a> [lambda\_validate\_letter\_template\_files](#module\_lambda\_validate\_letter\_template\_files) | ../lambda-function | n/a |
4849
| <a name="module_list_template_lambda"></a> [list\_template\_lambda](#module\_list\_template\_lambda) | ../lambda-function | n/a |
4950
| <a name="module_request_proof_lambda"></a> [request\_proof\_lambda](#module\_request\_proof\_lambda) | ../lambda-function | n/a |
5051
| <a name="module_s3bucket_internal"></a> [s3bucket\_internal](#module\_s3bucket\_internal) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
5152
| <a name="module_s3bucket_quarantine"></a> [s3bucket\_quarantine](#module\_s3bucket\_quarantine) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
53+
| <a name="module_sqs_process_proof_dlq"></a> [sqs\_process\_proof\_dlq](#module\_sqs\_process\_proof\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
5254
| <a name="module_sqs_sftp_upload"></a> [sqs\_sftp\_upload](#module\_sqs\_sftp\_upload) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
5355
| <a name="module_sqs_validate_letter_template_files"></a> [sqs\_validate\_letter\_template\_files](#module\_sqs\_validate\_letter\_template\_files) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
5456
| <a name="module_sqs_virus_scan_failed_delete_object_dlq"></a> [sqs\_virus\_scan\_failed\_delete\_object\_dlq](#module\_sqs\_virus\_scan\_failed\_delete\_object\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
5557
| <a name="module_sqs_virus_scan_passed_copy_object_dlq"></a> [sqs\_virus\_scan\_passed\_copy\_object\_dlq](#module\_sqs\_virus\_scan\_passed\_copy\_object\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
56-
| <a name="module_sqs_virus_scan_set_file_status_dlq"></a> [sqs\_virus\_scan\_set\_file\_status\_dlq](#module\_sqs\_virus\_scan\_set\_file\_status\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
58+
| <a name="module_sqs_virus_scan_set_file_status_for_upload_dlq"></a> [sqs\_virus\_scan\_set\_file\_status\_for\_upload\_dlq](#module\_sqs\_virus\_scan\_set\_file\_status\_for\_upload\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
5759
| <a name="module_submit_template_lambda"></a> [submit\_template\_lambda](#module\_submit\_template\_lambda) | ../lambda-function | n/a |
5860
| <a name="module_update_template_lambda"></a> [update\_template\_lambda](#module\_update\_template\_lambda) | ../lambda-function | n/a |
5961
## Outputs
@@ -66,6 +68,7 @@ No requirements.
6668
| <a name="output_send_proof_queue_url"></a> [send\_proof\_queue\_url](#output\_send\_proof\_queue\_url) | n/a |
6769
| <a name="output_sftp_environment"></a> [sftp\_environment](#output\_sftp\_environment) | n/a |
6870
| <a name="output_sftp_mock_credential_path"></a> [sftp\_mock\_credential\_path](#output\_sftp\_mock\_credential\_path) | n/a |
71+
| <a name="output_sftp_poll_lambda_name"></a> [sftp\_poll\_lambda\_name](#output\_sftp\_poll\_lambda\_name) | n/a |
6972
| <a name="output_templates_table_name"></a> [templates\_table\_name](#output\_templates\_table\_name) | n/a |
7073
<!-- vale on -->
7174
<!-- markdownlint-enable -->
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_failed_for_proof" {
2+
name = "${local.csi}-quarantine-scan-failed-for-proof"
3+
description = "Matches quarantine 'GuardDuty Malware Protection Object Scan Result' events where the scan result is not NO_THREATS_FOUND"
4+
5+
event_pattern = jsonencode({
6+
source = ["aws.guardduty"]
7+
detail-type = ["GuardDuty Malware Protection Object Scan Result"]
8+
resources = [aws_guardduty_malware_protection_plan.quarantine.arn]
9+
detail = {
10+
s3ObjectDetails = {
11+
bucketName = [module.s3bucket_quarantine.id]
12+
objectKey = [{ prefix = "proofs/" }]
13+
}
14+
scanResultDetails = {
15+
scanResultStatus = [{ anything-but = "NO_THREATS_FOUND" }]
16+
}
17+
}
18+
})
19+
}
20+
21+
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_process_proof" {
22+
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed_for_proof.name
23+
arn = module.lambda_process_proof.function_arn
24+
role_arn = aws_iam_role.quarantine_scan_failed_for_proof.arn
25+
}
26+
27+
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_delete_object_for_proof" {
28+
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed_for_proof.name
29+
arn = module.lambda_delete_failed_scanned_object.function_arn
30+
role_arn = aws_iam_role.quarantine_scan_failed_for_proof.arn
31+
}

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_guardduty_quarantine_scan_failed.tf renamed to infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_guardduty_quarantine_scan_failed_for_upload.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_failed" {
2-
name = "${local.csi}-quarantine-scan-failed"
1+
resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_failed_for_upload" {
2+
name = "${local.csi}-quarantine-scan-failed-for-upload"
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({
@@ -18,14 +18,14 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_failed" {
1818
})
1919
}
2020

21-
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_set_file_status" {
22-
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed.name
23-
arn = module.lambda_set_file_virus_scan_status.function_arn
24-
role_arn = aws_iam_role.quarantine_scan_failed.arn
21+
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_set_file_status_for_upload" {
22+
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed_for_upload.name
23+
arn = module.lambda_set_file_virus_scan_status_for_upload.function_arn
24+
role_arn = aws_iam_role.quarantine_scan_failed_for_upload.arn
2525
}
2626

27-
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_delete_object" {
28-
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed.name
27+
resource "aws_cloudwatch_event_target" "quarantine_scan_failed_delete_object_for_upload" {
28+
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_failed_for_upload.name
2929
arn = module.lambda_delete_failed_scanned_object.function_arn
30-
role_arn = aws_iam_role.quarantine_scan_failed.arn
30+
role_arn = aws_iam_role.quarantine_scan_failed_for_upload.arn
3131
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_passed_for_proof" {
2+
name = "${local.csi}-quarantine-scan-passed-proofs"
3+
description = "Matches quarantine 'GuardDuty Malware Protection Object Scan Result' events where the scan result is NO_THREATS_FOUND"
4+
5+
event_pattern = jsonencode({
6+
source = ["aws.guardduty"]
7+
detail-type = ["GuardDuty Malware Protection Object Scan Result"]
8+
resources = [aws_guardduty_malware_protection_plan.quarantine.arn]
9+
detail = {
10+
s3ObjectDetails = {
11+
bucketName = [module.s3bucket_quarantine.id]
12+
objectKey = [{ prefix = "proofs/" }]
13+
}
14+
scanResultDetails = {
15+
scanResultStatus = ["NO_THREATS_FOUND"]
16+
}
17+
}
18+
})
19+
}
20+
21+
resource "aws_cloudwatch_event_target" "quarantine_scan_passed_process_proof" {
22+
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed_for_proof.name
23+
arn = module.lambda_process_proof.function_arn
24+
role_arn = aws_iam_role.quarantine_scan_passed_for_proof.arn
25+
}

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_guardduty_quarantine_scan_passed.tf renamed to infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_guardduty_quarantine_scan_passed_for_upload.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_passed" {
2-
name = "${local.csi}-quarantine-scan-passed"
1+
resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_passed_for_upload" {
2+
name = "${local.csi}-quarantine-scan-passed-for-upload"
33
description = "Matches quarantine 'GuardDuty Malware Protection Object Scan Result' events where the scan result is NO_THREATS_FOUND"
44

55
event_pattern = jsonencode({
@@ -18,20 +18,20 @@ resource "aws_cloudwatch_event_rule" "guardduty_quarantine_scan_passed" {
1818
})
1919
}
2020

21-
resource "aws_cloudwatch_event_target" "quarantine_scan_passed_set_file_status" {
22-
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed.name
23-
arn = module.lambda_set_file_virus_scan_status.function_arn
24-
role_arn = aws_iam_role.quarantine_scan_passed.arn
21+
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
2525
}
2626

27-
resource "aws_cloudwatch_event_target" "quarantine_scan_passed_copy_object" {
28-
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed.name
27+
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
2929
arn = module.lambda_copy_scanned_object_to_internal.function_arn
30-
role_arn = aws_iam_role.quarantine_scan_passed.arn
30+
role_arn = aws_iam_role.quarantine_scan_passed_for_upload.arn
3131
}
3232

3333
resource "aws_cloudwatch_event_target" "quarantine_scan_passed_validate_files" {
34-
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed.name
34+
rule = aws_cloudwatch_event_rule.guardduty_quarantine_scan_passed_for_upload.name
3535
arn = module.sqs_validate_letter_template_files.sqs_queue_arn
36-
role_arn = aws_iam_role.quarantine_scan_passed.arn
36+
role_arn = aws_iam_role.quarantine_scan_passed_for_upload.arn
3737
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ resource "aws_dynamodb_table" "templates" {
3838
name, # To support backup and restore which will result in a new name otherwise
3939
]
4040
}
41+
42+
global_secondary_index {
43+
name = "QueryById"
44+
hash_key = "id"
45+
projection_type = "INCLUDE"
46+
non_key_attributes = ["owner"]
47+
}
4148
}

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

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "aws_iam_role" "quarantine_scan_failed_for_proof" {
2+
name = "${local.csi}-quarantine-scan-failed-for-proof"
3+
description = "IAM Role for GuardDuty failure CloudWatch events to trigger follow up actions"
4+
assume_role_policy = data.aws_iam_policy_document.events_assume_role.json
5+
}
6+
7+
resource "aws_iam_role_policy" "quarantine_scan_failed_for_proof" {
8+
name = "${local.csi}-quarantine-scan-failed-for-proof"
9+
role = aws_iam_role.quarantine_scan_failed_for_proof.id
10+
policy = data.aws_iam_policy_document.quarantine_scan_failed_for_proof.json
11+
}
12+
13+
data "aws_iam_policy_document" "quarantine_scan_failed_for_proof" {
14+
version = "2012-10-17"
15+
16+
statement {
17+
sid = "AllowLambdaInvoke"
18+
effect = "Allow"
19+
actions = ["lambda:InvokeFunction"]
20+
resources = [
21+
module.lambda_process_proof.function_arn,
22+
module.lambda_delete_failed_scanned_object.function_arn
23+
]
24+
}
25+
}

0 commit comments

Comments
 (0)