Generate, test, validate, explain, and debug OPA (Open Policy Agent) Rego policies and Conftest configurations. Covers deny/warn/violation rules, unit tests, regal linting, conftest fmt, namespace design, input shape analysis, and GitHub Actions integration. Use when asked to "write a policy", "test a rego file", "validate policies", "explain this rego", or "why is my policy not firing".
88%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
The canonical home for this skill is opa in nitinjain999/platform-skills
Write, test, validate, explain, and debug OPA Rego policies with Conftest.
AI-agent behavior, not infra policy: to gate what an AI coding agent (Copilot, Claude Code) can edit or run in a repo, use
/platform-skills:ai-governance— a different policy engine for a different input shape (tool calls and diffs, not Terraform/Kubernetes manifests).
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 runningValidation: Test the policy against both a passing and a failing resource before deploying to CI:
# Should produce no output (policy passes)
conftest test --policy <dir> <passing-resource.yaml>
# Should produce a deny/warn message (policy fires)
conftest test --policy <dir> <failing-resource.yaml>Both must behave as expected. A policy that never fires on a failing resource is not enforcing anything.
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>Validation: All tests must pass with zero skipped:
conftest verify --policy <dir>
# Expected: PASS - X tests, 0 failures, 0 skipped
# Skipped tests mean test fixtures are incomplete — fix before mergingRun 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>Translate an existing Rego policy into plain English.
Steps:
input.<field> to the resource attribute it readsdata.* (external allow-lists or config)Diagnose why a policy is not firing as expected.
Steps:
conftest test or conftest verify output# Extract every input.<path> reference from the policy
grep -oE 'input\.[a-zA-Z0-9_.[\]]+' <policy-file> | sort -u
# Build a targeted jq filter from those paths and run it
conftest parse <input-file> | jq '{field1: .<path1>, field2: .<path2>, ...}'--namespace or --all-namespaces?deny, warn, or violation? Other names are silently ignored by Conftestdeny[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>nitinjain999/platform-skills
c2e75b7
Canonical home
since Oct 12, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.