Interview Prep/DevSecOps/Container image and IaC scanning

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.

All DevSecOps questions

More on Container image and IaC scanning