Resources Infrastructure

Top Policy as Code Tools for Modern Cloud Governance

Compare the leading policy as code tools for DevSecOps and cloud platforms, from general-purpose engines like OPA to IaC scanners, and how to run them in pipelines.

TL;DR — The main policy as code tools are Open Policy Agent for general-purpose rules, Kyverno for Kubernetes admission, HashiCorp Sentinel for HCP Terraform, and Checkov and Trivy for scanning IaC before deployment. Kestra runs these engines as gates inside provisioning and deployment workflows, with approvals and a log of every run.

The faster pipelines and AI coding agents produce infrastructure code, the harder it is to review every change by hand. Manual reviews either slow delivery down or miss the exposed bucket, the missing tag, or the overly broad role.

The leading policy as code tools are Open Policy Agent (OPA), Kyverno, HashiCorp Sentinel, Checkov, and Trivy. They work at different points: before commit, in CI, at Kubernetes admission, or inside a vendor platform. This guide compares them and shows how Kestra runs them as gates in a delivery workflow. For the concept itself, see what policy as code is.

Why platform teams need policy as code tools

Rules written in a wiki do not stop a misconfiguration from reaching production. Three pressures make automated enforcement necessary:

  1. Drift and compliance: open security groups, unencrypted volumes, and missing cost tags slip through pull requests. Frameworks such as SOC 2, HIPAA, and DORA expect controls that can be shown to run on every change.
  2. AI-generated infrastructure code: coding agents write IaC quickly but know nothing about internal security boundaries. A deterministic check in the pipeline applies the same rules to generated and human-written code.
  3. Security out of the delivery loop: reviews that happen outside the pipeline turn security into a bottleneck. Rules kept as versioned files, as part of an everything as code approach, run on every commit and deployment.

Static checks vs runtime enforcement

Policy checks run at two moments. Static checks read files before anything exists: Terraform code, a JSON plan, a Kubernetes manifest in a pull request. They are cheap and give feedback early, but they only see what is in the repository. Runtime enforcement evaluates requests as they reach a live system, such as the Kubernetes API server, so it also catches changes made outside the pipeline, by a kubectl apply from a laptop or a controller. Most teams need both: static checks to keep pull requests clean, and an admission barrier for whatever bypasses them.

How we evaluated these tools

  • Language: a dedicated language (Rego, Sentinel), Kubernetes YAML, or built-in checks.
  • Where it enforces: static files, CI, Kubernetes admission, or a vendor run.
  • Maturity: foundation or vendor backing and community size.
  • License: open source or commercial.
  • Fit in workflows: how cleanly it runs as a step with approvals and remediation around it.

1. Kestra

Kestra is an open-source, declarative orchestration platform for data, infrastructure, and AI workflows, written in YAML. Kestra is not a policy engine: it runs the engines (OPA, Checkov, Trivy) as steps of provisioning and deployment workflows, with approvals and an audit trail around them.

A typical gate plans the change with Terraform, evaluates the plan with OPA, stops the run on a violation, waits for an approval when a rule raises a warning, and only then applies. Kestra Enterprise adds controls on the orchestrator itself: RBAC, audit logs, and allowlists that restrict which plugins can run.

  • Advantages: one versioned pipeline as code definition covers provisioning, scans, and approvals; the Pause task holds high-risk steps until someone approves; every run keeps its logs and outputs.
  • Trade-offs: policy checks run in containers, which adds startup time compared with an engine embedded in-process. Teams that only need to evaluate JSON inside an application should call OPA directly.

Best for: platform teams that want IaC runs, policy gates, approvals, and audit trails in one workflow. See infrastructure automation with Kestra.

2. Open Policy Agent (OPA)

Open Policy Agent is an open-source, general-purpose policy engine and a graduated CNCF project. It decouples policy decisions from enforcement: a caller sends a JSON input, OPA evaluates it against Rego rules, and returns a decision such as allow, deny, or a list of violations. The caller enforces it.

  • Advantages: the same rules apply to Terraform plans, Kubernetes (through OPA Gatekeeper), Envoy, and internal APIs; OPA is a small Go binary that can also compile policies to WebAssembly; conftest and the regal linter cover testing and style.
  • Trade-offs: Rego takes time to learn for engineers used to imperative languages, and teams must distribute policy bundles to every agent. OPA’s bundle API and a central bundle server, or the built-in decision logs shipped to a collector, are the usual answers once more than a few services query it.

Best for: one set of rules across infrastructure code, APIs, and Kubernetes. See orchestrating OPA for pipeline patterns.

3. Kyverno

Kyverno is a Kubernetes-native policy engine and a graduated CNCF project. Policies are Kubernetes resources written in YAML. As an admission controller, Kyverno can validate, mutate (for example, add default labels), generate (for example, a default NetworkPolicy for each new namespace), and clean up resources.

  • Advantages: no new language to learn; mutation and generation go beyond blocking; built-in verification of image signatures and attestations with Sigstore; an Audit mode reports violations on existing resources before a policy is switched to Enforce, which makes rollouts safer.
  • Trade-offs: admission control is Kubernetes-only. The separate kyverno-json project applies the same policy style to other JSON, such as Terraform plans, but there is no admission hook outside Kubernetes.

Best for: Kubernetes-centric teams enforcing pod security and image signatures. See the Kyverno audit-to-enforce blueprint.

4. HashiCorp Sentinel

HashiCorp Sentinel is a policy framework embedded in HashiCorp’s commercial products: HCP Terraform, Terraform Enterprise, Vault, and Nomad. In HCP Terraform, Sentinel runs between plan and apply and inspects the planned changes.

  • Advantages: three enforcement levels (advisory, soft-mandatory with administrator override, hard-mandatory); direct access to Terraform run data without extra parsing.
  • Trade-offs: proprietary and only available inside HashiCorp products; policies do not carry over to Kubernetes admission or other platforms. See HCP Terraform alternatives for other options.

Best for: organizations already standardized on HCP Terraform and Vault.

Ready to orchestrate your infrastructure?

5. Checkov

Checkov is an open-source static analysis tool for IaC, developed by Bridgecrew (Palo Alto Networks). It scans Terraform, CloudFormation, ARM templates, Kubernetes manifests, and Dockerfiles against built-in checks mapped to benchmarks such as CIS, and runs from the CLI, a pre-commit hook, or CI.

  • Advantages: useful immediately, with no policies to write; graph-based checks catch risks across connected resources, such as a public security group attached to an unencrypted database; findings point to the exact line. Custom checks can be added in Python or YAML when the built-in ones do not cover an internal rule, and individual checks can be skipped with an inline comment that documents why.
  • Trade-offs: it only sees files as written; it cannot check live resources or block anything at runtime.

Best for: catching misconfigurations in pull requests before anything is provisioned.

6. Trivy

Trivy is an open-source scanner from Aqua Security. It covers container vulnerabilities, language dependencies, secrets, licenses, and IaC misconfigurations, with built-in checks and custom Rego rules. It ships as a single binary and can run in Kubernetes through the Trivy Operator.

  • Advantages: one tool for images and infrastructure code; custom IaC rules in the same Rego as OPA, so a team that already writes OPA policies can reuse them; quick to add to CI, with output formats such as SARIF that code-scanning dashboards can read.
  • Trade-offs: it reports findings and fails builds, but does not block admission, mutate resources, or manage approvals.

Best for: CI pipelines that scan both images and IaC.

Comparison of policy as code tools

ToolCategoryLicenseScopeLanguageKubernetes admissionPricing model
KestraOrchestration (runs the engines)Apache 2.0 (Core), commercial (Enterprise)Pipelines, IaC, APIs, KubernetesYAMLNo, orchestrates gatesFree open source; usage-based Cloud; instance-based Enterprise
OPAGeneral-purpose engineApache 2.0Kubernetes, APIs, Envoy, IaCRegoYes, via GatekeeperFree open source
KyvernoKubernetes engineApache 2.0Kubernetes resources, image signaturesKubernetes YAMLYes, nativeFree open source
SentinelEmbedded frameworkProprietaryHCP Terraform, Vault, NomadSentinel languageNoPart of HashiCorp commercial tiers
CheckovStatic IaC scannerApache 2.0Terraform, CloudFormation, Kubernetes, DockerfilesBuilt-in checks, Python or YAML customNoFree open source; commercial platform
TrivySecurity scannerApache 2.0Images, IaC, secrets, SBOMBuilt-in checks, Rego customNo (operator scans clusters, does not block)Free open source

How to choose the right policy as code tool

The right tool depends on where a rule must be enforced. In every case, Kestra is how the checks run inside the delivery workflow, with approvals and a log of each decision.

  • Data engineering teams: rules on encryption, data residency, and access settings. Run OPA checks on Terraform plans from the same Kestra flows that provision warehouses and run migrations. See data orchestration.
  • Infrastructure and platform teams: layer the tools. Checkov or Trivy in pull requests, Kestra running plan, OPA check, approval, and apply for every environment, and Kyverno or OPA Gatekeeper as the last barrier at Kubernetes admission.
  • Teams adopting AI coding agents: when an agent opens a change, a Kestra flow evaluates the generated plan with OPA and holds changes to critical resources, such as production firewalls, for a human approval. See AI automation.
  • Small teams getting started: Checkov in pre-commit and CI gives fast feedback with no policies to write; open-source Kestra adds scheduled audit scans and the approval step when deployments grow.

Orchestrating policy as code gates with Kestra

The flow below plans a Terraform change, evaluates the JSON plan with OPA, and fails the run if a deny rule matches. If a warn rule matches, it waits up to four hours for an approval; without one, the execution is cancelled and nothing is applied.

id: terraform-opa-governance-gate
namespace: company.platform
description: Plan with Terraform, check the plan with OPA, apply only after approval when a rule warns.
tasks:
- id: terraform_plan
type: io.kestra.plugin.scripts.shell.Commands
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: hashicorp/terraform:1.9
inputFiles:
main.tf: |
resource "local_file" "environment_config" {
content = "environment=production"
filename = "env_config.txt"
}
commands:
- terraform init -input=false
- terraform plan -input=false -out=tfplan
- terraform show -json tfplan > plan.json
outputFiles:
- plan.json
- tfplan
- id: opa_check
type: io.kestra.plugin.scripts.shell.Commands
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: openpolicyagent/opa:1.4.2-debug
inputFiles:
plan.json: "{{ outputs.terraform_plan.outputFiles['plan.json'] }}"
policy.rego: |
package terraform.analysis
deny contains msg if {
some rc in input.resource_changes
"delete" in rc.change.actions
msg := sprintf("%v would be deleted", [rc.address])
}
warn contains msg if {
some rc in input.resource_changes
"create" in rc.change.actions
msg := sprintf("%v will be created", [rc.address])
}
commands:
- |
if ! opa eval --fail-defined --format pretty -d policy.rego -i plan.json "data.terraform.analysis.deny[x]"; then
echo "Policy violation: the plan is denied"
exit 1
fi
- echo "::{\"outputs\":{\"warnings\":$(opa eval --format raw -d policy.rego -i plan.json 'count(data.terraform.analysis.warn)')}}::"
- id: approval_if_warnings
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.opa_check.vars.warnings > 0 }}"
then:
- id: approve_apply
type: io.kestra.plugin.core.flow.Pause
pauseDuration: PT4H
behavior: CANCEL
- id: terraform_apply
type: io.kestra.plugin.scripts.shell.Commands
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: hashicorp/terraform:1.9
inputFiles:
main.tf: |
resource "local_file" "environment_config" {
content = "environment=production"
filename = "env_config.txt"
}
tfplan: "{{ outputs.terraform_plan.outputFiles['tfplan'] }}"
commands:
- terraform init -input=false
- terraform apply -input=false tfplan

What the flow shows: the policy lives next to the infrastructure code, a deny stops the run before anything changes, a warn turns into an approval with a deadline, and each decision stays in the execution logs. For a CI-oriented variant, see the OPA policy gate blueprint.

Establishing continuous compliance across your pipelines

Match each tool to its layer: Checkov and Trivy to catch issues during development, Kyverno or OPA Gatekeeper at Kubernetes admission, Sentinel if you run HCP Terraform, and OPA for rules shared across all of them. Kestra runs those checks inside every provisioning workflow, with approvals and an audit trail. Browse more infrastructure resources for related guides.

Terraform, Ansible and Kubernetes, orchestrated from one place.

Frequently asked questions

Find answers to your questions right here, and don't hesitate to Contact Us if you couldn't find what you're looking for.