/qa-iac:policy-as-code-runnerfrom qa-iac
Writes OPA Rego policies and runs Conftest to enforce custom rules on Kubernetes manifests, Terraform plans, Dockerfiles, and other structured data in CI.
Ships in qa-iac. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Conftest is a CLI that uses OPA (opa-docs) to test structured configuration files (Kubernetes manifests, Terraform plans, Dockerfiles, etc.) against Rego policies. This skill covers Conftest invocation + Rego policy authoring as the custom policy layer alongside Checkov / tfsec / KICS (which carry built-in checks).
:latest tags, no apt-get upgrade, etc.).# macOS
brew install conftest
# Or download binary
curl -LO https://github.com/open-policy-agent/conftest/releases/latest/download/conftest_<version>_Linux_x86_64.tar.gz
# policies/kubernetes/required_labels.rego
package main
# All pods must have these labels
required_labels := {"app", "version", "owner"}
deny[msg] {
input.kind == "Deployment"
label := required_labels[_]
not input.spec.template.metadata.labels[label]
msg := sprintf("Deployment '%s' missing required label '%s'", [input.metadata.name, label])
}
# All deployments must specify resource limits
deny[msg] {
input.kind == "Deployment"
container := input.spec.template.spec.containers[_]
not container.resources.limits.memory
msg := sprintf("Container '%s' in deployment '%s' missing memory limit", [container.name, input.metadata.name])
}
deny[msg] {
input.kind == "Deployment"
container := input.spec.template.spec.containers[_]
not container.resources.limits.cpu
msg := sprintf("Container '%s' in deployment '%s' missing CPU limit", [container.name, input.metadata.name])
}
The deny rule pattern: each deny[msg] rule that holds adds a
message to the deny set. If deny is non-empty, the test fails.
# Test a single manifest
conftest test deployment.yaml
# Test all manifests
conftest test manifests/
# With specific policy directory
conftest test deployment.yaml --policy ./policies/
# JSON output for CI parsing
conftest test deployment.yaml --output json
helm template myrelease charts/mychart/ -f values.yaml | conftest test -
The chart renders to manifests; Conftest validates them.
terraform plan -out=plan.tfplan
terraform show -json plan.tfplan > plan.json
conftest test plan.json --policy policies/terraform/
# policies/terraform/cost_center_tag.rego
package main
deny[msg] {
resource := input.resource_changes[_]
resource.type == "aws_instance"
not resource.change.after.tags.cost_center
msg := sprintf("EC2 instance '%s' missing cost_center tag", [resource.address])
}
# policies/dockerfile/no_latest.rego
package main
deny[msg] {
input[i].Cmd == "from"
val := input[i].Value
contains(val[0], ":latest")
msg := sprintf("Avoid :latest tag in FROM (line %d)", [i])
}
deny[msg] {
input[i].Cmd == "run"
val := input[i].Value[0]
contains(val, "apt-get upgrade")
msg := sprintf("Avoid 'apt-get upgrade' (line %d) - pin specific package versions", [i])
}
conftest test Dockerfile
Policies themselves should be tested:
# policies/kubernetes/required_labels_test.rego
package main
test_deployment_missing_labels {
deny[_] with input as {
"kind": "Deployment",
"metadata": {"name": "test"},
"spec": {"template": {"metadata": {"labels": {}}}}
}
}
test_deployment_with_all_labels {
count(deny) == 0 with input as {
"kind": "Deployment",
"metadata": {"name": "test"},
"spec": {"template": {"metadata": {"labels": {"app": "x", "version": "1.0", "owner": "team"}}}, "spec": {"containers": [{"resources": {"limits": {"memory": "512Mi", "cpu": "500m"}}}]}}
}
}
opa test policies/
jobs:
policy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- run: |
curl -L https://github.com/open-policy-agent/conftest/releases/download/v0.50.0/conftest_0.50.0_Linux_x86_64.tar.gz | tar xz
# user-owned bin dir on PATH: no sudo, no write to /usr/local/bin
mkdir -p "$HOME/.local/bin" && mv conftest "$HOME/.local/bin/"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Test policies
run: opa test policies/
- name: Conftest manifests
run: conftest test manifests/ --policy policies/
- name: Conftest Helm
run: helm template myrelease charts/mychart/ -f values.yaml | conftest test - --policy policies/
- name: Conftest Terraform
run: |
terraform plan -out=plan.tfplan
terraform show -json plan.tfplan > plan.json
conftest test plan.json --policy policies/terraform/
For runtime enforcement (vs PR-time):
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
name: requiredlabels
spec:
crd:
spec:
names: { kind: RequiredLabels }
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
# Same Rego from Step 2
Cluster admins install Gatekeeper; the constraint blocks Deployments that violate the policy at admission time.
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| Untested policies | Policy bugs let bad config through; over-strict policies block good config. | opa test against test fixtures (Step 7). |
| Policies in production without PR-time gating | Surprises at admission time; deployments fail. | CI gate first (Step 8); Gatekeeper second. |
| One mega-policy file | Hard to reason about; merge conflicts. | Per-domain policy files. |
| Rego complexity for simple checks | Hard to maintain; Rego learning curve. | Use Checkov / tfsec for built-in checks; OPA for custom. |
| Skipping the negation tests | Policy may pass for the wrong reason. | Test both deny and not-deny cases (Step 7). |
bdd-step-library-curator in the qa-bdd plugin),
policies can multiply; periodic review needed.conftest.dev.$GITHUB_PATH for a user-owned install dir in CI:
GitHub Actions: adding a system path.open-policy-agent.github.io/gatekeeper/.checkov-policy,
trivy-config - sister scanners with
built-in checks (use these first; OPA for custom).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub testland/qa --plugin qa-iac4 skills in this plugin
/checkov-policyUse for any question or task about Checkov or scanning infrastructure code (Terraform, CloudFormation, Kubernetes, Helm, ARM, Serverless, CDK) with the broadest built-in rule set, including custom security checks written in Python: SARIF and JUnit output, and a baseline so CI fails only on new findings. Single-tool option: trivy-config./helm-chart-testerUse when a Helm chart's template logic needs unit tests: helm-unittest test files per template with isKind, equal, matchRegex and snapshot assertions, plus helm lint and helm template render checks. Policy checks are policy-as-code-runner; security scans are checkov-policy or trivy-config./trivy-configUse for any question or task about scanning infrastructure code for misconfigurations with one tool, including Kubernetes manifests, Terraform, CloudFormation, Helm, ARM and Dockerfiles that run as root, or migrating off tfsec: trivy config with severity gating, .trivyignore suppressions, custom Rego checks and SARIF for GitHub code scanning. Legacy tfsec is in its references.2 plugins ship this exact skill · first indexed Nov 12, 2026
Other plugins' skills for the same job