Skip to content

Commit 384a0a0

Browse files
CCM-9061 Replace TFSec with Trivy (#62)
* CCM-9061 Replace TFSec with Trivy * CCM-9061 trigger trivy scan test * CCM-9061 trigger trivy scan test
1 parent c1b5122 commit 384a0a0

File tree

8 files changed

+43
-45
lines changed

8 files changed

+43
-45
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gitleaks 8.24.0
33
pre-commit 3.6.0
44
terraform 1.9.2
55
terraform-docs 0.19.0
6-
tfsec 1.28.10
6+
trivy 0.61.0
77
vale 3.6.0
88
python 3.13.2
99

infrastructure/terraform/components/acct/cloudwatch_log_group_route53_query_log.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data "aws_iam_policy_document" "route53_logs" {
3131

3232
resources = [
3333
aws_cloudwatch_log_group.aws_route53_query_log.arn,
34-
"${aws_cloudwatch_log_group.aws_route53_query_log.arn}:*"
34+
"${aws_cloudwatch_log_group.aws_route53_query_log.arn}:*",
3535
]
3636
}
3737
}

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"

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)