Skip to content

Commit 3310fdf

Browse files
Merge pull request #65 from NHSDigital/CCM-9061_replaceTfsecTrivy
CCM-9061 Replace TFSec with Trivy
2 parents e2108b0 + 4b58357 commit 3310fdf

13 files changed

Lines changed: 64 additions & 66 deletions

File tree

.github/actions/tfsec/action.yaml

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

.github/actions/trivy/action.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "Trivy Scan"
2+
runs:
3+
using: "composite"
4+
steps:
5+
- name: "Trivy Terraform IAC Scan"
6+
shell: bash
7+
run: |
8+
modules_exit_code=0
9+
10+
./scripts/terraform/trivy.sh ./infrastructure/modules || modules_exit_code=$?
11+
12+
if [ $components_exit_code -ne 0 ] || [ $modules_exit_code -ne 0 ]; then
13+
echo "Trivy misconfigurations detected."
14+
exit 1
15+
fi

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ jobs:
4040
echo "build_datetime=$datetime" >> $GITHUB_OUTPUT
4141
echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
4242
echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT
43-
echo "nodejs_version=$(grep "^nodejs " .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
44-
echo "python_version=$(grep "^python " .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
45-
echo "terraform_version=$(grep "^terraform " .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
43+
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
44+
echo "python_version=$(grep "^python\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
45+
echo "terraform_version=$(grep "^terraform\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
4646
echo "version=$(echo $version)" >> $GITHUB_OUTPUT
4747
echo "is_version_prerelease=$(if [[ $version == *-* ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT
4848

.github/workflows/cicd-3-deploy.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ jobs:
4545
echo "build_datetime=$datetime" >> $GITHUB_OUTPUT
4646
echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
4747
echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT
48-
echo "nodejs_version=$(grep "^nodejs " .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
49-
echo "python_version=$(grep "^python " .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
50-
echo "terraform_version=$(grep "^terraform " .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
48+
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
49+
echo "python_version=$(grep "^python\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
50+
echo "terraform_version=$(grep "^terraform\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
5151
# TODO: Get the version, but it may not be the .version file as this should come from the CI/CD Pull Request Workflow
5252
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT
5353
# echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT

.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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# This file is for you! Please, updated to the versions agreed by your team.
22

3+
gitleaks 8.18.4
4+
nodejs 18.18.2
5+
pre-commit 3.6.0
36
terraform 1.9.2
47
terraform-docs 0.19.0
5-
pre-commit 3.6.0
6-
nodejs 18.18.2
7-
gitleaks 8.18.4
8-
tfsec 1.28.10
98
terraform-docs 0.19.0
9+
trivy 0.61.0
1010
vale 3.6.0
1111

1212

infrastructure/modules/kms/data_iam_kms_admin_policy.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#tfsec:ignore:aws-iam-no-policy-wildcards
1+
#trivy:ignore:aws-iam-no-policy-wildcards
22
data "aws_iam_policy_document" "admin" {
33
policy_id = "${local.csi}-admin"
44

infrastructure/modules/kms/data_iam_kms_user_policy.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#tfsec:ignore:aws-iam-no-policy-wildcards
1+
#trivy:ignore:aws-iam-no-policy-wildcards
22
data "aws_iam_policy_document" "user" {
33
policy_id = "${local.csi}-user"
44

infrastructure/modules/lambda/data_iam_policy_document_put_logs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data "aws_iam_policy_document" "put_logs" {
88
"logs:PutLogEvents",
99
]
1010

11-
#tfsec:ignore:aws-iam-no-policy-wildcards
11+
#trivy:ignore:aws-iam-no-policy-wildcards
1212
resources = [
1313
"${aws_cloudwatch_log_group.main.arn}:*",
1414
]

infrastructure/modules/s3bucket/s3_bucket.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#tfsec:ignore:aws-s3-enable-bucket-logging Logging is a depricated attribute, use aws_s3_bucket_logging resource
1+
#trivy:ignore:aws-s3-enable-bucket-logging Logging is a depricated attribute, use aws_s3_bucket_logging resource
22
resource "aws_s3_bucket" "main" {
33
bucket = local.csi_global
44
force_destroy = var.force_destroy

0 commit comments

Comments
 (0)