Skip to content

Commit 7dffdba

Browse files
committed
Merge branch 'feature/CCM-8588-templates-require-proof' of https://github.com/NHSDigital/nhs-notify-web-template-management into feature/CCM-8588-templates-require-proof
2 parents 22edfca + 31956c3 commit 7dffdba

35 files changed

+696
-97
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
name: "TFSec Scan"
2-
description: "Scan HCL using TFSec"
1+
name: "Trivy Scan"
32
runs:
43
using: "composite"
54
steps:
6-
- name: "TFSec Scan - Components"
5+
- name: "Trivy Terraform IAC Scan"
76
shell: bash
87
run: |
98
components_exit_code=0
109
modules_exit_code=0
1110
12-
./scripts/terraform/tfsec.sh ./infrastructure/terraform/components || components_exit_code=$?
13-
./scripts/terraform/tfsec.sh ./infrastructure/terraform/modules || modules_exit_code=$?
11+
./scripts/terraform/trivy.sh ./infrastructure/terraform/components || components_exit_code=$?
12+
./scripts/terraform/trivy.sh ./infrastructure/terraform/modules || modules_exit_code=$?
1413
1514
if [ $components_exit_code -ne 0 ] || [ $modules_exit_code -ne 0 ]; then
16-
echo "One or more TFSec scans failed."
15+
echo "Trivy misconfigurations detected."
1716
exit 1
1817
fi

.github/workflows/stage-1-commit.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ jobs:
135135
uses: actions/checkout@v4
136136
- name: "Lint Terraform"
137137
uses: ./.github/actions/lint-terraform
138-
tfsec:
139-
name: "TFSec Scan"
138+
trivy:
139+
name: "Trivy Scan"
140140
runs-on: ubuntu-latest
141141
timeout-minutes: 5
142142
needs: detect-terraform-changes
@@ -148,8 +148,8 @@ jobs:
148148
uses: asdf-vm/actions/setup@v3
149149
- name: "Perform Setup"
150150
uses: ./.github/actions/setup
151-
- name: "TFSec Scan"
152-
uses: ./.github/actions/tfsec
151+
- name: "Trivy Scan"
152+
uses: ./.github/actions/trivy
153153
count-lines-of-code:
154154
name: "Count lines of code"
155155
runs-on: ubuntu-latest

.tool-versions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
act 0.2.64
22
gitleaks 8.24.0
3+
jq 1.6
4+
nodejs 20.18.2
35
pre-commit 3.6.0
46
terraform 1.9.2
57
terraform-docs 0.19.0
8+
trivy 0.61.0
69
vale 3.6.0
7-
tfsec 1.28.10
8-
nodejs 20.18.2
9-
jq 1.6
1010

1111
# ==============================================================================
1212
# The section below is reserved for Docker image versions.

infrastructure/terraform/components/acct/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
| <a name="output_github_pat_ssm_param_name"></a> [github\_pat\_ssm\_param\_name](#output\_github\_pat\_ssm\_param\_name) | n/a |
4545
| <a name="output_s3_buckets"></a> [s3\_buckets](#output\_s3\_buckets) | n/a |
4646
| <a name="output_vpc_nat_ips"></a> [vpc\_nat\_ips](#output\_vpc\_nat\_ips) | n/a |
47-
| <a name="output_vpc_public_subnets"></a> [vpc\_public\_subnets](#output\_vpc\_public\_subnets) | n/a |
47+
| <a name="output_vpc_subnets"></a> [vpc\_subnets](#output\_vpc\_subnets) | n/a |
4848
<!-- vale on -->
4949
<!-- markdownlint-enable -->
5050
<!-- END_TF_DOCS -->

infrastructure/terraform/components/acct/iam_policy_github_deploy_overload.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resource "aws_iam_role_policy_attachment" "github_deploy_overload" {
99
policy_arn = aws_iam_policy.github_deploy_overload.arn
1010
}
1111

12-
#tfsec:ignore:aws-iam-no-policy-wildcards Policy voilation expected for CI user role
12+
#trivy:ignore:aws-iam-no-policy-wildcards Policy voilation expected for CI user role
1313
data "aws_iam_policy_document" "github_deploy" {
1414
statement {
1515
effect = "Allow"

infrastructure/terraform/components/acct/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ output "s3_buckets" {
2020
}
2121
}
2222

23-
output "vpc_public_subnets" {
23+
output "vpc_subnets" {
2424
value = {
2525
public = module.vpc.public_subnets
2626
private = module.vpc.private_subnets

infrastructure/terraform/components/app/iam_role_amplify.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ data "aws_iam_policy_document" "amplify" {
4646
"logs:PutLogEvents",
4747
]
4848

49-
#tfsec:ignore:aws-iam-no-policy-wildcards
49+
#trivy:ignore:aws-iam-no-policy-wildcards
5050
resources = [
5151
"${aws_cloudwatch_log_group.amplify.arn}:*",
5252
"${aws_cloudwatch_log_group.amplify.arn}:log-stream:*",
@@ -59,7 +59,7 @@ data "aws_iam_policy_document" "amplify" {
5959
"logs:DescribeLogGroups",
6060
]
6161

62-
#tfsec:ignore:aws-iam-no-policy-wildcards
62+
#trivy:ignore:aws-iam-no-policy-wildcards
6363
resources = [
6464
"arn:aws:logs:${var.region}:${var.aws_account_id}:*"
6565
]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ No requirements.
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 |
4444
| <a name="module_lambda_send_letter_proof"></a> [lambda\_send\_letter\_proof](#module\_lambda\_send\_letter\_proof) | ../lambda-function | n/a |
4545
| <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_sftp_poll"></a> [lambda\_sftp\_poll](#module\_lambda\_sftp\_poll) | ../lambda-function | n/a |
4647
| <a name="module_lambda_validate_letter_template_files"></a> [lambda\_validate\_letter\_template\_files](#module\_lambda\_validate\_letter\_template\_files) | ../lambda-function | n/a |
4748
| <a name="module_list_template_lambda"></a> [list\_template\_lambda](#module\_list\_template\_lambda) | ../lambda-function | n/a |
4849
| <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 |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ resource "aws_api_gateway_rest_api" "main" {
44
description = "Templates API"
55
disable_execute_api_endpoint = false
66

7-
binary_media_types = [ "multipart/form-data" ]
7+
binary_media_types = ["multipart/form-data"]
88
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "aws_cloudwatch_event_rule" "sftp_poll" {
2+
for_each = var.letter_suppliers
3+
4+
name = "${local.csi}-sftp-poll-${lower(each.key)}"
5+
schedule_expression = "rate(1 hour)" # Runs at the top of every hour
6+
7+
state = each.value.enable_polling ? "ENABLED" : "DISABLED"
8+
}
9+
10+
resource "aws_cloudwatch_event_target" "sftp_poll" {
11+
for_each = var.letter_suppliers
12+
rule = aws_cloudwatch_event_rule.sftp_poll[each.key].name
13+
arn = module.lambda_sftp_poll.function_arn
14+
15+
input = jsonencode({
16+
supplier : each.key
17+
})
18+
}
19+
20+
resource "aws_lambda_permission" "allow_cloudwatch" {
21+
for_each = var.letter_suppliers
22+
statement_id = "AllowExecutionFromCloudWatch${each.key}"
23+
action = "lambda:InvokeFunction"
24+
function_name = module.lambda_sftp_poll.function_name
25+
principal = "events.amazonaws.com"
26+
source_arn = aws_cloudwatch_event_rule.sftp_poll[each.key].arn
27+
}

0 commit comments

Comments
 (0)