Infrastructure as Code (IaC) Security
Infrastructure as code (IaC) security means checking the code files that create cloud servers, networks and permissions for insecure settings before they're deployed, so misconfigurations are caught before they reach the cloud.
Also called: IaC security, IaC scanning, Terraform security, policy as code
What is infrastructure as code?
Instead of clicking through a cloud console to create servers, databases, networks and permissions, teams increasingly describe them in code files, using tools such as Terraform, AWS CloudFormation, Azure Bicep, Pulumi, Ansible and Kubernetes manifests. That code is stored in a repository and deployed automatically, so environments are consistent and repeatable.
The catch: a mistake in the code is repeated every time it's deployed. One insecure template can create dozens of exposed resources.
What IaC security covers
IaC security scans those files before deployment, catching problems while they're still just text:
- Storage buckets set to public
- Databases or admin ports open to the whole internet
- Encryption turned off
- Overly broad identity roles, such as wildcards granting all permissions
- Logging disabled
- Passwords and keys written directly in the code
- Containers set to run as root or privileged
These are exactly the cloud misconfigurations that CSPM tools find after deployment. IaC scanning is the "shift left" version: prevent rather than detect.
How it works
- Scan in the developer's editor and on every pull request, using tools such as Checkov, tfsec or Trivy, or features built into commercial code security platforms.
- Block risky changes in the CI/CD pipeline with policy-as-code rules, such as "no public storage" or "all databases encrypted".
- Review changes like any other code, since a pull request shows exactly what will change in the infrastructure.
- Keep secrets out of IaC files using a secrets manager, and protect state files, which can contain sensitive values.
- Detect drift: compare what's actually running with what the code says, because manual console changes bypass all these checks.
NIST's guidance on CI/CD supply chain security treats infrastructure definitions as code that should pass through the same protected pipeline as the application.
Who needs it
Any team that defines cloud infrastructure in code. If an IT provider or developer builds your cloud environment, ask whether they use IaC and scan it.
Related terms
Sources
Drafted with AI assistance, then edited and fact-checked by a person. How we use AI.
