tfsec Executor¶
Category: IaC, Containers and Kubernetes
Script: tfsec.py
Integration: CLI
Faraday Plugin: SarifPlugin
Website: https://aquasecurity.github.io/tfsec/
Description¶
Runs a tfsec static analysis scan on Terraform code and imports the misconfigurations it finds into Faraday. You can scan a local directory or a Git repository.
Prerequisites¶
tfsecinstalled and available in the agent'sPATH(checked withtfsec --version)git, if you scan a repository by URL- Read access to the Terraform code, either as a local path or a Git repository
Configuration¶
Environment Variables (Setup)¶
| Variable | Required | Description |
|---|---|---|
GIT_USERNAME |
No | Username for cloning private repositories over HTTPS (default: oauth2) |
GIT_TOKEN |
No | Access token for cloning private repositories over HTTPS |
Execution Arguments¶
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
TFSEC_TARGET |
string | No* | Directory with the .tf files to scan. When TFSEC_GIT_URL is set, it is a subpath inside the cloned repository (e.g., terraform/). |
TFSEC_MIN_SEVERITY |
string | No | Minimum severity to report: LOW, MEDIUM, HIGH or CRITICAL |
TFSEC_EXCLUDE |
list | No | Check IDs to skip (e.g., ["aws-s3-enable-bucket-encryption"]) |
TFSEC_GIT_URL |
url | No* | Git repository to clone and scan |
TFSEC_GIT_REF |
string | No | Branch or tag to clone (default: the repository's default branch) |
* You must set TFSEC_TARGET, TFSEC_GIT_URL, or both.
YAML Configuration Example¶
executors:
tfsec:
repo_executor: tfsec.py
max_size: 65536
varenvs:
GIT_USERNAME: "<git_username>"
GIT_TOKEN: "<git_token>"
params:
TFSEC_TARGET:
mandatory: false
type: string
base: string
TFSEC_MIN_SEVERITY:
mandatory: false
type: string
base: string
TFSEC_EXCLUDE:
mandatory: false
type: list
base: list
TFSEC_GIT_URL:
mandatory: false
type: url
base: string
TFSEC_GIT_REF:
mandatory: false
type: string
base: string
How It Works¶
- If
TFSEC_GIT_URLis set, makes a shallow clone of the repository (atTFSEC_GIT_REF, if given) into a temporary directory. For HTTPS URLs it authenticates withGIT_USERNAME/GIT_TOKEN. - Runs
tfsec <target> --format sarif --soft-failwith the severity and exclusion options - Parses the SARIF report with
SarifPluginand sends the results to Faraday - Deletes the temporary clone when the run ends
Notes¶
TFSEC_TARGETmust point inside the cloned repository. Paths that escape it (e.g.,../) are rejected.- The run fails if tfsec does not produce a SARIF report.
- tfsec is being merged into Trivy upstream. For new setups, consider [[executor-trivy]].
- Supports the shared agent parameters (
AGENT_CONFIG_*tags and severity filters).