How does policy-as-code with OPA/Conftest relate to Checkov?
IntermediateConceptCheckov
Answer
Short answer
Checkov comes with ready-made security policies for common misconfigurations. OPA (Open Policy Agent) with Conftest is a general policy engine where you write your own rules in Rego — ideal for organisation-specific rules (approved regions, mandatory tags, naming) on Terraform plans, Kubernetes YAML or any JSON/YAML. Many teams use Checkov for broad security coverage and OPA for custom governance.
Conftest example (Rego) on a Terraform plan
package main
deny contains msg if {
r := input.resource_changes[_]
r.type == "aws_instance"
not r.change.after.tags.owner
msg := sprintf("%s must have an 'owner' tag", [r.address])
}
terraform show -json tfplan > tfplan.json
conftest test tfplan.json
Where each fits
| Need | Tool |
|---|---|
| Broad security baseline, compliance mapping | Checkov / Trivy |
| Custom org rules, any JSON/YAML | OPA / Conftest |
| Admission control in Kubernetes | OPA Gatekeeper or Kyverno |
What to say in the interview
"Checkov provides a large library of built-in security checks; OPA with Conftest is a general engine for custom Rego rules on plans and manifests. We use Checkov for the security baseline and OPA for company-specific governance."
More on Checkov
What is Checkov and how do you scan Terraform with it?BeginnerWhat is IaC security scanning and why is it needed?BeginnerWhat is Checkov?BeginnerHow do you scan Terraform code with Checkov?BeginnerWhy scan the Terraform plan with Checkov instead of only the .tf files?IntermediateHow do you scan Kubernetes manifests and Dockerfiles with Checkov?Beginner