Conftest/OPA policy on Terraform plan always passes, even for a resource that clearly violates it
AdvancedTroubleshootingContainer image and IaC scanning
Answer
Likely causes → Rego path mismatch: wrong package (package main expected by default), rule named deny vs violation, or iterating input.resource_changes with the wrong field (change.after is null on deletes).
Diagnose →
conftest test tf.json -p policy --namespace main --trace | head -50
opa eval -i tf.json -d policy 'data.main.deny' --format pretty
Fix → Match the package and rule names Conftest expects and guard nulls:
package main
deny contains msg if {
rc := input.resource_changes[_]
rc.type == "aws_s3_bucket_public_access_block"
rc.change.after.block_public_acls == false
msg := sprintf("%s must block public ACLs", [rc.address])
}
Prevent → Unit-test policies with opa test using passing and failing fixtures.
More on Container image and IaC scanning
Trivy fails the build on 14 HIGH/CRITICAL CVEs in the base image, all with "Fixed Version" emptyBeginner`FATAL ... failed to download vulnerability DB: ... TOOMANYREQUESTS: retry-after` from Trivy in CIIntermediateTrivy in an air-gapped runner fails with `failed to download vulnerability DB` even though you copied `db.tar.gz`AdvancedTrivy and Grype report different CVE counts for the same imageIntermediate`.trivyignore` entries are ignored and the build still fails on the same CVEBeginnerTrivy reports a critical CVE in a Go binary built from your own code, in package `stdlib`Intermediate