Lesson 7 of 12 · 20m
IaC Scanning: Kill the Misconfig in the Diff
The public S3 bucket is born as one line in a Terraform PR weeks before deploy — trivy config and Checkov gate the diff, and tfstate carries plaintext secrets.
The misconfig that opens your database to the internet isn't born in the cloud console — it's born in a pull request, as one line in a Terraform file, weeks before anyone deploys it. That's the leverage: infrastructure-as-code turns "someone clicked the wrong thing in a console" into "a diff a scanner can read," and a diff can be gated.
The wrong mental model is "misconfiguration is an ops problem found by auditing the environment." Console audits find what exists. IaC scanning finds what will exist — and it comments on the line while the author still remembers writing it.
What the scanner reads
Tools like trivy config and Checkov parse Terraform, CloudFormation, Kubernetes manifests, Helm, and Dockerfiles, then match resources against policy-as-code rule sets. tfsec's checks were merged into Trivy in 2024 — install Trivy, not the abandoned standalone binary. A typical gate:
trivy config --severity HIGH,CRITICAL --exit-code 1 terraform/
# checkov's --check takes check IDs — severity words like HIGH,CRITICAL
# only filter behind a Prisma Cloud API key (--bc-api-key); keyless, gate on names
checkov -d terraform/ --framework terraform --check CKV_AWS_20,CKV_AWS_24What it catches, concretely:
resource "aws_security_group_rule" "ssh" {
type = "ingress"
from_port = 22
to_port = 22
cidr_blocks = ["0.0.0.0/0"] # every finding engine on earth flags this
}
resource "aws_s3_bucket" "reports" {
acl = "public-read" # aws_s3_bucket_public_access_block exists for a reason
}containers:
- name: app
securityContext:
privileged: true # container = host, more or less
image: registry.internal/app:latestSecurity groups wide open on 22 or 3389, public S3 buckets and SAS tokens, privileged: true and hostNetwork: true in pod specs, runAsUser: 0, missing encryption flags on RDS/EBS/azurerm_storage_account, :latest image tags, plaintext secrets in user_data and environment blocks. These aren't exotic — they're the rule families every IaC scanner ships in its first hundred checks.
Why it earns its keep
Public-bucket and open-ACL misconfigs are the recurring mechanism behind a decade of data leaks — the Verizon/NICE Systems exposure in 2017 put up to 14 million subscriber records in a public S3 bucket — UpGuard's count; Verizon acknowledged six million — and the pattern hasn't slowed since. Capital One's 2019 breach ran through an over-permissive IAM role attached to a WAF EC2 instance — an infrastructure decision, not an application bug. A trivy config check for wildcard IAM actions and public buckets costs CI seconds; the incident costs years.
Two traps nobody warns you about
- Terraform state is a secrets store.
terraform.tfstatecarries plaintext resource attributes — including any secret you passed touser_data, a random provider output, or a database password. Lock down the state backend (private bucket, encryption, no public CI artifacts), and neverterraform show -jsoninto a log. - Plan output leaks. CI logs that echo
terraform planprint+ password = "hunter2"for everyone with Actions read access. Mask it, or run plans where the output isn't world-readable.
Where it fits
Gate PRs that touch *.tf, main.yml under kubernetes/, and Dockerfile — the findings are cheap, fast, and mostly true positives. Custom rules ride along: Checkov custom checks in Python or YAML, OPA/Rego via conftest test -p policy/ for the policies no pack knows — "every load balancer needs waf_enabled", "no namespace outside prod-* may request a public IP."
One honest limit: IaC scanning sees the intent, not the drift. The Terraform may be clean while the live account has a security group someone opened by hand in March. Cloud-side audit tools — Prowler, ScoutSuite, aws config conformance packs — close that gap from the other direction, and they belong on the scheduled side of the pipeline.
Field notes
- Scan the modules, not just the root repo — your
modules/vpc/is where0.0.0.0/0hides. - Kubernetes YAML gets scanned by the same tools;
kube-linterandkubesecadd pod-security-specific checks forsecurityContextgaps. - A finding in IaC is one line to fix. This is the highest fix-per-dollar ratio in the whole course — gate it hard.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Buying Time: Package Managers Are Adding Delay as a Security Control
Composer 2.11 shipped a cooldown that refuses to install a version until it has aged. vlt now holds npm publishes until their dependencies actually exist, because 22% of new npm versions land broken. And Ruby Central's reviewers threw out 90% of what an AI scanner flagged.
Your npm Install Just Ran Someone Else's Code: Why Dependency Security Has to Start Before CI
A pull request checkout, a poisoned GitHub Actions cache, and an OIDC token pulled straight out of runner memory. That's how 84 malicious versions of TanStack's packages hit npm in six minutes.
CVE-2025-62718: Critical Axios SSRF Vulnerability Explained
A critical SSRF flaw in Axios was used in a North Korean supply chain attack. Here's what it does and how to patch it today.
What is Supply Chain Security? Dependencies, SBOMs, and the Attack That Hit 2.6 Billion npm Downloads
Your application is only as secure as every package it depends on. In September 2025, attackers compromised 27 npm packages with 2.6 billion weekly downloads by phishing one maintainer.