A Comprehensive Guide to Infrastructure as Code (IaC) Scanning Tools | Brainboard Blog

A Comprehensive Guide to Infrastructure as Code (IaC) Scanning Tools

Chafik Belhaoues July 4, 2025
Expert reviewed
A Comprehensive Guide to Infrastructure as Code (IaC) Scanning Tools
A Comprehensive Guide to Infrastructure as Code (IaC) Scanning ToolsComplete analysis of IaC security scanning tools that helps you better understand and pick the right solution(s) for your cloud infrastructure.Cloud Security2025-07-04T00:00:00.000Z11 minutesadvancedguidedevelopers, DevOps engineers, cloud architects
11 min read
advanced
guide

Introduction

IaC scanning tools are automated solutions that analyze these IaC templates (like Terraform, CloudFormation, Kubernetes YAML, etc.) for security issues before deployment. They check for problems such as overly permissive access, hardcoded secrets (like passwords or API keys), insecure network settings, and deviations from compliance standards. For DevOps, platform and cloud engineers, these tools are vital for maintaining security without slowing down development.

Feature matrix and key differentiators

The following table summarizes key features and differentiators for the prominent open-source IaC scanning tools discussed. This is intended to provide a high-level comparison to aid in tool selection.

FeatureCheckovKICSTerrascanTrivytfsecOPA (as engine)
Primary FocusIaC Misconfig, Vulns, ComplianceIaC Misconfig, Vulns, Compliance, API SecurityIaC Misconfig, ComplianceVulns (Image/OS/Lib), IaC Misconfig, Secrets, LicensesTerraform Misconfig, SecurityGeneral Policy Enforcement
Supported IaC (Core)TF, CFN, K8s, ARM, Docker, Helm, SLFTF, CFN, K8s, ARM, Docker, Helm, Ansible, OpenAPI, Pulumi, etc.TF, K8s, Helm, Kustomize, Docker, CFN, ARMTF, CFN, K8s, Docker, Helm, etc.Terraform, TF PlanAny JSON/YAML (e.g., TF Plan JSON, K8s)
Secret Scanning (IaC)YesYesLimited (focus on image vulns)YesLimited (sensitive vars)No (Policy-based)
Custom PoliciesPython, YAMLRegoRegoRego (via config)JSON, YAML, RegoRego
Built-in Compliance MapYes (CIS, NIST, HIPAA, PCI, SOC2)Categorized (indirectly supports)Yes (CIS, etc.)General standards (explicit map unclear)Limited direct mappingN/A (user-defined)
Graph-Based AnalysisYesNo (Query-based)No (OPA-based)NoYes (relationships)No (evaluates input)
K8s Admission ControlNo (via Checkov directly)NoYesNo (K8s manifest scan)NoYes (via Gatekeeper)
LicensingApache 2.0Apache 2.0Apache 2.0Apache 2.0MITApache 2.0
Primary Vendor/MaintainerPalo Alto NetworksCheckmarxTenableAqua SecurityAqua Security (merging to Trivy)CNCF / Styra

TF=Terraform, CFN=CloudFormation, K8s=Kubernetes, ARM=Azure Resource Manager, SLF=Serverless Framework.

Core Benefits of IaC scanners

  • Shifting Left
  • Enhancing Compliance
  • Reducing Risk

The adoption of IaC scanning tools offers several compelling benefits:

  • Early Detection & Cost Reduction: Identifying and remediating misconfigurations during the pre-production phase is significantly less costly and disruptive than addressing security incidents in live environments. This proactive approach, central to the “shift-left” strategy, emphasizes prevention over mere detection.
  • Automated Compliance: IaC scanning tools play a crucial role in automating adherence to a wide array of regulatory and industry standards, such as CIS Benchmarks, NIST frameworks, PCI DSS, HIPAA, and SOC2. They achieve this by systematically checking infrastructure configurations against the specific requirements of these frameworks. This moves compliance from a periodic, manual exercise to an embedded, automated process. While traditional audits offer a point-in-time snapshot, IaC scanning integrated into CI/CD pipelines provides continuous validation, offering a higher assurance of ongoing compliance in dynamic cloud settings and reducing audit fatigue.
  • Reduced Attack Surface: By systematically identifying and enabling the remediation of misconfigurations and vulnerabilities, these tools help organizations minimize their exposed attack surface.
  • Consistency and Standardization: They enforce uniform security configurations across all infrastructure components managed by IaC, ensuring that security policies are applied consistently.
  • Developer Empowerment and Education: IaC scanning tools provide developers with immediate, actionable feedback and guidance on secure coding practices for infrastructure, fostering a culture of security awareness and responsibility from the earliest stages of development.

Broad IaC Language and Format Support

The landscape of IaC tools is diverse, and organizations often use multiple technologies. Therefore, an effective IaC scanning solution should ideally support a wide range of common IaC languages and formats. These include:

  • Terraform (HCL): A widely adopted multi-cloud provisioning tool.
  • AWS CloudFormation (JSON/YAML): AWS’s native IaC service.
  • Azure Resource Manager (ARM) Templates (JSON): Microsoft Azure’s native IaC solution.
  • Bicep: A domain-specific language (DSL) for ARM templates.
  • Google Cloud Deployment Manager (YAML/Python): GCP’s native IaC tool (though it is being deprecated ).
  • Kubernetes (YAML): For defining and managing containerized applications and their configurations.
  • Dockerfile: For building container images.
  • Helm Charts: A package manager for Kubernetes.
  • Serverless Frameworks (e.g., AWS SAM): For defining serverless applications.
  • Ansible Playbooks (YAML): For configuration management and orchestration.

While some tools like TFLint are highly specialized for a single language (Terraform in TFLint’s case ), others such as Checkov, KICS, Terrascan, and Trivy aim for broader, multi-framework support. Commercial platforms like Prisma Cloud also typically list extensive IaC framework compatibility.

In-depth review of tools

The open-source community has produced a variety of powerful IaC scanning tools. These tools are widely adopted due to their accessibility, extensibility, and active community support. This section provides an in-depth review of some of the most prominent open-source options.

Checkov

Overview: Checkov is a highly popular open-source static code analysis tool developed by Bridgecrew, which was later acquired by Palo Alto Networks and integrated into its Prisma Cloud offering. It is designed to scan IaC configurations for misconfigurations and security vulnerabilities prior to deployment, playing a crucial role in “shifting left” security.

Key Features & Strengths:

  • Extensive Policy Library: Checkov comes with a vast collection of hundreds of built-in policies (sources vary, citing between 750+ and over 1,000 ). These policies cover a wide range of security best practices, guidelines from major cloud providers (AWS, Azure, GCP), and requirements for various compliance frameworks.
  • Multi-Framework Support: It offers broad support for numerous IaC languages and formats, including Terraform (HCL and plan JSON), AWS CloudFormation (JSON/YAML), Kubernetes (YAML), Dockerfile, Azure Resource Manager (ARM) templates, Serverless Framework, and Helm charts.
  • Graph-Based Scanning: A distinguishing feature of Checkov is its ability to build a graph of resource relationships from the IaC code. This allows it to understand the context of configurations and detect more complex, interconnected security risks that isolated checks might miss. For environments with intricate dependencies, such as microservices or large-scale cloud deployments, this capability provides significantly deeper security insights.
  • Custom Policies: Users can define their own security policies using Python or YAML, enabling organizations to enforce company-specific requirements and tailor scanning to their unique risk posture.
  • CI/CD Integration: Checkov integrates smoothly with a variety of CI/CD platforms, including GitHub Actions, GitLab CI, Jenkins, Azure DevOps, and Bitbucket Pipelines, facilitating automated scanning within development workflows.
  • Flexible Output Formats: Scan results can be generated in various formats, including CLI (human-readable), JSON, JUnitXML, and SARIF. SARIF output is particularly useful for integration with GitHub Advanced Security’s code scanning features.
  • Terraform Plan Scanning: Checkov can analyze Terraform plan files (typically in JSON format), allowing for checks against the intended state of infrastructure before changes are applied.

Optimal Use Cases: Checkov is well-suited for teams that require comprehensive IaC framework coverage, a large and regularly updated set of out-of-the-box policies, the advanced analytical capabilities of graph-based scanning, and robust CI/CD integration options. It is also a natural choice for organizations already using or considering Prisma Cloud, as it provides a clear pathway to enterprise-level features. The strong corporate backing from Palo Alto Networks ensures continuous development, an up-to-date policy library reflecting evolving cloud services and threats, and a higher degree of confidence in its long-term viability and support.

Licensing: Checkov is licensed under the Apache 2.0 License.

Installation & Configuration:

  • Installation: Checkov can be installed using package managers like pip (Python), Homebrew, or run via Docker.
    • Using pip: $ pip install checkov
    • Using Homebrew: $ brew install checkov
    • Using Docker: $ docker run -t -v /user/tf:/tf bridgecrew/checkov -d /tf (example for scanning a local Terraform directory mounted to /tf in the container).
  • Configuration: Checkov’s behavior can be configured through command-line interface (CLI) flags or a configuration file.

CLI Examples:

  • Scan a directory: $ checkov -d /path/to/your/iac/code
  • Scan a specific file: $ checkov -f /path/to/your/file.tf
  • Scan a directory for a specific framework: $ checkov -d. --framework terraform
  • Skip specific checks: $ checkov -d. --skip-check CKV_AWS_18,CKV_AWS_21
  • Run only specific checks: $ checkov -d. --check CKV_AWS_53
  • Specify output format (e.g., JSON): $ checkov -f main.tf --output json
  • Scan a Terraform plan file (after generating tfplan.json): $ terraform plan -out=tfplan.binary$ terraform show -json tfplan.binary > tfplan.json$ checkov -f tfplan.json

Secret Scanning Capabilities: Checkov includes a dedicated secrets scanning framework that can be invoked using the --framework secrets flag. It identifies various types of hardcoded secrets, including API keys, passwords, and private keys. A list of specific secret types Checkov looks for includes Artifactory Credentials, AWS Access Keys, Azure Storage Account access keys, Basic Auth Credentials, various IBM Cloud keys, JSON Web Tokens, Mailchimp Access Keys, NPM tokens, Private Keys (general), Slack Tokens, and more, often identified by high entropy strings in Base64 or Hex formats.

Compliance Standard Mapping: Checkov’s built-in policies are often mapped to recognized compliance standards and benchmarks. Explicit mentions include CIS Benchmarks, NIST frameworks, HIPAA, PCI DSS, and SOC2. This mapping helps organizations automate compliance checks and generate reports demonstrating adherence to these standards. Engineers can filter scan results based on these compliance standards or use them to prioritize remediation efforts.

KICS

Overview: KICS (Keeping Infrastructure as Code Secure) is an open-source static analysis security testing (SAST) tool developed by Checkmarx. It is designed to find security vulnerabilities, compliance issues, and infrastructure misconfigurations early in the development lifecycle of IaC files.

Key Features & Strengths:

  • Extensive Query Library: KICS boasts a comprehensive library of over 1500 pre-built security queries, which are fully customizable and adjustable. These queries are primarily written in Rego, the policy language from Open Policy Agent.
  • Broad IaC and API Support: KICS supports an impressive array of IaC platforms and related technologies. This includes Terraform, Kubernetes, Docker, AWS CloudFormation, Ansible, Helm, OpenAPI, gRPC, Azure Resource Manager (ARM), Google Deployment Manager, AWS Cloud Development Kit (CDK), AWS SAM, Docker Compose, Knative, Crossplane, Pulumi, ServerlessFW, Azure Blueprints, GitHub Workflows, OpenTofu, and Bicep. This wide coverage is a significant advantage for organizations using diverse toolsets.
  • Extensibility and Customization: The tool is designed with a modular architecture, making it highly extensible. Developers can add new checks using Rego and extend support for new IaC solutions.
  • CI/CD Integration: KICS is built for seamless integration into CI/CD pipelines, with support for platforms like GitHub Actions, GitLab CI, Jenkins, and Azure DevOps. Checkmarx One, the commercial platform, provides official plugins for many of these.
  • IDE Integration: KICS offers an auto-scanning extension for Visual Studio Code, providing real-time feedback to developers as they write IaC.
  • API Design Assessment: Beyond IaC files, KICS can scan OpenAPI specifications to identify misconfigurations in API path definitions, authentication schemas, and transport encryption, helping to enforce API security standards.

Optimal Use Cases: KICS is an excellent choice for teams that require broad IaC and API specification coverage from a single tool. Its large and extensible query set makes it adaptable to diverse security needs. It is particularly beneficial for organizations with heterogeneous IaC environments or those looking for a tool that can be deeply customized. The connection to Checkmarx’s commercial offerings also provides a clear upgrade path for enterprises needing advanced features and support. This makes KICS a strong entry point for IaC scanning, with the assurance of an enterprise solution if future needs dictate.

Licensing: KICS is licensed under the Apache 2.0 License.

Installation & Configuration:

  • Installation: KICS can be installed via Docker, a one-liner install script (for Linux/macOS), or by downloading pre-compiled binaries for various operating systems.
    • Using Docker: docker pull checkmarx/kics:latest
    • One-liner script: curl -sfL 'https://raw.githubusercontent.com/Checkmarx/kics/master/install.sh' | bash
  • Configuration: KICS behavior can be controlled via CLI options or a configuration file (e.g., kics.config).

CLI Examples:

  • Scan a project path: ./kics scan -p "/path/to/your/project" -o "/path/to/output/results.json"
  • Scan using Docker (mounting the project directory): docker run -v /host/path/to/scan:/path checkmarx/kics:latest scan -p /path
  • Specify custom queries directory: kics scan -p. -q /path/to/custom/queries
  • Exclude specific paths: kics scan -p. --exclude-paths "**/test/*,docs/*"
  • Filter by severity: kics scan -p. --fail-on high,medium

Secret Scanning Capabilities: KICS is capable of detecting hardcoded secrets within IaC files. The KICS query list includes a “Secret Management” category, featuring queries designed to find various types of secrets, such as “Hardcoded AWS Access Key,” “Passwords And Secrets,” and tokens. While GitLab’s SAST IaC scanner (which uses KICS) had secret detection disabled at one point (GitLab 15.3 ), KICS as a standalone tool retains this functionality. Users can also define custom secret detection rules.

Compliance Standard Mapping: KICS queries are organized by categories like “Access Control,” “Encryption,” and “Insecure Configurations” , which are fundamental to many compliance standards (CIS, NIST, PCI DSS, HIPAA, SOC2). While the query list in does not provide explicit, direct mappings from individual queries to these specific standards, KICS is often mentioned in the context of tools that help achieve compliance. For precise mappings, users would typically refer to dedicated KICS compliance documentation or cross-reference query descriptions with standard requirements.

Terrascan

Overview: Terrascan is an open-source static analysis tool, now maintained by Tenable, designed to detect security vulnerabilities and compliance policy violations in a wide range of IaC frameworks. It helps organizations mitigate risks before cloud-native infrastructure is provisioned.

Key Features & Strengths:

  • Extensive Policy Library: Terrascan comes with over 500 out-of-the-box policies covering security best practices for AWS, Azure, GCP, Kubernetes, Docker, and GitHub configurations.
  • Multi-Framework Support: It supports scanning various IaC types, including Terraform (HCL2), Kubernetes (JSON/YAML), Helm v3, Kustomize, Dockerfiles, AWS CloudFormation Templates (CFT), and Azure Resource Manager (ARM) templates.
  • OPA-Based Custom Policies: Terrascan leverages the Open Policy Agent (OPA) engine, allowing users to write custom policies using the Rego query language. This provides significant flexibility for defining organization-specific rules.
  • CI/CD Integration: It can be integrated into various CI/CD pipelines, including GitHub Actions, GitLab CI, Jenkins, ArgoCD, and Atlantis, as well as used with pre-commit hooks.
  • Kubernetes Admission Controller: A notable feature is Terrascan’s ability to function as a Kubernetes admission controller. This allows for the enforcement of policies at the time of deployment to a Kubernetes cluster, preventing non-compliant resources from being created or updated in the runtime environment. This bridges static analysis with runtime policy enforcement using the same OPA engine.
  • Flexible Output Formats: Terrascan supports various output formats for scan results, including YAML, JSON, XML, JUnit-XML, and SARIF, facilitating integration with different reporting and analysis tools.
  • Container Vulnerability Insights: Terrascan can identify security vulnerabilities in container images referenced from popular registries like ECR, ACR, GCR, and Harbor, when scanning IaC files that reference these images.

Optimal Use Cases: Terrascan is particularly well-suited for teams that use a diverse set of IaC tools and are looking for a scanner with broad framework support. Its Kubernetes admission controller functionality makes it highly valuable for organizations prioritizing runtime policy enforcement in Kubernetes environments. Teams already familiar with or willing to learn OPA/Rego will benefit most from its custom policy capabilities. The need for Rego proficiency should be considered if extensive policy customization is planned, though the VS Code extension for Rego editing can aid this.

Licensing: Terrascan is licensed under the Apache 2.0 License. (Note: Snippets refer to “Terrasolid,” a different product, not Tenable’s Terrascan).

Installation & Configuration:

  • Installation: Terrascan offers multiple installation methods, including native executables (downloadable via curl), package managers for ArchLinux (yay) and macOS (brew), Docker images, Python pip install, and direct Windows binary downloads.
    • Using Homebrew: brew install terrascan
    • Using Docker: docker run tenable/terrascan scan --help
    • Using pip: pip install terrascan
  • Configuration: Terrascan can be configured using CLI flags or a TOML configuration file (e.g., terrascan.toml).

CLI Examples:

  • Scan the current directory (defaults to Terraform): terrascan scan or terrascan scan -d.
  • Scan a specific file: terrascan scan -f./iac/main.tf
  • Specify IaC type (e.g., Kubernetes): terrascan scan -i k8s -d./kube-configs/
  • Specify policy type to scan against (e.g., AWS): terrascan scan -t aws
  • Skip specific rules: terrascan scan --skip-rules="AWS.S3.DS.High.1043,AWS.IAM.DS.High.0190"
  • Output in JSON format: terrascan scan -o json > results.json

Trivy

Overview: Trivy, developed by Aqua Security, is a comprehensive and versatile open-source security scanner. Initially known for its robust vulnerability scanning of container images, Trivy has expanded its capabilities significantly to include scanning for OS package vulnerabilities, language-specific dependencies, IaC misconfigurations, hardcoded secrets, and software licenses. Its “all-in-one” nature is a key characteristic.

Key Features & Strengths:

  • Multi-Purpose Scanning: Trivy’s ability to handle diverse security concerns—CVEs, IaC issues, secrets, licenses—in a single tool is a major strength. This consolidation is a notable trend, as evidenced by Aqua Security’s decision to merge tfsec’s capabilities into Trivy. This can simplify security toolchains and provide a more holistic security view.
  • Broad Target Support: Trivy can scan a wide array of targets, including container images (from various registries and tarballs), filesystems, Git repositories (local and remote), virtual machine images, Kubernetes clusters, and AWS environments.
  • IaC Misconfiguration Scanning: It detects configuration issues in popular IaC formats like Docker, Kubernetes, Terraform, CloudFormation, Helm, and more. Trivy can automatically detect mixed types of IaC files within a directory and apply relevant policies.
  • Secret Scanning: Trivy effectively scans for hardcoded secrets such as passwords, API keys, and tokens. It uses a comprehensive set of built-in rules for common secret types (e.g., AWS access keys, GCP service accounts, GitHub PATs, GitLab PATs, Slack tokens) and also allows for custom secret detection rules. It scans plaintext files within its supported targets.
  • CI/CD Integration: Trivy offers an official GitHub Action (aquasecurity/trivy-action) and an official Azure DevOps Task (aquasecurity/trivy-azure-pipelines-task). Community-driven integrations and Orbs are available for other platforms like Jenkins, GitLab CI, and CircleCI.
  • Multiple Output Formats: Trivy supports a rich set of output formats, including human-readable tables, JSON, SARIF (for integration with GitHub Advanced Security and SonarQube), HTML, JUnit, and SBOM formats like CycloneDX and SPDX.
  • SBOM Generation: It can generate Software Bill of Materials (SBOM) and submit them to platforms like the GitHub Dependency Graph.
  • License Scanning: Trivy can scan for software licenses in container images and classify them based on risk (e.g., using Google License Classification).

Optimal Use Cases: Trivy is an excellent choice for teams seeking a unified, versatile scanner to address vulnerabilities, misconfigurations, and secrets across containers, IaC templates, and software dependencies. It is particularly powerful in Kubernetes-centric environments where both the security of container images and the IaC manifests defining the Kubernetes resources are critical. Its comprehensive nature simplifies the security tooling landscape.

Licensing: Trivy is licensed under the Apache 2.0 License.

Installation & Configuration:

  • Installation: Trivy can be installed via package managers like Homebrew (brew install trivy), from binaries, or run as a Docker container (docker run aquasec/trivy).
  • Configuration: Trivy’s behavior is controlled via CLI flags. For more complex configurations, it supports YAML configuration files (e.g., trivy.yaml for general settings, trivy-secret.yaml for secret scanning rules).

CLI Examples:

  • Scan a container image for vulnerabilities: trivy image YOUR_IMAGE_NAME
  • Scan a filesystem for IaC misconfigurations: trivy fs --scanners misconfig /path/to/iac/directory
  • Scan a project for vulnerabilities, secrets, and misconfigurations: trivy fs --scanners vuln,secret,misconfig./myproject/
  • Specify output format (e.g., SARIF for IaC scan): trivy config --format sarif --output results.sarif./iac_configs/
  • Scan for secrets with custom rules: trivy fs --secret-config path/to/custom-secret-rules.yaml.
  • Generate SBOM in CycloneDX format: trivy image --format cyclonedx --output sbom.cdx.json YOUR_IMAGE_NAME

Secret Scanning Capabilities: Trivy has strong secret scanning capabilities. It comes with a rich set of built-in rules to detect various types of secrets, including API keys (AWS, GCP), personal access tokens (GitHub, GitLab), and other sensitive credentials. Users can also define custom secret detection rules using YAML configuration files to tailor the scanning to their specific needs or to detect proprietary secret patterns. Secret scanning is enabled by default when scanning filesystems or repositories and can be explicitly invoked.

Compliance Standard Mapping: Trivy’s misconfiguration policies are based on industry standards. While the provided snippets do not detail explicit, per-policy mappings to specific compliance frameworks like CIS, NIST, PCI DSS, or HIPAA for its IaC checks, its comprehensive scanning for vulnerabilities, misconfigurations, and secrets inherently contributes to achieving and maintaining compliance. The ability to generate SBOMs and scan for license compliance also addresses other facets of regulatory and policy adherence. For detailed compliance mappings, official Trivy documentation would be the primary source.

tfsec

Overview: tfsec is an open-source static analysis security scanner specifically designed for Terraform code. It was developed by Aqua Security and is now in the process of being merged into Trivy to consolidate Aqua’s open-source scanning efforts. It focuses on identifying security misconfigurations and deviations from best practices in Terraform templates.

Key Features & Strengths:

  • Terraform-Focused Analysis: tfsec possesses a deep understanding of Terraform’s HashiCorp Configuration Language (HCL), including its ability to evaluate expressions, resolve local and remote modules, and interpret variables. This specialized focus allows for more accurate detection of Terraform-specific misconfigurations.
  • Comprehensive Check Library: It includes hundreds of built-in checks covering a wide range of potential security issues for various cloud providers like AWS, Azure, and GCP, as well as general Terraform practices.
  • Custom Checks: tfsec supports the creation of custom security policies. Initially, this was often done using JSON or YAML configurations, and it can also apply user-defined Rego policies, leveraging the Open Policy Agent engine.
  • Developer-Friendly Output: Provides clear, actionable reports that include detailed descriptions of detected issues, recommendations for remediation, and links to relevant documentation from cloud providers or Terraform, making it easier for developers to understand and fix vulnerabilities.
  • CI/CD Integration: Designed for easy integration into CI/CD pipelines, with official support for GitHub Actions and an Azure DevOps Task. It can also be run via CLI in other CI systems.
  • IDE Plugins: tfsec offers plugins for popular Integrated Development Environments (IDEs) such as JetBrains IDEs (IntelliJ, GoLand, etc.), Visual Studio Code, and Vim, providing real-time feedback to developers as they code.
  • Speed and Efficiency: Known for its fast scanning capabilities, enabling quick analysis even of large repositories.

Optimal Use Cases: tfsec is an ideal tool for teams whose primary IaC language is Terraform and who require a dedicated, fast scanner with a profound understanding of Terraform’s nuances. Its detailed, developer-centric feedback aids in quick remediation. Given its announced transition into Trivy, new adopters might consider Trivy directly, while existing users should plan for potential migration.

Licensing: tfsec is licensed under the MIT License.

Installation & Configuration:

  • Installation: tfsec can be installed using various methods, including package managers like Homebrew (macOS/Linux), Chocolatey (Windows), and Scoop (Windows). It can also be installed via a bash script for Linux, by direct binary download from its GitHub releases page, or using go install.
    • Using Homebrew: brew install tfsec
    • Using Docker: docker run --rm -v "$(pwd):/src" aquasec/tfsec /src
  • Configuration: tfsec can be configured using CLI flags, a JSON or YAML configuration file, or a .tfsecignore file to exclude specific checks or paths.

CLI Examples:

  • Scan the current directory: tfsec.
  • Exclude specific checks by ID: tfsec. --exclude aws-s3-enable-bucket-logging,azure-storage-queue-services-logging-enabled
  • Output results in JSON format: tfsec. --format json
  • Filter results by minimum severity (e.g., HIGH): tfsec. --minimum-severity HIGH
  • Use a custom configuration file (e.g., for custom checks): tfsec. --config-file custom-checks.yml
  • Include values from a .tfvars file: tfsec. --tfvars-file terraform.tfvars

Secret Scanning Capabilities: tfsec’s primary focus is on detecting infrastructure misconfigurations rather than being a dedicated secret scanner. However, it does include checks that can identify sensitive data hardcoded in Terraform variables (e.g., the general-secrets-sensitive-in-variable check mentioned as excludable in ). Its capabilities in this area are generally less specialized than tools like Checkov or Trivy, which have dedicated secret scanning modules with broader pattern recognition.

Compliance Standard Mapping: The provided snippets do not offer explicit, built-in mappings of tfsec checks to specific compliance standards like CIS, NIST, PCI DSS, or HIPAA. While its misconfiguration checks contribute to overall security posture and thus indirectly to compliance, tfsec is positioned more as a security vulnerability scanner for Terraform code. Users might need to manually map tfsec findings to compliance controls or use it in conjunction with other tools that offer direct compliance reporting.

The strategic decision by Aqua Security to merge tfsec’s capabilities into Trivy is a key consideration for users. While tfsec remains a potent tool for Terraform-specific analysis due to its deep HCL parsing , new adopters should evaluate Trivy for a more future-proof solution aligned with Aqua’s open-source strategy. Existing tfsec users should explore the migration path to leverage Trivy’s broader feature set and ongoing development focus.

Open Policy Agent (OPA)

Overview: Open Policy Agent (OPA) is a powerful, general-purpose, open-source policy engine. It provides a unified framework and a high-level declarative language called Rego to define, manage, and enforce policies across various layers of the technology stack, including Infrastructure as Code. OPA itself is not a standalone IaC scanner but rather an engine that can be leveraged by IaC scanning tools (like Terrascan and tfsec ) or used directly to make policy decisions on IaC configurations.

Key Features & Strengths:

  • Declarative Policy Language (Rego): Rego is purpose-built for expressing policies over complex hierarchical data structures like JSON or YAML, which are common for IaC. It allows for concise and expressive policy definitions.
  • Decoupled Policy Decisions: OPA separates policy decision-making logic from the application or tool logic. This means policies can be developed, managed, and updated independently of the systems they govern.
  • JSON-Native Processing: OPA is designed to work natively with JSON input. Since most IaC tools can output their plans or configurations in JSON format (e.g., terraform show -json), OPA can readily consume this data for policy evaluation.
  • Versatile Integration Patterns: OPA can be deployed as a standalone daemon, a sidecar container, or embedded as a Go library or WebAssembly (Wasm) module, offering flexibility in how it’s integrated into different systems and workflows.
  • Broad Applicability (Policy-as-Code - PaC): OPA enables a true Policy-as-Code (PaC) approach, where policies are treated as code—versioned, tested, and deployed alongside application and infrastructure code. This aligns policy management with DevOps best practices, leading to more robust, auditable, and maintainable enforcement.
  • Growing Ecosystem: OPA is a CNCF graduated project with a vibrant community, an expanding ecosystem of integrations, and a growing library of community-contributed policies.

Optimal Use Cases: OPA is best suited for organizations that require fine-grained, highly customizable policy enforcement across a diverse set of tools and platforms, extending beyond just IaC to areas like Kubernetes admission control, API authorization, and microservice security. It is the engine of choice for implementing comprehensive Policy-as-Code strategies. While it has a learning curve, particularly for Rego, the investment can yield significant benefits by providing a consistent policy framework across the entire technology stack.

Supported IaC Formats: As a general-purpose policy engine, OPA can process any IaC configuration or plan file that can be represented as JSON. This commonly includes:

  • Terraform plan files (converted to JSON via terraform show -json)
  • Kubernetes manifests (YAML/JSON)
  • AWS CloudFormation templates (JSON)
  • Azure Resource Manager templates (JSON)

Licensing: Open Policy Agent is licensed under the Apache 2.0 License.

Installation & Configuration:

  • Installation: OPA can be downloaded as a binary for various operating systems or run as a Docker container (openpolicyagent/opa).
    • Using curl (Linux example): curl -L -o opa https://openpolicyagent.org/downloads/latest/opa_linux_amd64_static && chmod +x./opa
  • Configuration: Policies are written in Rego and saved as .rego files. OPA is typically invoked with one or more policy files and an input JSON document.

CLI Examples (using OPA directly for IaC):

  • Basic Policy Evaluation:$./opa eval -i input.json -d policy.rego "data.example_policy.allow" (Where input.json contains the IaC data, and policy.rego defines data.example_policy.allow)

  • Evaluating a Terraform Plan:

    1. Generate the plan in JSON: $ terraform plan -out=tfplan.binary$ terraform show -json tfplan.binary > tfplan.json

    2. Create a Rego policy (e.g., terraform_policy.rego): Code snippet

      package terraform.analysis
      
          default allow = false
      
          # Deny if any S3 bucket is configured with public-read ACL
          deny[msg] {
              resource := input.resource_changes[_]
              resource.type == "aws_s3_bucket"
              resource.change.after.acl == "public-read"
              msg := sprintf("S3 bucket %s must not have public-read ACL", [resource.address])
          }
      
          allow {
              count(deny) == 0
          }
          ```
Back to Blog