Policy as code (PaC) is the practice of writing security, compliance and infrastructure policies as code so that systems can enforce, test and audit them automatically. Instead of a rule living in a document that someone has to read and apply, the rule lives in a file that a policy engine applies the same way every time.
Policies written as code integrate directly with IT infrastructure management, so enforcement, validation and auditing of policies happen automatically. With PaC, organizations can hold every environment to the same standards and regulations without a manual review step.
PaC replaces manual review and enforcement with automated, systematic policy application. That reduces human error, strengthens security compliance and gives IT a record of what each policy said and when it was applied.
Policy as code is only as good as the language it's written in. These three matter most today, and they solve different problems:
Cedar
Cedar is an open-source, declarative authorization language and evaluation engine. Policies define principals, actions, resources and context, and then engine returns an allow or deny decision in milliseconds. It supports role-based and attribute-based models, with relationship-based patterns built on top. Formal verification means a policy's effects can be proven rather than just tested. Cedar is also a Cloud Native Computing Foundation (CNCF) project adopted by Cloudfare, MongoDB and AWS.
Best for: fast, fine-grained decisions on individual requests, where teams need to know exactly what a policy allows.
Open Policy Agent (OPA) and Rego
OPA is a CNCF graduated project and the most widely deployed general-purpose policy engine. Its language, Rego, evaluates structured data (JSON, YAML, API payloads) against rules, so one engine can gate Kubernetes admission, evaluate Terraform plans in CI, authorize an API call or check a config file. OPA comes with a steeper learning curve than Cedar without the same formal guarantees.
Best for: a single policy engine across many inputs and enforcement points.
OpenFGA
Open FGA is a CNCF project that implements relationship-based authorization, modeled on the system Google built for Docs and Drive. It uses a modeling language rather than a standalone policy language, but it answers a question the other two struggle with: who can reach a specific object, and through what chain of relationships.
Best for: permissions that follow a graph, such as document owners, nested folders or team hierarchies.
Moving to a PaC model requires a structured approach:
How Policy-based Access Control Improves Agility and Security
StrongDM Brings Continuous Authorization to the Delinea Platform
The Access Control Paradigm: Unpacking ABAC, PBAC & RBAC