Skip to content

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

  • tfsec installed and available in the agent's PATH (checked with tfsec --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

  1. If TFSEC_GIT_URL is set, makes a shallow clone of the repository (at TFSEC_GIT_REF, if given) into a temporary directory. For HTTPS URLs it authenticates with GIT_USERNAME/GIT_TOKEN.
  2. Runs tfsec <target> --format sarif --soft-fail with the severity and exclusion options
  3. Parses the SARIF report with SarifPlugin and sends the results to Faraday
  4. Deletes the temporary clone when the run ends

Notes

  • TFSEC_TARGET must 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).