Production-grade platform engineering handbook — Kubernetes, Terraform, Flux CD, GitHub Actions, AWS, and more.
67
84%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
Write, test, validate, explain, and debug OPA Rego policies with Conftest.
When invoked with no arguments, ask before proceeding:
Q1 — Mode?
What do you need?
1. generate — write a new production-ready Rego policy
2. test — write _test.rego unit tests for an existing policy
3. validate — run the full pipeline (fmt, lint, tests) against a directory
4. explain — translate an existing Rego policy into plain English
5. debug — diagnose why a policy is not firing as expected
Enter 1–5 or mode name:Q2 — Context (after mode selected, one at a time):
Describe the policy — target resource type (Terraform/Kubernetes/GHA/Dockerfile) and what to deny or warn on:Paste the Rego policy to write tests for:Provide the directory path containing your .rego files:Paste the Rego policy to explain:Describe the symptom — is the policy not firing, producing no output, or throwing an error? Paste the conftest output:Then proceed into the relevant mode below.
Write a production-ready Rego policy from a description.
Steps:
conftest parse <file> to show the input shape if the user has a file, then write rules that match that shape exactly# METADATA block: title, description, authors, entrypoint: truepackage <namespace> — use main only when a single policy set applies; use a named package (package terraform.iam, package k8s.pods) for multi-domain reposimport rego.v1 — required for modern Rego syntaxdeny for hard failures, warn for advisory violations, violation for OPA framework integrations (Gatekeeper, Conftest policy sets)msg that includes the offending resource name/value and a remediation hintsome for iteration, in for membership, startswith/contains for string matchingterraform validate and before terraform plan as a blocking gate — failing conftest must prevent plan from runningReference: references/opa.md → Rule Types, Input Shape, Rego v1 Syntax
Write _test.rego unit tests for a given policy.
Steps:
<policy>_test.rego in the same directory:
package <namespace>_test (e.g. package terraform.iam_test)import rego.v1import data.<namespace>deny/warn/violation rule, write:
test_deny_ / test_warn_; assert count(<rule>) == 1 or count(<rule>) > 0test_allow_; assert count(<rule>) == 0conftest verify --policy <dir>Reference: references/opa.md → Unit Tests
Run the full policy validation pipeline against a directory.
Steps:
conftest fmt <dir>/*.rego --check — fails if any file is not canonically formattedconftest fmt <dir>/*.rego — rewrites in placeregal lint <dir> — reports style and correctness violations; fix each finding before continuingconftest verify --policy <dir> — all *_test.rego files must passconftest test --policy <dir> <input-files>Reference: references/opa.md → Validation Pipeline, Regal
Translate an existing Rego policy into plain English.
Steps:
input.<field> to the resource attribute it readsdata.* (external allow-lists or config)Reference: references/opa.md → Input Shape, Rego v1 Syntax
Diagnose why a policy is not firing as expected.
Steps:
conftest parse <file> output, and the conftest test or conftest verify output--namespace or --all-namespaces?deny, warn, or violation? Other names are silently ignored by Conftestconftest parse <input-file> and compare each input.<path> in the rule against the actual parsed structuredeny[msg]) or a boolean? Conftest expects set comprehensions for message outputimport rego.v1 missing: without it, if, in, contains may not work as expectedsome missing: iterating without some can cause unexpected behaviour in Rego v0 compatibility modeconftest test --policy <dir> <input>Reference: references/opa.md → Troubleshooting
.claude-plugin
.github
commands
docs
examples
agent-self-improve
argocd
awesome-docs
aws
cloudfront
functions
lambda-edge
functions
azure
compliance
conventional-commits
datadog
llm-observability
demo
documentation
dora
dynatrace
fluxcd
github-actions
composite-actions
configure-cloud
db-migrate
docker-build-push
k8s-deploy
notify-slack
pr-comment
release-tag
security-scan
setup-env
setup-terraform
terraform-plan
helm
web-service
templates
kubernetes
kyverno
mcp
observability
openshift
pr-review
ownership
runtime-security
supply-chain
terraform
references
scripts
skills
platform-skills
tests