Infrastructure as Code Security: Scanning Terraform and CloudFormation Before Misconfiguration Reaches Production
Cloud misconfigurations are the leading cause of cloud security incidents. S3 buckets open to the public, security groups with 0.0.0.0/0 ingress on port 22, IAM roles with wildcard permissions, encryption disabled on databases -- these are not sophisticated attacks. They are configuration errors that become exploitable the moment the resource is deployed. Infrastructure as Code scanning prevents these errors from reaching production by analyzing Terraform, CloudFormation, and Kubernetes manifests in the same code review workflow used for application code. This guide covers the tooling landscape, the highest-priority misconfigurations to catch, CI/CD integration patterns, and the policy-as-code layer for enforcing organizational security standards.
The Highest-Priority Misconfigurations IaC Scanning Must Catch
Not all IaC findings are equal. Start by ensuring your scanner reliably catches the misconfigurations most commonly exploited in real cloud breaches.
Publicly accessible storage:
S3 buckets with block_public_acls = false or bucket-public-access-block resources missing. Azure Storage accounts with allow_blob_public_access = true. Google Cloud Storage buckets with allUsers or allAuthenticatedUsers IAM bindings. Public storage is responsible for more cloud data exposures than any other misconfiguration category.
Overly permissive network access: Security groups with ingress rules permitting 0.0.0.0/0 (any source) to ports 22 (SSH), 3389 (RDP), 5432 (PostgreSQL), 3306 (MySQL), or 6379 (Redis). These are the top five ports targeted by automated internet scanners. A database security group with 0.0.0.0/0 ingress is a critical finding that should block deployment.
IAM privilege escalation paths:
IAM policies with "Action": "*" or "Resource": "*", inline policies attached directly to users rather than roles, and roles with the AdministratorAccess managed policy attached to non-administrative services. IaC scanners do not perform full privilege escalation graph analysis (that requires tools like PMapper or Cloudsplaining) but they catch the most obvious wildcard permission patterns.
Encryption disabled at rest and in transit:
RDS instances without storage_encrypted = true, S3 buckets without server-side encryption configured, EBS volumes without encryption, and load balancers configured with HTTP rather than HTTPS listeners. Most compliance frameworks (PCI DSS, HIPAA, SOC 2) require encryption at rest and in transit as baseline controls.
Logging and monitoring gaps: CloudTrail disabled, VPC Flow Logs not enabled, S3 access logging disabled, and CloudWatch log groups without retention periods set. These are not directly exploitable but are required for incident response and create compliance gaps.
IaC Scanning Tool Comparison: Checkov, tfsec, Terrascan, and KICS
| Tool | Supported IaC | Rule Count | CI/CD Integration | Policy Language | License |
|---|---|---|---|---|---|
| Checkov | Terraform, CF, K8s, ARM, Pulumi, Helm | 1,000+ | GitHub Actions, GitLab, Jenkins, CircleCI | Python or YAML | Open source (Apache 2) |
| tfsec | Terraform only | 400+ | All major CI platforms | Rego (OPA) | Open source (MIT) |
| Terrascan | Terraform, K8s, CF, Helm, ARM, Kustomize | 500+ | All major CI platforms | Rego (OPA) | Open source (Apache 2) |
| KICS | 20+ IaC frameworks | 2,000+ | All major CI platforms | JSON | Open source (Apache 2) |
| Semgrep | Terraform (limited) | Community rules | All major CI platforms | YAML | Open source + enterprise |
| Snyk IaC | Terraform, CF, K8s, ARM | 500+ | All major CI platforms | Rego (OPA) | Freemium |
| Wiz IaC | All major IaC + graph analysis | Proprietary | All major CI platforms | Proprietary | Commercial |
Checkov is the most widely adopted open-source IaC scanner, with the broadest framework coverage and the largest rule library. Developed by Bridgecrew (now part of Palo Alto Networks Prisma Cloud), it remains open source and receives active community contributions. Checkov outputs results in multiple formats including SARIF (for GitHub Code Scanning), JUnit XML (for CI pass/fail), and JSON for programmatic processing. Best choice for most organizations starting with IaC scanning.
tfsec is Terraform-specific and deeply optimized for Terraform HCL analysis. If your IaC is exclusively Terraform, tfsec provides faster scans and more Terraform-specific rules than general-purpose scanners. Now maintained as part of the aquasecurity ecosystem alongside Trivy.
KICS (Keeping Infrastructure as Code Secure) by Checkmarx has the broadest framework coverage and largest rule count, making it valuable in polyglot IaC environments. The tradeoff is higher false positive rates and longer scan times on large codebases.
Briefings like this, every morning before 9am.
Threat intel, active CVEs, and campaign alerts, distilled for practitioners. 50,000+ subscribers. No noise.
CI/CD Integration: Blocking Deployments on Critical Findings
The value of IaC scanning is zero if findings are reported but not acted upon. Integrate scanning into your deployment pipeline with hard failures on critical findings.
GitHub Actions integration pattern with Checkov:
- name: Run Checkov IaC scan
uses: bridgecrewio/checkov-action@v12
with:
directory: ./terraform
framework: terraform
soft_fail: false
check: CKV_AWS_18,CKV_AWS_20,CKV_AWS_57
output_format: sarif
output_file_path: results.sarif
- name: Upload Checkov results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
Set soft_fail: false to fail the pipeline on any finding. Start with a subset of critical checks using the check: parameter rather than enabling all rules immediately -- this prevents alert fatigue and gives developers a manageable remediation queue.
Pre-commit hooks for immediate feedback: Run IaC scanning as a pre-commit hook so developers see issues before pushing. The pre-commit framework supports Checkov, tfsec, and Terrascan. This gives the fastest feedback loop: finding a misconfiguration locally takes seconds to fix; finding it after a failed CI run takes 10-15 minutes.
Baseline and suppression management: Every team inherits legacy IaC with existing findings. Use a baseline file (Checkov supports --baseline flags) to track the existing finding count without failing builds on pre-existing issues, while blocking any new misconfigurations from being introduced. Suppression comments in Terraform code (# checkov:skip=CKV_AWS_18:Justification here) should require a documented justification and be reviewed in code review.
Policy as Code with OPA and HashiCorp Sentinel
IaC scanners provide generic security rules. Policy as Code lets you enforce organization-specific requirements that generic rules cannot express: your company's required tags, approved AMI lists, mandatory backup retention periods, or region restrictions.
Open Policy Agent (OPA) with Conftest: OPA is a general-purpose policy engine. Conftest uses OPA's Rego policy language to validate structured data -- including Terraform plan JSON output. Write Rego policies that express your organizational requirements and run them against terraform plan -out=tfplan && terraform show -json tfplan output.
Example Rego policy requiring all S3 buckets to have versioning enabled:
deny[msg] {
resource := input.resource_changes[_]
resource.type == "aws_s3_bucket"
not resource.change.after.versioning[_].enabled
msg := sprintf("S3 bucket '%v' must have versioning enabled", [resource.address])
}
HashiCorp Sentinel integrates directly into Terraform Cloud and Terraform Enterprise as the policy enforcement layer. Sentinel policies run after terraform plan and before terraform apply, with three enforcement levels: advisory (log but allow), soft-mandatory (warn but allow override with approval), and hard-mandatory (block with no override). Sentinel is the right choice for organizations using Terraform Cloud as their deployment platform; OPA/Conftest is better for teams with self-managed CI/CD.
Common organizational policies to encode:
- Require specific tags (Environment, Owner, CostCenter, DataClassification) on all resources
- Restrict deployment to approved AWS regions or Azure locations
- Require specific instance types or SKUs (preventing accidental large instance deployment)
- Enforce minimum backup retention periods for databases
- Require MFA delete on S3 buckets
- Restrict to approved AMI IDs or OS images
Drift Detection: When Live Infrastructure Diverges from IaC State
IaC scanning prevents misconfigurations at deployment time. But infrastructure drifts: developers make emergency changes in the console, automated systems modify resources, or manual changes bypass the IaC workflow. Drift detection identifies when your live cloud environment no longer matches the state defined in your IaC.
Terraform drift detection: terraform plan reports drift between the Terraform state file and the live cloud environment. Run terraform plan on a schedule (not just before deployments) in read-only mode and alert on any non-zero plan output. AWS Service Control Policies or Azure Policy can detect and alert on out-of-band console changes.
CSPM for continuous drift detection: Cloud Security Posture Management tools (Wiz, Orca, Prisma Cloud, AWS Security Hub) continuously scan your live cloud environment against security benchmarks. They are complementary to IaC scanning: IaC scanning prevents misconfigurations from being deployed; CSPM finds misconfigurations that exist in the running environment regardless of how they got there.
Drift remediation strategy:
When drift is detected, the correct response depends on the cause. If a developer made a legitimate emergency change, import the change into the IaC state (terraform import) and submit it for code review. If the change is unauthorized, investigate it as a potential security incident -- unauthorized infrastructure changes are a lateral movement indicator. Never simply run terraform apply to overwrite a drifted state without investigating why the drift occurred.
The bottom line
IaC security scanning is one of the highest-ROI security investments available to cloud-native organizations. It prevents the misconfigurations responsible for the majority of cloud breaches -- for free, using open-source tools, integrated into an existing CI/CD pipeline. Start with Checkov covering your highest-criticality Terraform modules, fail builds on critical findings (public S3, 0.0.0.0/0 ingress, encryption disabled), and build the policy-as-code layer to enforce organizational standards once the baseline scanning is producing clean results. Add drift detection via scheduled Terraform plans or a CSPM tool as the program matures.
Frequently asked questions
What is the difference between IaC security scanning and CSPM?
IaC scanning analyzes Terraform, CloudFormation, and other IaC templates before deployment -- it catches misconfigurations at the code level, before any cloud resources are created. CSPM (Cloud Security Posture Management) continuously scans your live cloud environment and identifies misconfigurations in running resources, regardless of how they were created. They are complementary: IaC scanning prevents misconfigurations from being deployed; CSPM finds misconfigurations that already exist, including those created via the console, API calls, or automated systems that bypassed IaC.
Which IaC scanner should I start with?
Checkov is the recommended starting point for most organizations. It has the broadest IaC framework support (Terraform, CloudFormation, Kubernetes, ARM templates, Helm, Pulumi), the largest rule library (1,000+ checks), excellent CI/CD integration with SARIF output for GitHub Code Scanning, and active open-source development. If your IaC is exclusively Terraform, tfsec provides Terraform-specific optimization. For organizations already using Palo Alto Prisma Cloud or Snyk, their native IaC scanning modules integrate with the broader platform.
How do I handle false positives in IaC scanning without disabling checks?
Use suppression comments directly in the IaC code with documented justification, rather than disabling entire rule categories. In Terraform, Checkov supports inline skips: add a comment like `# checkov:skip=CKV_AWS_18:Public access required for static website hosting` adjacent to the resource. Require suppression comments to be reviewed in the pull request and tracked in a risk register. This approach maintains visibility into accepted risks rather than silently disabling checks. Baseline files let you acknowledge existing findings in legacy code without failing new work.
Can IaC scanning detect privilege escalation paths in IAM policies?
IaC scanners catch obvious IAM misconfigurations (wildcard actions, wildcard resources, AdministratorAccess policy attachment) but they do not perform full privilege escalation graph analysis. For that, use dedicated IAM analysis tools: AWS IAM Access Analyzer, PMapper (Python privilege escalation mapper for AWS), Cloudsplaining (generates privilege escalation reports from IAM policy documents), or the IAM analysis capabilities built into commercial CSPM tools like Wiz or Prisma Cloud. IAM privilege escalation analysis is most valuable after an IaC scan identifies the worst offenders.
How do I implement IaC scanning without slowing down developer velocity?
Speed matters for adoption. Run IaC scans in parallel with other CI checks rather than sequentially. Use pre-commit hooks for instant local feedback before code reaches CI. Start with a targeted check list covering only the 10-20 highest-criticality rules (public storage, open security groups, encryption, MFA delete) and expand the rule set as developers build familiarity. Present findings in the pull request code review interface (via SARIF upload) so developers fix issues in context rather than navigating a separate security dashboard. Most IaC scans complete in under 30 seconds on moderate-sized codebases.
What is Terraform drift and why is it a security concern?
Terraform drift occurs when the live cloud environment diverges from the state defined in your Terraform code -- typically because someone made a change via the AWS console, CLI, or API outside the IaC workflow. Drift is a security concern because it indicates unreviewed infrastructure changes that may introduce misconfigurations, and it means your IaC code no longer accurately represents what is running in production. In security investigations, unexpected infrastructure drift (a new security group rule, an IAM role change, a new EC2 instance) can indicate unauthorized access or attacker lateral movement. Run scheduled Terraform plans in read-only mode and alert on any plan output as a drift detection mechanism.
Sources & references
Free resources
Critical CVE Reference Card 2025–2026
25 actively exploited vulnerabilities with CVSS scores, exploit status, and patch availability. Print it, pin it, share it with your SOC team.
Ransomware Incident Response Playbook
Step-by-step 24-hour IR checklist covering detection, containment, eradication, and recovery. Built for SOC teams, IR leads, and CISOs.
Get threat intel before your inbox does.
50,000+ security professionals read Decryption Digest for early warnings on zero-days, ransomware, and nation-state campaigns. Free, weekly, no spam.
Unsubscribe anytime. We never sell your data.

Founder & Cybersecurity Evangelist, Decryption Digest
Cybersecurity professional with expertise in threat intelligence, vulnerability research, and enterprise security. Covers zero-days, ransomware, and nation-state operations for 50,000+ security professionals weekly.
The Mythos Brief is free.
AI that finds 27-year-old zero-days. What it means for your security program.
