Skip to content

Commit a05e015

Browse files
CCM-9061 Replace TFSec with Trivy
1 parent 8b46b0c commit a05e015

9 files changed

Lines changed: 43 additions & 44 deletions

File tree

.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

scripts/config/tfsec.yaml

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

scripts/config/trivy.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
severity: MEDIUM # Minimum reported findings
3+
exit-code: 1 # When issues are found
4+
scan:
5+
skip-files:
6+
- "**/.terraform/**/*"
Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -euo pipefail
99
# Run tfsec for security checks on Terraform code.
1010
#
1111
# Usage:
12-
# $ ./tfsec.sh [directory]
12+
# $ ./trivy.sh [directory]
1313
# ==============================================================================
1414

1515
function main() {
@@ -18,68 +18,63 @@ function main() {
1818

1919
local dir_to_scan=${1:-.}
2020

21-
if command -v tfsec > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then
21+
if command -v trivy > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then
2222
# shellcheck disable=SC2154
23-
run-tfsec-natively "$dir_to_scan"
23+
run-trivy-natively "$dir_to_scan"
2424
else
25-
run-tfsec-in-docker "$dir_to_scan"
25+
run-trivy-in-docker "$dir_to_scan"
2626
fi
2727
}
2828

29-
# Run tfsec on the specified directory.
29+
# Run trivy on the specified directory.
3030
# Arguments:
3131
# $1 - Directory to scan
32-
function run-tfsec-natively() {
32+
function run-trivy-natively() {
3333

3434
local dir_to_scan="$1"
3535

36-
echo "TFSec found locally, running natively"
36+
echo "Trivy found locally, running natively"
3737

38-
echo "Running TFSec on directory: $dir_to_scan"
39-
tfsec \
40-
--force-all-dirs \
41-
--exclude-downloaded-modules \
42-
--config-file scripts/config/tfsec.yaml \
43-
--format text \
44-
"$dir_to_scan"
38+
echo "Running Trivy on directory: $dir_to_scan"
39+
trivy config \
40+
--config scripts/config/trivy.yaml \
41+
--tf-exclude-downloaded-modules \
42+
"${dir_to_scan}"
4543

46-
check-tfsec-status
44+
check-trivy-status
4745
}
4846

4947
# Check the exit status of tfsec.
50-
function check-tfsec-status() {
48+
function check-trivy-status() {
5149

5250
if [ $? -eq 0 ]; then
53-
echo "TFSec completed successfully."
51+
echo "Trivy completed successfully."
5452
else
55-
echo "TFSec found issues."
53+
echo "Trivy found issues."
5654
exit 1
5755
fi
5856
}
5957

60-
function run-tfsec-in-docker() {
58+
function run-trivy-in-docker() {
6159

6260
# shellcheck disable=SC1091
6361
source ./scripts/docker/docker.lib.sh
6462
local dir_to_scan="$1"
6563

6664
# shellcheck disable=SC2155
67-
local image=$(name=aquasec/tfsec docker-get-image-version-and-pull)
65+
local image=$(name=aquasec/trivy docker-get-image-version-and-pull)
6866
# shellcheck disable=SC2086
69-
echo "TFSec not found locally, running in Docker Container"
70-
echo "Running TFSec on directory: $dir_to_scan"
67+
echo "Trivy not found locally, running in Docker Container"
68+
echo "Running Trivy on directory: $dir_to_scan"
7169
docker run --rm --platform linux/amd64 \
7270
--volume "$PWD":/workdir \
7371
--workdir /workdir \
7472
"$image" \
75-
--concise-output \
76-
--force-all-dirs \
77-
--exclude-downloaded-modules \
78-
--config-file scripts/config/tfsec.yaml \
79-
--format text \
80-
--soft-fail \
81-
"$dir_to_scan"
82-
check-tfsec-status
73+
config \
74+
--config scripts/config/trivy.yaml \
75+
--tf-exclude-downloaded-modules \
76+
"${dir_to_scan}"
77+
check-trivy-status
8378
}
8479
# ==============================================================================
8580

0 commit comments

Comments
 (0)