← Writing

2026 · By Somesh Motupally · 4 min read

Policy-as-Code Gates: Blocking Bad Deploys Before They Ship

Kubernetes OPA Kyverno Supply Chain Security

The problem

Security policy at most organizations lives in a document. "Containers must not run as root." "Images must come from an approved registry." "No privileged containers in production." These rules get written once, reviewed in an audit, and then quietly ignored — because nothing in the deployment path actually checks for them. A misconfigured manifest that violates every rule in the document will deploy exactly as successfully as one that follows all of them.

We hit this directly: a security review found containers running as root, some with privileged access they didn't need, and images pulled from registries nobody had explicitly approved. None of this was malicious — it was just what happens when policy exists as prose instead of as something the pipeline actually enforces. By the time these findings surfaced, the workloads were already live.

Why manual review wasn't enough

The instinctive fix — add a manual security review step before production deploys — didn't scale and didn't match how the org actually shipped software. Reviewers became a bottleneck, review quality varied by who was on call, and the whole model depended on a human catching a YAML misconfiguration by eye, every time, under time pressure. We needed the check to happen automatically, consistently, and early enough that failing it was cheap — a rejected pull request, not an incident report.

The solution: policy gates with OPA and Kyverno

We built a layered policy enforcement setup using Open Policy Agent (OPA) for CI-time checks against Infrastructure-as-Code, and Kyverno as an admission controller enforcing the same intent at the Kubernetes cluster level — so a violation is caught whichever way it tries to reach production.

The policies we enforced were deliberately the highest-leverage ones first:

OPA runs earlier — against Terraform plans and Kubernetes manifests in CI, using Conftest — so violations get caught in a pull request with a clear, specific failure message before anything is ever applied. Kyverno acts as the backstop at the cluster's admission controller, so even a change that bypasses CI (a manual kubectl apply, a hotfix, a misconfigured pipeline elsewhere) still can't land a non-compliant workload. Neither layer alone was sufficient; together they close the gap between "policy that's written" and "policy that's actually true in production."

Results

Lessons learned

What's next

We're extending the policy set to cover network policy enforcement (default-deny with explicit allow rules) and tightening the signature verification requirement to include provenance attestation (SLSA-style build provenance), not just a valid signature — moving from "this image wasn't tampered with" to "this image was built by the pipeline we expect, from the source we expect."


If you're building out policy-as-code enforcement with OPA, Kyverno, or a similar stack, I'd like to hear how you're approaching exception handling — get in touch.