Insights · Security Architecture
Policy as code: compliance you can run in the pipeline
Turn compliance rules into code enforced at the pipeline and admission: deny on drift, generate audit evidence from the same rules.
Every regulated estate runs two systems: the system it operates, and the system it claims to operate — a wall of spreadsheets, screenshots and sign-offs that ages the moment it is written. Policy as code collapses the distance between the two. The definition now standard in the literature: encoding “security and compliance policies into machine-readable formats” so they can be evaluated automatically against infrastructure and applications (Romeo et al., arXiv 2025). An empirical study of 399 open-source projects (Foalem, Khomh, Da Silva & Merlo, arXiv 2026) calls it “a foundational approach for embedding governance, compliance, and security requirements directly into software systems” — and documents its adoption across nine tools. This article is the directional version: how to stand it up so auditors and engineers both win.
The decision/enforcement split
The architectural move behind all of this is old and good: separate deciding from enforcing. The Open Policy Agent documentation states it as the design goal — a “general-purpose policy engine that unifies policy enforcement across the stack”, with a declarative language (Rego) that lets you “specify policy as code” and “decouples policy decision-making from policy enforcement.” The same policy library can then decide admission for Kubernetes, Terraform plan approval in CI, and API authorization at the edge — one body of rules, one review process, one audit trail.
In Kubernetes specifically, enforcement lives at admission — the moment an object would enter the cluster. Two mainstream options:
- Native admission policy. The ValidatingAdmissionPolicy API — “a declarative, in-process alternative to validating admission webhooks” using the CEL expression language, generally available since v1.30, with Deny/Warn/Audit actions. No extra component; the policy ships with the cluster’s own control plane.
- A policy engine. Kyverno — “a cloud native policy engine” that can “validate, mutate, generate, or cleanup any Kubernetes resource” and verify container image signatures — with policies written as ordinary Kubernetes resources managed in git, no new language to learn.
The choice is less about features than about where the policy estate should live: native CEL for cluster-local rules with zero operational overhead; OPA or Kyverno when the same policies must also govern CI, IaC, and other platforms.
The same pattern, natively, in each cloud
The public clouds converged on the model independently, which is evidence of a pattern rather than a fashion:
- Azure Policy evaluates resources against JSON business-rule definitions with deny/audit/modify effects, re-evaluates compliance on a 24-hour cycle, supports bulk and automatic remediation — and explicitly recommends managing policy definitions as code.
- AWS service control policies provide “central control over the maximum available permissions” across an organization — with the guardrail caveat that “an SCP never grants permissions”; it only bounds what identity policies can allow.
- Google Cloud Organization Policy applies “centralized and programmatic control” through constraints enforced down the organization/folder/project hierarchy.
Govern the cloud-native policies the same way you govern your own: definitions in version control, changes through pull requests, drift alerts when someone edits a guardrail by hand.
Map checks to the frameworks auditors cite
The difference between “we have some policies” and “we have a compliance program” is traceability. Two anchors do most of the work:
- NIST SSDF (SP 800-218). The Secure Software Development Framework is “a core set of high-level secure software development practices” organized into four groups — Prepare the Organization (PO), Protect the Software (PS), Produce Well-Secured Software (PW), Respond to Vulnerabilities (RV). Each pipeline gate maps to a practice; the framework exists precisely to give suppliers and purchasers “a common vocabulary” for secure development. When an auditor asks how a requirement is met, the answer is a control ID, a policy file, and a passing check.
- CIS Benchmarks. The consensus configuration baselines (100+ guides across 25+ product families, including AWS, Azure, GCP and Kubernetes) give your admission rules and IaC checks concrete, recognized targets: run as non-root, no privileged pods, encryption on, ports closed.
For the evidence layer, NIST’s OSCAL expresses controls, implementations and findings in “open, machine-readable formats in XML, JSON, and YAML” — with the stated ambition that automation can cut audit timelines from months to minutes. Emitting OSCAL-shaped evidence from your pipeline turns the quarterly evidence hunt into a query.
The five gates that matter first
Direction, not exhaustive: start the pipeline gates whose violation is most expensive, and grow deliberately.
- IaC admission check. Every Terraform/CloudFormation change is policy-evaluated in CI before plan applies — public buckets, unencrypted volumes, open security groups fail the build.
- Container admission. Non-root user, no privilege escalation, signed images, from approved registries — enforced in-cluster, so a bypassed pipeline still fails at the door.
- Secrets hygiene. No literals in code or IaC; secret references resolve to the vault (the secrets management companion article covers the runtime side).
- Network posture. Default-deny policies must exist per namespace; any allow-all fails review.
- Change governance. Deploys to regulated environments require the recorded approvals — checked by the pipeline, not by the honor system.
Three ways policy as code goes wrong
- Audit-only mode. If everything is “audit” and nothing is “deny”, the code is a report generator, not a control. Enforce the ones that protect integrity; audit the exploratory ones; promote deliberately.
- The policy monolith. One global rulebook for every team produces rule-dodging, not compliance. Version policies, own them like software, and let teams propose changes through the same pull-request process the code uses.
- Drift blind spots. Policies checked only at deploy miss out-of-band change. Continuous evaluation (cloud-native cycles or scheduled scans) closes the gap between what you wrote and what is running.
Done this way, policy as code is the connective tissue between the decisions you record and the estate you operate: the ADR says non-root is the law; the admission policy is what makes it true at 3 a.m. when nobody is watching.
Put your compliance in the pipeline
Sources
- Open Policy Agent documentation — policy as code, Rego, decision/enforcement decoupling
- Kubernetes documentation, “ValidatingAdmissionPolicy” (CEL-based native admission control)
- Kyverno documentation — cloud-native policy engine
- NIST SP 800-218, “Secure Software Development Framework (SSDF) v1.1” (2022)
- NIST SSDF project page — practice groups and structure
- Center for Internet Security, “CIS Benchmarks”
- NIST OSCAL — Open Security Controls Assessment Language
- Microsoft, “Azure Policy overview”
- AWS, “Service control policies (SCPs)” — AWS Organizations User Guide
- Google Cloud, “Organization Policy Service overview”
- Foalem, Khomh, Da Silva & Merlo, “An Empirical Study of Policy-as-Code Adoption in Open-Source Software Projects” (arXiv, 2026)
- Romeo et al., “ARPaCCino: An Agentic-RAG for Policy as Code Compliance” (arXiv, 2025)