Description
Describe the bug
Describe the bug
We configured our precommit setting with pre-commit-terraform and the terraform_trivy hook is raising an issue with a k8s yaml
The same yaml, in the same path, is present in the repo for some months but with the recent upgrade jumping from pre-commit-terraform from v1.96.3 to v1.97.4 the terraform_trivy started to raise the following alert:
AVD-KSV-0104 (MEDIUM): container "ubi-micro" of deployment "ubi-micro-deployment" in "ubimicro" namespace should specify a seccomp profile
════════════════════════════════════════
A program inside the container can bypass Seccomp protection policies.
See https://avd.aquasec.com/misconfig/ksv104
────────────────────────────────────────
scripts/ubi_micro.yaml:81-103
────────────────────────────────────────
81 ┌ - image: registry.access.redhat.com/ubi9/ubi-micro@sha256:...
82 │ imagePullPolicy: Always
83 │ name: ubi-micro
84 │ command:
85 │ - "/bin/sh"
86 │ - "-c"
87 │ - "sleep infinity"
88 │ securityContext:
89 └ allowPrivilegeEscalation: false
The yaml path relative to the repo is
examples/deploy-proxy/scripts/ubi_micro.yaml
This is the pre-commit-setting we use, that seemed to work fine until the recent upgrade, as we expect the yaml to be ignored.
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.97.4
hooks:
- id: terraform_fmt
- id: terraform_validate
# only scan directories with provider config in them due to limitation https://github.com/hashicorp/terraform/issues/28490
files: ^examples/|^patterns/|^solutions/
args:
- --hook-config=--retry-once-with-cleanup=true
- id: terraform_tflint
args:
- --args=--enable-rule=terraform_unused_declarations
- --args=--enable-rule=terraform_deprecated_index
- --args=--enable-rule=terraform_comment_syntax
- --args=--enable-rule=terraform_documented_outputs
- --args=--enable-rule=terraform_documented_variables
- --args=--enable-rule=terraform_typed_variables
- --args=--enable-rule=terraform_naming_convention
- --args=--enable-rule=terraform_required_version
- --args=--enable-rule=terraform_required_providers
- --args=--enable-rule=terraform_unused_required_providers
- --args=--enable-rule=terraform_standard_module_structure
exclude: dynamic_values/
- id: terraform_trivy
args:
- --args=--skip-files="**/.terraform/**/*"
- --args=--skip-files="**/examples/**/*.yaml"
- --args=--skip-files="**/examples/**/*.yml"
- --args=--skip-files="**/helm-charts/**/*"
- --args=--skip-files="**/tests/**/*"
- --args=--skip-files="common-dev-assets/**/*"
# workaround for https://github.com/antonbabenko/pre-commit-terraform/issues/691
- --hook-config=--parallelism-limit=1
We tried to set the following trivy ignore tag as workaroud, but it seems to be ignored as well: # trivy:ignore:AVD-KSV-0104
containers:
- image: registry.access.redhat.com/ubi9/ubi-micro@sha256:...
imagePullPolicy: Always
name: ubi-micro
command:
- "/bin/sh"
- "-c"
- "sleep infinity"
# trivy:ignore:AVD-KSV-0104
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
readOnlyRootFilesystem: true
runAsUser: 10001
runAsGroup: 10001
capabilities:
drop:
- "ALL"
We tried also to use the same tag at the very start of the container section whose code makes trivy to complain but didn't help as well
containers:
# trivy:ignore:AVD-KSV-0104
- image: registry.access.redhat.com/ubi9/ubi-micro@sha256:...
imagePullPolicy: Always
name: ubi-micro
command:
- "/bin/sh"
- "-c"
- "sleep infinity"
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
readOnlyRootFilesystem: true
Also setting at the very start of the deployment yaml didn't help.
The only way to solve this issue started with recent upgrade is to add the following path --args=--skip-files="**/scripts/*.yaml"
to the skip-file configuration, with the following final result
- id: terraform_trivy
args:
- --args=--skip-files="**/.terraform/**/*"
- --args=--skip-files="**/examples/**/*.yaml"
- --args=--skip-files="**/examples/**/*.yml"
- --args=--skip-files="**/helm-charts/**/*"
- --args=--skip-files="**/tests/**/*"
- --args=--skip-files="**/scripts/*.yaml"
- --args=--skip-files="common-dev-assets/**/*"
# workaround for https://github.com/antonbabenko/pre-commit-terraform/issues/691
- --hook-config=--parallelism-limit=1
Below the logs of the precommit hook failure
Terraform validate with trivy.............................................Failed
- hook id: terraform_trivy
- exit code: 1
2025-03-05T10:41:22+01:00 INFO [misconfig] Misconfiguration scanning is enabled
2025-03-05T10:41:25+01:00 INFO [terraform scanner] Scanning root module file_path="examples/deploy-proxy"
2025-03-05T10:41:25+01:00 WARN [terraform parser] Variable values was not found in the environment or variable files. Evaluating may not work correctly. module="root" variables="ibmcloud_api_key"
2025-03-05T10:41:25+01:00 INFO [terraform scanner] Scanning root module file_path="examples/deploy-proxy-existing-cluster"
2025-03-05T10:41:25+01:00 WARN [terraform parser] Variable values was not found in the environment or variable files. Evaluating may not work correctly. module="root" variables="cluster_id, ibmcloud_api_key"
2025-03-05T10:41:25+01:00 INFO Detected config files num=13
2025-03-05T10:41:25+01:00 INFO [misconfig] Misconfiguration scanning is enabled
2025-03-05T10:41:27+01:00 INFO [terraform scanner] Scanning root module file_path="."
2025-03-05T10:41:27+01:00 WARN [terraform parser] Variable values was not found in the environment or variable files. Evaluating may not work correctly. module="root" variables="ibmcloud_api_key"
2025-03-05T10:41:28+01:00 INFO Detected config files num=2
scripts/ubi_micro.yaml (kubernetes)
Tests: 110 (SUCCESSES: 108, FAILURES: 2)
Failures: 2 (UNKNOWN: 0, LOW: 1, MEDIUM: 1, HIGH: 0, CRITICAL: 0)
AVD-KSV-0030 (LOW): Either Pod or Container should set 'securityContext.seccompProfile.type' to 'RuntimeDefault'
════════════════════════════════════════
According to pod security standard 'Seccomp', the RuntimeDefault seccomp profile must be required, or allow specific additional profiles.
See https://avd.aquasec.com/misconfig/ksv030
────────────────────────────────────────
scripts/ubi_micro.yaml:80-103
────────────────────────────────────────
80 ┌ - image: registry.access.redhat.com/ubi9/ubi-micro@sha256:...
81 │ imagePullPolicy: Always
82 │ name: ubi-micro
83 │ command:
84 │ - "/bin/sh"
85 │ - "-c"
86 │ - "sleep infinity"
87 │ # trivy:ignore:AVD-KSV-0104
88 └ securityContext:
..
────────────────────────────────────────
AVD-KSV-0104 (MEDIUM): container "ubi-micro" of deployment "ubi-micro-deployment" in "ubimicro" namespace should specify a seccomp profile
════════════════════════════════════════
A program inside the container can bypass Seccomp protection policies.
See https://avd.aquasec.com/misconfig/ksv104
────────────────────────────────────────
scripts/ubi_micro.yaml:80-103
────────────────────────────────────────
80 ┌ - image: registry.access.redhat.com/ubi9/ubi-micro@sha256:...
81 │ imagePullPolicy: Always
82 │ name: ubi-micro
83 │ command:
84 │ - "/bin/sh"
85 │ - "-c"
86 │ - "sleep infinity"
87 │ # trivy:ignore:AVD-KSV-0104
88 └ securityContext:
..
────────────────────────────────────────
2025-03-05T10:41:28+01:00 INFO [misconfig] Misconfiguration scanning is enabled
2025-03-05T10:41:29+01:00 INFO [terraform scanner] Scanning root module file_path="."
2025-03-05T10:41:29+01:00 WARN [terraform parser] Variable values was not found in the environment or variable files. Evaluating may not work correctly. module="root" variables="cluster_id, ibmcloud_api_key"
2025-03-05T10:41:29+01:00 INFO Detected config files num=1
2025-03-05T10:41:29+01:00 INFO [misconfig] Misconfiguration scanning is enabled
2025-03-05T10:41:30+01:00 INFO [terraform scanner] Scanning root module file_path="."
2025-03-05T10:41:30+01:00 WARN [terraform parser] Variable values was not found in the environment or variable files. Evaluating may not work correctly. module="root" variables="cluster_id"
2025-03-05T10:41:30+01:00 INFO Detected config files num=1
I mentioned the issue AVD-KSV-0104 as example, even if it raised also AVD-KSV-0030
How can we reproduce it?
pre-commit run --all-files
Environment information
Environment information
-
OS: MacOS and GitHub Action using golang:1.24 as base image
-
Tools availability and versions:
GNU bash, version 5.2.37(1)-release (x86_64-apple-darwin23.4.0)
pre-commit 4.1.0
OpenTofu v1.6.2
Terraform v1.9.2
python SKIPPED
Python 3.12.6
checkov SKIPPED
infracost SKIPPED
terraform-docs version v0.19.0 af31cc6 darwin/amd64
terragrunt version v0.55.1
terrascan SKIPPED
TFLint version 0.55.1
+ ruleset.terraform (0.10.0-bundled)
tfsec v1.28.5
trivy Version: 0.59.1
Check Bundle:
Digest: sha256:2bc834fc222789e26b85dc3e92e3333b488e16a9bfa192aa971cca25db884837
DownloadedAt: 2025-03-04 11:03:29.487846 +0000 UTC
tfupdate SKIPPED
hcledit SKIPPED
pre-commit-config.yaml
.pre-commit-config.yaml
:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.97.4
hooks:
- id: terraform_fmt
- id: terraform_validate
# only scan directories which has provider config in them due to limitation https://github.com/hashicorp/terraform/issues/28490
files: ^examples/|^patterns/|^solutions/
args:
- --hook-config=--retry-once-with-cleanup=true
- id: terraform_tflint
args:
- --args=--enable-rule=terraform_unused_declarations
- --args=--enable-rule=terraform_deprecated_index
- --args=--enable-rule=terraform_comment_syntax
- --args=--enable-rule=terraform_documented_outputs
- --args=--enable-rule=terraform_documented_variables
- --args=--enable-rule=terraform_typed_variables
- --args=--enable-rule=terraform_naming_convention
- --args=--enable-rule=terraform_required_version
- --args=--enable-rule=terraform_required_providers
- --args=--enable-rule=terraform_unused_required_providers
- --args=--enable-rule=terraform_standard_module_structure
exclude: dynamic_values/
- id: terraform_trivy
args:
- --args=--skip-files="**/.terraform/**/*"
- --args=--skip-files="**/examples/**/*.yaml"
- --args=--skip-files="**/examples/**/*.yml"
- --args=--skip-files="**/helm-charts/**/*"
- --args=--skip-files="**/tests/**/*"
- --args=--skip-files="common-dev-assets/**/*"
# workaround for https://github.com/antonbabenko/pre-commit-terraform/issues/691
- --hook-config=--parallelism-limit=1