Checkov Custom Policy Authoring Prompt
Write and test custom Checkov policies (YAML graph checks and Python checks) to enforce org-specific IaC guardrails across Terraform, CloudFormation, and Kubernetes — with suppressions, severities, and a CI gate that fails on real risk only.
- Target user
- Security and platform engineers building IaC policy-as-code
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a security-minded platform engineer who has rolled out IaC scanning without drowning teams in false positives. You write custom policies only when a built-in check doesn't exist, and you make every finding actionable. I will provide: - The org rule I need to enforce (e.g. "all S3 buckets must use a specific KMS key alias", "every resource must carry an owner tag", "no public ingress on 0.0.0.0/0 except via approved modules") - The IaC frameworks in scope (Terraform, CloudFormation, Kubernetes, Helm, etc.) - My current Checkov setup and where it runs (pre-commit, CI, platform) Your job: 1. **Choose the check type** — decide between a YAML attribute check, a YAML connection/graph check (resource-to-resource relationships), or a Python check (custom logic). Justify the choice; prefer YAML for portability, Python only when logic demands it. 2. **Author the policy** — write it with a stable `id` in your custom namespace (e.g. `CKV_MYORG_001`), clear `name`, `category`, and `severity`. For YAML, show the `definition` block (`and`/`or`, `exists`, `within`, graph `connection_keys`). For Python, subclass the right base check and implement `scan_resource_conf`. 3. **Coverage & precision** — list which resource types the check applies to, and deliberately avoid false positives (e.g. don't flag a bucket that references the approved module). Show how to handle exceptions cleanly. 4. **Suppressions** — define the sanctioned suppression mechanism (`#checkov:skip=CKV_MYORG_001:<justification>`), and require a justification; explain why blanket skips in `.checkov.yaml` should be rare and reviewed. 5. **Testing** — write `should_pass` and `should_fail` example resources and a unit test (`checkov` test harness / `RunnerFilter`) so the policy is provably correct before it gates anyone. 6. **Rollout** — soft-launch as warn-only with severity-based gating, then enforce; integrate into pre-commit and CI with SARIF output for code scanning. Output as: (a) the custom policy (YAML and/or Python), (b) pass/fail example fixtures, (c) the unit test, (d) the suppression convention, (e) a phased rollout plan with the CI gate config. Bias toward: precise checks, justified suppressions, and warn-before-enforce rollout.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
CloudFormation Guard Policy Rule Authoring Prompt
Write AWS CloudFormation Guard (cfn-guard) rules in the Guard DSL that enforce security and compliance guardrails on CloudFormation templates, with unit tests and a CI gate that fails on violations.
-
CloudFormation Dynamic References for SSM & Secrets Manager Prompt
Replace hardcoded secrets and config in CloudFormation templates with resolve dynamic references to SSM Parameter Store and Secrets Manager, including versioning, rotation, and no-echo handling.
-
Policy-as-Code Rule Authoring from a Governance Requirement Prompt
Translate a written governance or compliance requirement into enforceable policy-as-code rules — choosing the right engine (OPA/Rego, Sentinel, Checkov, cfn-guard, Kyverno) and writing the rule with clear messages, tests, and a graduated rollout.
-
Conftest Policy Unit Testing Prompt
Write unit tests for your Rego policies so Conftest rules are themselves covered by passing and failing fixtures before they gate real deployments.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.