Infrastructure as Code (IaC) is the standard method to deploy and manage cloud deployments. The benefits are obvious: faster deployment times, improved repeatability, and increased standardization across cloud infrastructure.
However, the flexibility and power of IaC also introduces unique risks. IaC configurations define your infrastructure, including sensitive settings, access permissions, and operational behaviors.
A single misconfiguration or exposed secret can compromise entire environments. Additionally, IaC integrates with a variety of external plugins and providers, creating a dependency chain vulnerable to supply chain attacks.
As the practice of IaC evolves, additional emphasis is placed on building security into the IaC development lifecycle to protect infrastructure resources and avoid security and compliance violations. This article discusses approaches and tools for securing Infrastructure as Code workloads, from development to running environments.
IaC Security Tools Defined
Before we discuss specific tools, it is important to understand the background of IaC security approaches. This prerequisite knowledge will help you make informed decisions about the IaC security features that your organization needs when choosing which tools to use.
The Necessity of IaC Security
First, let’s discuss why you need to build security into your IaC workflows. Infrastructure as Code enables more members of an organization – from software developers to platform engineers – to build infrastructure in a repeatable way.
Organizations benefit from this approach in many ways. Infrastructure provisioning lead times decrease, consistency improves, and the risk of human error causing misconfigurations or security issues is greatly reduced. Additionally, it's easier to make and roll back infrastructure changes.
However, this approach also comes with increased responsibility. IaC allows for large-scale deployments but introduces the challenge of managing two layers of complexity: the code that defines resources and the resources themselves.
This introduces new opportunities for security mistakes and misconfigurations. Engineers need help securing their infrastructure resources, and a rich ecosystem of Infrastructure as Code security tools has developed to meet this need.
Approaches to Security Scanning
Just as software engineering has adopted a shift-left approach to integrating testing earlier in the software development lifecycle, so did IaC practitioners begin embedding security measures earlier in their workflows. This proactive approach ensures that security is a foundational element of infrastructure design, rather than an afterthought. The tools discussed in this article take two broad approaches to IaC security:
- Proactive: The tool scans IaC code and configuration files before they are deployed and identifies misconfigurations before they reach an environment. This approach is similar to the static code analysis tools used by software engineers.
- Reactive: The tool scans existing infrastructure and identifies misconfigurations in the running environment. For example, a reactive tool might scan your cloud services for existing misconfigurations.
The shift left approach makes proactive scanning a crucial element of IaC security strategy. However, reactive scanning is equally important to identify configuration drift or unauthorized changes. Even the best environments can experience situations where a production environment has drifted from the codified intent of IaC. Leveraging both proactive and reactive IaC tools ensures protection across the IaC development lifecycle.
IaC Security Beyond Terraform
Terraform has become synonymous with the Infrastructure as Code movement, but many other popular tools meet this need. OpenTofu is being widely adopted as a Terraform alternative. Cloud providers expose their own specific tooling. Examples include AWS CloudFormation (CFN), Azure Resource Manager (ARM), Microsoft Azure Bicep, and Google Cloud Platform Deployment Manager.
Even Kubernetes can be considered an Infrastructure as Code tool. Projects such as Crossplane extend Kubernetes to provide a control plane across infrastructure and application resources. The Kubernetes Cluster API special interest group extends Kubernetes to deploy additional Kubernetes clusters. The OperatorHub is also full of infrastructure-oriented operators that build upon the power of the Kubernetes control plane to deploy infrastructure resources.
A comprehensive security approach in a multi-cloud environment must consider the need to support the entirety of an organization’s IaC tools.
Ten Tools for Better IaC Security
This article discusses ten different tools for improving the security posture of your Infrastructure as Code:
- Open Policy Agent
- Tflint
- Trivy
- CloudSploit
- Checkov
- Snyk
- Kubescape
- Terrascan
- Prowler
- KICS
Open Policy Agent
Open Policy Agent (OPA) is more than a simple tool. It’s a declarative language for expressing policy as code using the Rego language. OPA runs against JSON inputs, so it supports proactive policy enforcement against any language that can be converted to JSON.
The Conftest project from OPA can run Rego queries directly against many configuration languages. It supports Terraform, Docker, Kubernetes, and many other languages. Conftest also includes direct support for YAML-based configuration files.
Unlike many of the tools in this list, OPA and Conftest do not include any default security policies for IaC scanning. Instead, OPA provides a framework to build custom policies. As you'll see, the OPA framework is integrated into many Infrastructure as Code tools discussed in this list.
Tflint
Tflint is a linter for Terraform configuration files. While linting isn’t strictly a security activity, following a language's best practices and avoiding deprecated language features are important elements of robust code. Tflint’s comprehensive rule set ensures that your infrastructure code follows language best practices.
Tflint offers a plugin-based architecture with support for writing custom plugins. It also supports adding custom rules using OPA.
Trivy
Trivy is a comprehensive vulnerability scanner from Aqua. The tfsec tool familiar to many infrastructure engineers is now integrated into Trivy. The Trivy team maintains vulnerability databases to address hundreds of vulnerabilities and misconfigurations.
Trivy is primarily a proactive tool that can scan a wide variety of configuration files, container images, and package formats. It features support for a variety of common IaC formats, including Terraform, Azure ARM, Azure Bicep, and AWS CloudFormation.
Trivy also has some support for reactive scanning of existing environments. Specifically, Trivy can connect directly to a Kubernetes cluster and scan it for misconfigurations.
Trivy can be extended via custom checks written in the OPA Rego language.
CloudSploit
CloudSploit is a reactive security project from Aqua that perfectly complements Trivy. It scans a cloud environment and detects security risks in running cloud infrastructure across multiple cloud providers. CloudSploit can even run remediative actions to automatically resolve an identified issue.
Reactive environment scanning is an important part of IaC's overall security strategy. While CloudSploit doesn’t directly scan IaC configuration files, regular scanning of the cloud environment itself can detect vulnerabilities introduced by configuration drift or malicious actors.
CloudSploit is extensible via custom plugins that directly make API calls to a cloud provider to interrogate the cloud configuration and identify misconfiguration.
Checkov
Checkov is a proactive scanning tool that emphasizes policy as code. It features support for Terraform, AWS CloudFormation, Azure ARM, Kubernetes (including Helm charts), Docker, and even Ansible.
Checkov includes hundreds of policies to meet compliance with the Center for Internet Security and AWS Foundations Benchmark standards. Using IaC is an excellent way to ensure compliance with security benchmarks in a repeatable way. Checkov can ensure that your IaC is actually meeting these benchmarks.
Checkov is also highly extensible, supporting custom policies in Python or YAML.
Snyk
Snyk is a cloud platform that provides proactive scanning across several common IaC formats. It supports scanning Terraform, AWS CloudFormation, Azure ARM, and Kubernetes file formats. Snyk offers a comprehensive database of vulnerabilities and common misconfigurations. It can also be extended through custom policies, including those written using OPA.
Snyk prides itself on a positive developer experience. Snyk’s integrations include IDE plugins and the ability to directly suggest fixes for misconfigurations while authoring IaC. The cloud platform also includes helpful dashboards to provide visibility into an organization’s IaC security posture.
Kubescape
Kubescape is a CNCF sandbox project that aims to embed security across the lifecycle of Kubernetes environments. Kubescape includes elements of proactive and reactive security. It is increasingly used as an IaC tool to directly deploy infrastructure workloads. Scanning Kubernetes manifests is paramount to ensure best practices.
Kubescape can proactively scan Kubernetes manifests and Helm charts for misconfigurations. It can also reactively scan existing Kubernetes clusters to find vulnerabilities, or it can be deployed as a Kubernetes Operator to provide regular scanning of cluster resources.
Kubescape uses Open Policy Agent under the hood, and it is extensible via custom policies written in Rego.
Terrascan
Terrascan is a tool used to scan IaC for security best practices. It features over 500 policies across a variety of clouds. Despite its name, Terrascan is not limited to Terraform files; it also supports AWS CloudFormation, Azure ARM, Kubernetes, Helm, and Docker.
Terrascan can run as a Kubernetes admission webhook to proactively deny misconfigurations from reaching a Kubernetes cluster. It supports custom policies through OPA.
Prowler
Prowler is a reactive security scanner that directly scans cloud infrastructure to identify misconfigurations and vulnerabilities. It features hundreds of checks across AWS, Azure, GCP, and Kubernetes. Pairing Prowler’s reactive approach with proactive scanning of IaC configuration files provides an enhanced security posture across the infrastructure lifecycle.
Prowler can be extended with custom checks through Python scripts. It includes Prowler Check Kreator, a utility to quickly build the scaffolding needed for custom checks.
Prowler shines with advanced reporting capabilities for security best practices. A comprehensive web UI provides a dashboard of a cloud environment’s security posture. Prowler can also forward its findings and logs to external services, such as AWS Security Hub, for further triage and analysis.
KICS
Keeping Infrastructure as Code Secure (KICS) is a comprehensive scanner that supports proactive scanning against over 20 configuration formats. The platform includes support for Terraform, Pulumi, Ansible, AWS CloudFormation, Azure ARM, Kubernetes, and many others.
The KICS query database includes hundreds of common misconfigurations and security vulnerabilities. The project also makes it very easy to write additional queries using OPA.
KICS’s unique architecture makes it highly extensible through plugins to parse additional IaC languages.
Four Questions for Choosing the Right Tools
We’ve covered ten Infrastructure as Code security tools, with their unique approach to securing IaC workflows and mitigating security risks. How do you decide on the right IaC tools for your organization?
Ask yourself these four questions when evaluating your IaC security toolchain:
- Does the tool support the Infrastructure as Code languages and configuration management tools that your organization currently uses and is planning to use in the future? This is particularly important to consider as many organizations adopt a multi-cloud approach.
- Does the tool's deployment model work for you, and can it be easily integrated into your existing developer workflows? The majority of the tools discussed in this article are easy to install and integrate into common workflows, such as CI/CD pipelines. However, some tools provide a better developer experience with robust IDE integrations.
- Does the tool support a proactive approach, a reactive approach, or both? One approach is not better than the other. Rather, a mature security posture includes tools that support the entire IaC development lifecycle.
- Finally, can the tool be extended using approaches that you are comfortable with? Many of the tools discussed in this article are extensible via Open Policy Agent, which is seeing broad industry adoption as the chosen framework for policy as code. However, some tools may require you to write custom plugins that must be designed and maintained.
IaC Security Tools and env0
env0 integrates security seamlessly across the Infrastructure as Code (IaC) lifecycle, empowering users to incorporate tools like Open Policy Agent (OPA), Checkov, TFLint, TFSec, and Trivy directly into their workflows. These integrations allow organizations to identify risks proactively and enforce compliance standards using tools tailored to their needs.
In addition, env0 ensures robust protection through granular access controls, including Role-Based Access Control (RBAC), for precise permission management. Features such as encrypted state files and secure secret management further safeguard sensitive data. Together, these capabilities provide a comprehensive security framework, enabling organizations to confidently manage and protect their IaC environments.
Final Thoughts
Securing the IaC development lifecycle involves shifting left and integrating security tools earlier in the development process. This proactive approach, exemplified by many of the tools in this article, embeds security best practices in the Infrastructure as Code development lifecycle. This strategy mitigates security risks and compliance violations by preventing them from ever reaching production environments.
On the other hand, a reactive approach to scanning existing cloud environments is equally important. Regular scanning of cloud resources for security vulnerabilities can catch configuration drift, identify unauthorized changes, and notice deprecated configurations that may have been created in the past.
A combination of proactive and reactive scanning is important when designing an IaC security strategy.