Checkov
Checkov is an open-source static code analysis tool that performs security and compliance scanning for Infrastructure as Code (IaC) and Software Composition Analysis (SCA). It identifies misconfigurations and vulnerabilities in various IaC frameworks (e.g., Terraform, CloudFormation, Kubernetes, Dockerfiles, Bicep, Serverless) and scans container images and open-source packages for Common Vulnerabilities and Exposures (CVEs). Actively maintained by Prisma Cloud, Checkov has a frequent release cadence, often with multiple patch versions released monthly.
Warnings
- breaking The migration from Checkov v2 to v3 introduced several breaking changes. These include the removal of the 'level up' flow, changes to the syntax for Python custom checks, and the replacement of deprecated flags like `--no-guide` and `--skip-suppressions` with the unified `--skip-download` flag.
- gotcha When scanning a Terraform plan outputted to JSON (e.g., `terraform show -json tf.plan > tf.json`), the resulting `tf.json` file is often a single line. This causes Checkov to report all findings on line number 0, making it difficult to pinpoint the exact location of issues in the original plan.
- gotcha Checkov's installation and usage on Alpine Linux is not officially supported and is generally not recommended for larger Python projects due to potential incompatibilities with C extensions. While it might work with Python 3.11+, stability is not guaranteed.
- gotcha When using Checkov with an API key (e.g., for integrating with Prisma Cloud), the `--repo-id` flag is now a mandatory requirement. Failing to provide this flag will result in an error or incomplete functionality.
Install
-
pip install checkov
Imports
- CheckResult
from checkov.common.models.enums import CheckResult
- CheckCategories
from checkov.common.models.enums import CheckCategories
- BaseResourceCheck
from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck
Quickstart
checkov --directory ./my-iac-code # Example: Scan a Terraform directory # checkov --directory /path/to/my/terraform/configs # Example: Scan a specific Kubernetes manifest file # checkov --file /path/to/my/k8s/deployment.yaml # Example: Scan a Terraform plan JSON, ensuring multiline output for better line numbers # terraform init # terraform plan -out tf.plan # terraform show -json tf.plan | jq '.' > tf.json # checkov --file tf.json