HOWTOIntermediate

Scan Terraform, Dockerfiles and Kubernetes Manifests with Checkov

Catch cloud and container misconfigurations before they ship: install Checkov, scan IaC, tune policies with baselines and skips, and gate pull requests in CI.

Dylan H.

Tutorials

November 23, 2026
4 min read
Scan Terraform, Dockerfiles and Kubernetes Manifests with Checkov

Introduction

Most cloud breaches trace back to misconfiguration, not zero-days: a public storage bucket, a security group open to the world, a container running as root. When infrastructure is defined as code, those mistakes are visible in a pull request, which means you can catch them before anything is deployed.

Checkov is an open-source static analysis tool for infrastructure as code. It ships with hundreds of built-in policies covering Terraform, CloudFormation, Kubernetes, Helm, Dockerfiles, GitHub Actions and more. It reads files only and needs no cloud credentials.

In this guide you will install Checkov, scan a sample project, read the results, suppress false positives properly, adopt it on an existing repo with a baseline, and enforce it in CI.

Prerequisites

  • Python 3.9+ and pip (or pipx)
  • A repo with IaC files. If you have none, the steps below create a small test project
  • Permission to add a workflow file if you want the CI gate

Step 1: Install Checkov

Use pipx so Checkov gets an isolated environment:

python3 -m pip install --user pipx
pipx ensurepath
pipx install checkov
checkov --version

Alternatively, run it from the container image with no local install:

docker run --rm -v "$PWD":/tf -w /tf bridgecrew/checkov -d .

Step 2: Create a deliberately flawed test project

mkdir -p iac-demo && cd iac-demo
 
cat > main.tf <<'EOF'
resource "aws_s3_bucket" "logs" {
  bucket = "example-demo-logs-bucket"
}
 
resource "aws_security_group" "web" {
  name = "web"
  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}
EOF
 
cat > Dockerfile <<'EOF'
FROM ubuntu:latest
RUN apt-get update && apt-get install -y curl
COPY . /app
CMD ["/app/run.sh"]
EOF

Step 3: Run your first scan

Scan the whole directory and let Checkov detect each framework:

checkov -d .

Each finding prints a policy ID such as CKV_AWS_24 (SSH open to the world), the resource, the file and line range, and a link to remediation guidance. A summary shows passed, failed and skipped counts.

Limit the scan to one framework when you need speed or focus:

checkov -d . --framework terraform
checkov -f Dockerfile --framework dockerfile
checkov -d k8s/ --framework kubernetes

Step 4: Fix the findings

Harden the Terraform by restricting SSH to an admin range and enabling bucket protections:

resource "aws_security_group" "web" {
  name        = "web"
  description = "Web tier"
  ingress {
    description = "SSH from admin VPN only"
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["10.20.0.0/24"]
  }
}

Fix the Dockerfile by pinning the tag, dropping root and adding a health check:

FROM ubuntu:24.04
RUN apt-get update \
 && apt-get install -y --no-install-recommends curl \
 && rm -rf /var/lib/apt/lists/* \
 && useradd -r -u 10001 appuser
COPY --chown=appuser . /app
USER appuser
HEALTHCHECK CMD curl -fs http://localhost:8080/health || exit 1
CMD ["/app/run.sh"]

Re-run checkov -d . and watch the failed count drop.

Step 5: Suppress false positives with a reason

Some checks do not apply. A public website bucket legitimately allows public reads, for example. Suppress inline, and always record why:

resource "aws_s3_bucket" "site" {
  #checkov:skip=CKV_AWS_18:Access logging not required for public static assets
  bucket = "example-public-site"
}

For Dockerfiles, use a comment above the instruction:

# checkov:skip=CKV_DOCKER_2:Short-lived batch job, no health check needed

You can also skip globally, but use sparingly:

checkov -d . --skip-check CKV_AWS_18,CKV_DOCKER_2

Step 6: Adopt on an existing repo with a baseline

Turning on a scanner for a mature repo can produce hundreds of failures. Create a baseline so only new findings block merges, then pay down the old ones over time:

checkov -d . --create-baseline
# writes .checkov.baseline
 
checkov -d . --baseline .checkov.baseline

Commit .checkov.baseline so CI uses the same reference.

Step 7: Configure with .checkov.yaml

Keep options in version control instead of long command lines:

directory:
  - .
framework:
  - terraform
  - dockerfile
  - kubernetes
skip-path:
  - node_modules
  - .terraform
soft-fail-on:
  - LOW
hard-fail-on:
  - HIGH
  - CRITICAL
compact: true
quiet: true

Severity-based gating requires severity metadata, which newer Checkov versions provide. If your version reports no severities, drop the two fail-on keys and rely on exit codes. Checkov exits non-zero when any check fails.

Step 8: Gate pull requests in GitHub Actions

name: iac-scan
on:
  pull_request:
    paths:
      - "**.tf"
      - "**/Dockerfile*"
      - "k8s/**"
permissions:
  contents: read
  security-events: write
jobs:
  checkov:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install checkov
      - name: Run Checkov
        run: checkov --config-file .checkov.yaml --output cli --output sarif --output-file-path console,results.sarif
      - name: Upload SARIF
        if: always()
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: results.sarif

For production use, pin actions to full commit SHAs and pin the Checkov version (pip install checkov==<version>) so a new release cannot unexpectedly break builds. Upgrade deliberately.

Step 9: Write a custom policy

Organization-specific rules go in YAML. Require a owner tag on every AWS resource that supports tags:

# policies/require-owner-tag.yaml
metadata:
  id: "CKV2_CUSTOM_1"
  name: "Ensure resources have an owner tag"
  category: "GENERAL_SECURITY"
definition:
  cond_type: attribute
  resource_types:
    - aws_instance
    - aws_s3_bucket
  attribute: tags.owner
  operator: exists
checkov -d . --external-checks-dir policies/

Verification

  1. Run checkov -d . ; echo "exit=$?". A repo with failures must exit 1, and a clean one 0.
  2. Introduce a regression, such as reopening 0.0.0.0/0 on port 22, and confirm CKV_AWS_24 fails again.
  3. Confirm skips appear in the summary as Skipped checks and carry your comment.
  4. Open a test pull request and verify the workflow fails on the bad change and passes on the fix.
  5. Check the GitHub Security tab for SARIF results if you enabled the upload.

Troubleshooting

SymptomLikely cause and fix
checkov: command not foundRun pipx ensurepath and restart the shell
No resources scannedWrong --framework, or files in a skipped path. Run with -d . --framework all and check skip-path
Terraform modules not evaluatedRun terraform init first, or use --download-external-modules true for remote modules
Variables show as unresolvedPass --var-file prod.tfvars, or scan a terraform show -json plan: checkov -f plan.json
CI suddenly fails with no code changeA new Checkov release added checks. Pin the version and upgrade on a schedule
Skip comment ignoredThe ID must match exactly and the comment must sit inside the resource block
Slow scans on big monoreposUse --skip-path, scan only changed directories, and avoid scanning .terraform caches

Summary

  • Checkov scans Terraform, Dockerfiles, Kubernetes, CloudFormation and more with no cloud credentials
  • Fix findings in code, and when you skip a check, record a reason inline
  • Use --create-baseline to adopt the tool on legacy repos without blocking every merge
  • Keep settings in .checkov.yaml and gate pull requests with a pinned CI job
  • Add custom YAML policies to enforce organization standards such as required tags
  • Static scanning complements, but does not replace, runtime monitoring and cloud posture review