Checkov

Checkov is a static code analysis tool for infrastructure-as-code (IaC) that scans cloud infrastructure provisioned using Terraform, CloudFormation, Kubernetes, Helm, ARM Templates and Serverless framework.

Installation

Using pip

pip install checkov

Using Homebrew

brew install checkov

Using Docker

docker pull bridgecrew/checkov

Basic Usage

Scan a Directory

checkov -d /path/to/terraform/code

Scan a Specific File

checkov -f /path/to/terraform/file.tf

Output Formats

Configuration

Skip Checks

Create .checkov.yaml in your project root:

Policy Categories

  1. Security

    • Access Control

    • Encryption

    • Network Security

    • IAM

  2. Compliance

    • HIPAA

    • PCI DSS

    • SOC2

    • NIST

  3. Operational Excellence

    • Backups

    • Monitoring

    • High Availability

CI/CD Integration

GitHub Actions

Azure DevOps Pipeline

Pre-commit Hook

Add to .pre-commit-config.yaml:

Common Security Checks

1. S3 Bucket Security

2. Security Group Rules

Custom Policies

Create custom_policies.py:

Best Practices

  1. Regular Scanning

    • Integrate with CI/CD

    • Use pre-commit hooks

    • Schedule periodic scans

  2. Policy Management

    • Document skip decisions

    • Review skipped checks regularly

    • Maintain custom policies

  3. Remediation

    • Prioritize findings

    • Track fixes

    • Validate fixes

Checklist

Last updated