Treat policy as versioned, testable release logic. Run checks before deployment; enforce critical invariants at the runtime boundary.
| Boundary | Control | Operational rule |
|---|---|---|
| Source / CI | OPA + Conftest on YAML, JSON or Terraform plans | Block noncompliant changes; return actionable failures |
| Deployment | IaC validation and environment gates | Validate rendered artifacts, not only source templates |
| Kubernetes admission | Native ValidatingAdmissionPolicy (CEL) or Gatekeeper | Enforce on create/update; scope bindings and exclusions explicitly |
| Running estate | Gatekeeper audit / scheduled drift scans | Detect existing violations; admission alone does not remediate drift |
# policy/ contains Rego rules; manifests/ contains rendered YAML
conftest test manifests/ --policy policy/
if ($LASTEXITCODE -ne 0) { throw "Policy validation failed" }
conftest test manifests/ --policy policy/
Example Rego v1 policy (policy/labels.rego):
package main
import rego.v1
deny contains msg if {
input.kind == "Deployment"
not input.metadata.labels["owner"]
msg := "Deployment requires metadata.labels.owner"
}