Skip to content

Commit 028f9a1

Browse files
authored
chore: migrated to trivy (#121)
1 parent 071d5cb commit 028f9a1

File tree

19 files changed

+63
-36
lines changed

19 files changed

+63
-36
lines changed

.github/workflows/static-analysis.yaml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,32 @@ jobs:
6464

6565
- run: make tflint
6666

67-
tfsec:
67+
trivy:
6868
runs-on: ubuntu-latest
69-
strategy:
70-
matrix:
71-
terraform: [ ~1.3 ]
7269
steps:
7370
- uses: actions/checkout@v4
7471

75-
- uses: hashicorp/setup-terraform@v3
76-
with:
77-
terraform_version: ${{ matrix.terraform }}
78-
79-
# TODO: check https://github.com/aquasecurity/tfsec-pr-commenter-action/issues/90, this action currently swallows all findings
80-
- uses: aquasecurity/tfsec-pr-commenter-action@v1.3.1
72+
- name: config
73+
run: |
74+
cat >> ./trivy.yaml << EOF
75+
# see https://aquasecurity.github.io/trivy/latest/docs/references/configuration/config-file/ for reference
76+
exit-code: 1
77+
exit-on-eol: 1
78+
misconfiguration:
79+
terraform:
80+
exclude-downloaded-modules: true
81+
severity:
82+
- HIGH
83+
- CRITICAL
84+
scan:
85+
skip-dirs:
86+
- "**/.terraform/**/*"
87+
EOF
88+
89+
cat ./trivy.yaml
90+
91+
- uses: aquasecurity/trivy-action@0.16.1
8192
with:
82-
github_token: ${{ secrets.GITHUB_TOKEN }}
83-
tfsec_args: --exclude aws-s3-encryption-customer-key,aws-sns-topic-encryption-use-cmk,aws-sqs-queue-encryption-use-cmk
93+
scan-type: 'config'
94+
hide-progress: false
95+
trivy-config: trivy.yaml

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.83.5
3+
rev: v1.86.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
77
args: ['--envs=AWS_REGION="eu-west-1"']
88
- id: terraform_tflint
9-
- id: terraform_tfsec
9+
- id: terraform_trivy
1010
args:
11-
- --args=--minimum-severity HIGH
12-
- --args=--exclude aws-s3-encryption-customer-key,aws-sns-topic-encryption-use-cmk,aws-sqs-queue-encryption-use-cmk
11+
- --args=--tf-exclude-downloaded-modules
12+
- --args=--skip-dirs "**/.terraform/**/*"
13+
- --args=--severity=HIGH,CRITICAL
1314
- id: terraform_docs
1415
args:
1516
- '--args=--lockfile=false'

examples/complete/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module "lambda" {
1818
function_name = random_pet.this.id
1919
handler = "index.handler"
2020
memory_size = 128
21-
runtime = "nodejs18.x"
21+
runtime = "nodejs20.x"
2222
publish = false
2323
snap_start = false
2424
source_code_hash = module.source.output_base64sha256

examples/container-image/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ locals {
33
function_name = "example-with-container-images"
44
}
55

6-
#tfsec:ignore:aws-ecr-enforce-immutable-repository
6+
#trivy:ignore:AVD-AWS-0031
77
resource "aws_ecr_repository" "this" {
8-
name = local.function_name
8+
force_delete = true
9+
name = local.function_name
910

1011
image_scanning_configuration {
1112
scan_on_push = true

examples/deployment/complete/codepipeline_step.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ data "aws_iam_policy_document" "custom_codepipeline_step" {
6161
"s3:GetObjectVersion"
6262
]
6363

64-
#tfsec:ignore:aws-iam-no-policy-wildcards
64+
#trivy:ignore:AVD-AWS-0057
6565
resources = ["${module.deployment.codepipeline_artifact_storage_arn}/deploy/*"]
6666
}
6767
}

examples/deployment/complete/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module "lambda" {
2020
handler = "index.handler"
2121
ignore_external_function_updates = true
2222
publish = true
23-
runtime = "nodejs18.x"
23+
runtime = "nodejs20.x"
2424
s3_bucket = aws_s3_bucket.source.bucket
2525
s3_key = local.s3_key
2626
s3_object_version = aws_s3_object.initial.version_id
@@ -193,7 +193,8 @@ resource "aws_iam_role_policy_attachment" "traffic_hook" {
193193
# S3 source and pipeline bucket resources
194194
# ---------------------------------------------------------------------------------------------------------------------
195195

196-
#tfsec:ignore:aws-s3-enable-bucket-encryption - configure bucket encryption in production!
196+
#trivy:ignore:AVD-AWS-0088
197+
#trivy:ignore:AVD-AWS-0132
197198
resource "aws_s3_bucket" "source" {
198199
bucket = "ci-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"
199200
force_destroy = true

examples/deployment/container-image/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module "deployment" {
3838
function_name = local.function_name
3939
}
4040

41-
#tfsec:ignore:aws-ecr-enforce-immutable-repository
41+
#trivy:ignore:AVD-AWS-0031
4242
resource "aws_ecr_repository" "this" {
4343
force_delete = true
4444
name = local.function_name

examples/deployment/s3/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module "lambda" {
1818
handler = "index.handler"
1919
ignore_external_function_updates = true
2020
publish = true
21-
runtime = "nodejs18.x"
21+
runtime = "nodejs20.x"
2222
s3_bucket = aws_s3_bucket.source.bucket
2323
s3_key = local.s3_key
2424
s3_object_version = aws_s3_object.initial.version_id
@@ -52,7 +52,8 @@ module "deployment" {
5252
# S3 source bucket resources
5353
# ---------------------------------------------------------------------------------------------------------------------
5454

55-
#tfsec:ignore:aws-s3-enable-bucket-encryption - configure bucket encryption in production!
55+
#trivy:ignore:AVD-AWS-0088
56+
#trivy:ignore:AVD-AWS-0132
5657
resource "aws_s3_bucket" "source" {
5758
bucket = "ci-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"
5859
force_destroy = true
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM public.ecr.aws/lambda/nodejs:18
1+
FROM public.ecr.aws/lambda/nodejs:20
2+
USER func
23
COPY index.js /var/task/
34

45
CMD [ "index.handler" ]

examples/with-cloudwatch-event-rules/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module "lambda" {
1414
filename = module.source.output_path
1515
function_name = "example-with-cloudwatch-events"
1616
handler = "index.handler"
17-
runtime = "nodejs18.x"
17+
runtime = "nodejs20.x"
1818
source_code_hash = module.source.output_base64sha256
1919

2020
cloudwatch_event_rules = {

0 commit comments

Comments
 (0)