New to Kestra?
Use blueprints to kickstart your first workflows.
Upload and evaluate Open Policy Agent (OPA) Rego policies in Kestra to gate CI/CD changes, failing workflows when Kubernetes or Terraform changes break the rules.
Enforce Open Policy Agent (OPA) guardrails as a CI/CD policy gate in Kestra. This blueprint uploads a Rego policy to OPA, evaluates a proposed change set (Kubernetes manifests and Terraform) against it, and fails the workflow when the policy returns any deny messages. It solves a common DevOps and platform engineering problem: stopping non-compliant infrastructure and configuration changes before they reach an environment, with policy logic written once in Rego and applied consistently across pipelines.
A single io.kestra.plugin.core.flow.WorkingDirectory task named policy_gate wraps three steps:
upload_policy (io.kestra.plugin.ee.opa.policy.Upload) creates or updates the ci-guardrails Rego policy in OPA. The policy denies Kubernetes Deployments with fewer than 2 replicas and Terraform that uses a public S3 bucket, and allows the change only when there are zero deny messages.evaluate_policy (io.kestra.plugin.ee.opa.policy.Evaluate) sends the change set to the ci/guardrails policy path, with metrics: true and explain: "notes" for observability and debugging.fail_if_denied (io.kestra.plugin.core.flow.If) inspects outputs.evaluate_policy.result.deny. If any deny messages are present, the fail task (io.kestra.plugin.core.execution.Fail) stops the run with the deny list in the error message. Otherwise the ok task (io.kestra.plugin.core.log.Log) logs that the policy passed.OPA evaluates policy but does not schedule, trigger, or wire itself into the rest of your pipeline. Kestra fills that gap: run the gate on event triggers (a webhook from your VCS or CI system, an upstream flow, or a schedule), add retries on transient OPA connection failures, and capture full execution lineage so every allow and deny is recorded and replayable. The flow is declarative YAML, so the gate lives in version control next to the Rego policy and can be reviewed like any other change.
OPA_URL: base URL of the OPA server (for example http://localhost:8181).OPA_TOKEN: bearer token used to authenticate to OPA when it is protected.OPA_URL and OPA_TOKEN secrets to your Kestra namespace or environment.upload_policy to match your own guardrails.input.files in evaluate_policy with your real change set.