5 Steps to Securing Infrastructure as Code with Policy as Code Frameworks
April 25, 2024

Dotan Nahum
Check Point Software Technologies

Remember that troublesome Terraform misconfiguration that leaked sensitive keys?

Security incidents like that are the stuff of developer nightmares.

Safeguarding our Infrastructure as Code (IaC) becomes a non-negotiable part of the DevSecOps game. Policy as Code (PaC) steps in to assist us in staying ahead of the curve with the sheer volume of IaC templates, scripts, and modules. To help you understand how to marry the two, here are five steps to securing IaC with PaC.

Step 1: Understand the Changing IaC Threat Landscape

IaC has undeniably streamlined provisioning and deployment, but it's a double-edged sword. Configuration errors were once tedious manual mistakes and now have the potential to scale at a terrifying pace through automation. Hardcoded secrets within IaC templates can quickly end up in public repositories or get accidentally shared during collaboration. Overly permissive IAM roles defined in IaC grant attackers undue access if compromised, opening lateral movement paths for attackers.

Malicious actors can target your IaC tooling itself. Think zero-day vulnerabilities in popular IaC frameworks or supply chain attacks where compromised third-party modules slip into your trusted codebase. To combat this, developers and DevOps teams need to go beyond understanding individual misconfigurations, shifting their focus to the broader patterns and systemic risks that IaC introduces.

Step 2: Embrace the Shift-Left Mentality with PaC

Shift-left security is vital because the earlier we address vulnerabilities, the less costly and disruptive they become. PaC fully embodies this philosophy by seamlessly integrating security into the very act of defining your infrastructure. Compliance requirements and best practices become a codified extension of your IaC.

Traditionally, IaC undergoes scans and audits after being written. PaC flips this model. By embedding policy checks directly into CI/CD pipelines, developers get near-instant feedback on whether new infrastructure changes adhere to your security standards. Predefined policies analyze IaC for risky configurations like overly permissive networking or unencrypted data stores. This feature empowers developers to fix potential security problems at the design stage, not when frantic alerts go off in production.

Step 3: Choose Your PaC Strategy with Technical Considerations

A PaC strategy requires a careful analysis of your organization's specific needs, resources, and level of customization. For example, general-purpose languages like Python, coupled with libraries like PyTerraform, Terraform-compliance, or various cloud provider SDKs (like AWS), provide exceptional flexibility. You can tailor checks to even the most nuanced risk scenarios and complex infrastructure designs. However, be aware that this path burdens development expertise more.

Alternatively, Domain-Specific Languages like Open Policy Agent's Rego offer a solution designed explicitly for authoring and managing policies. Rego's declarative syntax lets you define rules in a way that closely resembles plain-language security requirements. The active OPA community often provides a rich repository of pre-written policies, streamlining your initial setup. Tools like Styrakos with visual interfaces extend PaC accessibility to less code-savvy team members.

Embedded frameworks like Checkov, Terrascan, or tfsec prioritize developer experience and rapid integration into existing IaC workflows. These tools boast vast libraries of pre-built checks aligned with industry benchmarks and cloud security best practices. The trade-off is that while they reduce initial time investment, extensive customization might be more limited compared to a full-fledged, general-purpose programming language approach.

Step 4: Define Your Policies with Precision

Industry-standard benchmarks like those provided by the Center for Internet Security (CIS) or OWASP offer a solid foundation for your PaC policies – but you should tailor them to mirror your organization's risk profile. Begin by pinpointing your most important assets, such as the infrastructure components containing your most sensitive data or critical business logic. Simultaneously, consider the regulatory landscape relevant to your industry. PCI DSS for payment processing, HIPAA for healthcare, or SOC 2 for SaaS providers will shape your policy requirements.

For example, enforcing comprehensive resource tagging might seem mundane, but it's a cornerstone of cost control and security incident response. Another valuable policy could restrict the range of EC2 instance types developers can launch. Policies like this prevent accidental resource over-provisioning and reduce the potential attack surface. PaC policies can also forbid hardcoding credentials and secrets in IaC templates, instead mandating dedicated secrets management solutions like AWS Secrets Manager or HashiCorp Vault.

Step 5: Automate, Automate, Automate

The heart of PaC lies in relentlessly automating away manual security checks. Embed policy evaluations seamlessly into your existing CI/CD pipelines for maximum value. Every pull request proposing an IaC change should automatically trigger validation against your meticulously defined rules. Tools like Jenkins X coupled with OPA Gatekeeper offer excellent integration capabilities. Configuring Gatekeeper as an admission controller enforces your policies at the Kubernetes level, preventing misconfigured deployments from reaching your clusters. Similarly, Terraform Cloud with Sentinel allows you to define pre-run policy checks, ensuring compliance even before infrastructure changes are applied.

A genuinely robust implementation goes beyond just pipeline enforcement. Consider complementing your CI/CD safeguards with IaC testing frameworks like Terratest or Kitchen-Terraform. Paired with a tool like Checkov, you can write tests that verify the syntactical correctness of your IaC and its adherence to your security policies.

The Future of IaC is Secure

IaC and PaC are a powerful combo. Treating security as code allows you to gain agility without sacrificing peace of mind. Of course, tools are only part of the equation. Fostering a DevSecOps culture where security is everyone's responsibility is the real key to long-term success.

Dotan Nahum is Head of Developer-First Security at Check Point Software Technologies
Share this

Industry News

October 17, 2024

Progress announced the latest release of Progress® Flowmon®, the network observability platform with AI-powered detection for cyberthreats, anomalies and fast access to actionable insights for greater network and application performance across hybrid cloud ecosystems.

October 17, 2024

Mirantis announced the release of Mirantis OpenStack for Kubernetes (MOSK) 24.3, which delivers enterprise-ready and fully supported OpenStack Caracal, featuring enhancements tailored for artificial intelligence (AI) and high-performance computing (HPC).

October 17, 2024

StreamNative announced a managed Apache Flink BYOC product offering will be available to StreamNative customers in private preview.

October 17, 2024

Gluware announced a series of new offerings and capabilities that will help network engineers, operators and automation developers deliver network security, AI-readiness, and performance assurance better, faster and more affordably, using flawless intent-based intelligent network automation.

October 17, 2024

Sonar released SonarQube 10.7 with AI-driven features and expanded support for new and existing languages and frameworks.

October 16, 2024

Red Hat announced a collaboration with Lenovo to deliver Red Hat Enterprise Linux AI (RHEL AI) on Lenovo ThinkSystem SR675 V3 servers.

October 16, 2024

mabl announced the general availability of GenAI Assertions.

October 16, 2024

Amplitude announced Web Experimentation – a new product that makes it easy for product managers, marketers, and growth leaders to A/B test and personalize web experiences.

October 16, 2024

Resourcely released a free tier of its tool for configuring and deploying cloud resources.

October 15, 2024

The Cloud Native Computing Foundation® (CNCF®), which builds sustainable ecosystems for cloud native software, announced the graduation of KubeEdge.

October 15, 2024

Perforce Software announced its AI-driven strategy, covering four AI-driven pillars across the testing lifecycle: test creation, execution, analysis and maintenance, across all main environments: web, mobile and packaged applications.

October 15, 2024

OutSystems announced Mentor, a full software development lifecycle (SDLC) digital worker, enabling app generation, delivery, and monitoring, all powered by low-code and GenAI.

October 15, 2024

Azul introduced its Java Performance Engineering Lab, which collaborates with global Java developers and customers’ technical teams to deliver enhanced Java performance through continuous benchmarking, code modernization recommendations and in-depth analysis of performance impacts from new OpenJDK releases.

October 10, 2024

AWS has added support for Valkey 7.2 on Amazon ElastiCache and Amazon MemoryDB, a fully managed in-memory services.

October 10, 2024

MineOS announced a major upgrade: Data Subject Request Management (DSR) 2.0.