Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Policy as Code · Compliance Automation

Direct answer

Policy as code writes compliance and security rules as code, with tools like Open Policy Agent (Rego), Sentinel or Kyverno, so policies are versioned, tested and enforced automatically in pipelines.

When to use this

Use this when writing compliance rules as code.

First 30 seconds

1. Policy as code enforces rules in CI and at runtime.

2. Tested policies.

3. Clear messages.

4. Exceptions as code.

5. Version control.

Operational verification

change → policy evaluation → allow/deny

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
policy-as-code and compliance automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformpolicy-as-code and compliance automation · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when writing compliance rules as code.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

The negative fixture should deliberately exercise risks such as stale policy, incomplete input, exception creep, false compliance from missing data, destructive auto-remediation and passing policy check without validating actual target, choosing the cases most relevant to versioned policy bundle, deterministic input, rule decision/violations, exceptions and re-evaluation after remediation.

Step 2 Common mistakes Narrow the fault
  • Policies without tests.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • OPA/Rego, Sentinel, Kyverno.
  • Test policies like code.
  • Enforce in pipelines.
Key checks
  • opa eval / conftest test — OPA policies
  • Kyverno/Gatekeeper policies (Kubernetes) — admission
  • Sentinel/OPA on Terraform plans — IaC
ReferenceWhy it matters1 section · depth on demand

What it is

Policy as code expresses rules as testable code (OPA/Rego, Batfish checks, Ansible asserts) run in CI.

ReferenceImportant terms & boundaries1 section · depth on demand

In depth

Policy as code expresses compliance and security rules in machine-readable form, stored in Git, tested and evaluated automatically against configurations, infrastructure plans or live systems. Rules become consistent, versioned and reviewable instead of living in documents.

ToolEvaluates
Open Policy Agent / ConftestJSON/YAML: Terraform plans, Kubernetes manifests, configs
KyvernoKubernetes resources at admission
Checkov, tfsec/TrivyIaC security
BatfishNetwork configurations and reachability
SentinelTerraform Cloud/Enterprise plans
package network
deny[msg] {
  some i
  input.interfaces[i].mode == "access"
  not input.interfaces[i].bpduguard
  msg := sprintf("%s: access port without BPDU Guard", [input.interfaces[i].name])
}

Run policies in CI before changes are applied, and against live state on a schedule.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docpolicy-as-code and compliance automation current

Authoritative/upstream documentation reviewed for bounded claims in Compliance Automation > Policy as Code. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.openpolicyagent.org/docs/latest/ · confidence 94%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For versioned policy bundle, deterministic input, rule decision/violations, exceptions and re-evaluation after remediation, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?