Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Policy as Code?

Policy as code means writing organisational rules in a machine-readable form that lives in version control, is tested like software, and is enforced automatically at the points where decisions are made.

Illustration for the cybersecurity term Policy as Code
Home / Blog / Cybersecurity Terms / What Is Policy as Code?
17 November 2026

What Is Policy as Code?

What Is Policy as Code?

Policy as code is the practice of expressing organisational rules — security standards, compliance requirements, architectural constraints — in files that a machine evaluates, rather than in documents that a human is supposed to have read. The rules live in a repository, go through review, carry tests, and are enforced automatically wherever a relevant decision is made.

The shift is from “our standard says storage buckets must be encrypted” to a rule that refuses to create one that is not.

Why Written Standards Fail

A configuration standard in a wiki has three predictable problems. Nobody reads it at the moment they need it. It drifts from what is actually deployed within weeks. And verifying compliance means a person manually comparing a document to an environment, which happens annually at best and is wrong by the time it is finished.

Encoding the same rule gives you three things the document never could: it applies to every change rather than the ones someone checked, it is versioned so you can see when and why it changed, and the enforcement record is evidence. Most security misconfigurations in cloud environments are violations of a rule the organisation had already written down somewhere.

Where the Rules Are Enforced

The same requirement usually needs expressing at more than one point, because each point catches a different mistake.

PointTypical mechanismCatches
Developer machinePre-commit hookObvious mistakes, secrets, before they are shared
Pull requestIaC scanner, Conftest, custom rulesMisconfiguration in proposed change, with review context
Before applyTerraform plan evaluation, SentinelResolved values that source files cannot show
AdmissionKyverno, Gatekeeper, Validating Admission PolicyAnything deployed by any route, including manually
RuntimePosture management, cloud guardrails such as SCPsDrift, console changes, resources created outside the pipeline

A rule enforced only in continuous integration is bypassed by anyone with console access. A rule enforced only at admission gives developers no feedback until deployment. The combination of an early advisory check and a late blocking one is what works.

The Engines

Open Policy Agent with Rego is the general-purpose option, used through Gatekeeper in Kubernetes and Conftest in pipelines. Kyverno keeps Kubernetes policy in YAML. HashiCorp Sentinel gates Terraform runs in the commercial editions. AWS service control policies and Azure Policy enforce at the cloud control plane, where nothing can route around them. Infrastructure scanners such as Checkov and KICS allow custom rules of their own.

The choice matters less than consistency. Three engines with three languages and three exception processes is a common and avoidable outcome of letting each team pick separately.

Making It Survive Contact With Delivery

Compliance Benefit

Auditors increasingly ask how a control is enforced rather than whether it is documented. For ISO 27001:2022, control A.8.9 covers configuration management, and a policy repository with a decision log answers it far better than a narrative. Cyber Essentials requires secure configuration across devices and services, and the NCSC’s cloud security principles expect separation and configuration to be demonstrable. For financial entities under DORA, evidence that ICT changes are checked against defined requirements before deployment is directly in scope.

The reporting side also improves: policy engines emit machine-readable results, so “which workloads violate which control today” becomes a query rather than a project.

FAQ – Frequently Asked Questions

Is Policy as Code the Same as Infrastructure as Code?

No, though they work together. Infrastructure as code describes what you want to exist. Policy as code describes what is permitted to exist. One is a specification, the other a constraint on all specifications. Policies are usually evaluated against infrastructure code, but they also apply to running resources, API requests, pipeline artefacts, and anything else where a rule should be enforced automatically.

Which Policy Engine Should We Choose?

If Kubernetes is the main enforcement point and application teams will write the rules, Kyverno’s YAML approach is quicker to adopt. If you need one language across Kubernetes, pipelines, and service authorisation, Open Policy Agent with Rego is the stronger foundation despite the learning curve. Cloud-native guardrails such as service control policies should be used regardless, because nothing can bypass them.

How Do We Handle Legitimate Exceptions?

Build the exception process before you start enforcing. Each exemption should name an owner, state the reason, and carry an expiry date, and it should live next to the resource it applies to rather than in a pipeline configuration nobody reads. Review expiring exceptions on a schedule. Without this, teams invent bypasses that are invisible to everyone including you.

Will This Slow Down Our Developers?

Badly implemented, yes. The usual causes are enforcing from day one rather than auditing first, error messages that do not say how to comply, and no route to an exception. Done well it does the opposite, because the answer to what is allowed is immediate and automatic instead of waiting for a security review. Measure how long a policy failure takes to resolve, and fix the rules that score worst.

Related Terms

You May Be Interested In These

What Is the Sysinternals Suite?

Cybersecurity Terms

17 November 2026

What Is the Sysinternals Suite?

Read More
What Is Smart Grid Security?

Cybersecurity Terms

17 November 2026

What Is Smart Grid Security?

Read More
What Is Ransomware?

Cybersecurity Terms

17 November 2026

What Is Ransomware?

Read More