How do you write a custom Checkov policy?
IntermediateProductionTesting and Policy as Code
Answer
A YAML policy (or Python check) defines a resource type and attribute condition.
metadata:
id: "CKV2_ACME_1"
name: "S3 buckets must have Owner tag"
category: "GENERAL_SECURITY"
definition:
cond_type: attribute
resource_types: ["aws_s3_bucket"]
attribute: "tags.Owner"
operator: exists
Run with checkov -d . --external-checks-dir ./policies. Keep custom policies in one repo, versioned and tested.
More on Testing and Policy as Code
How do you test infrastructure code, and what does the testing pyramid look like?BeginnerWhat does the static-analysis layer catch?BeginnerWhat does tflint do, and how is it configured?BeginnerHow do Checkov and Trivy differ?IntermediateHow does `terraform test` work?BeginnerHow do mock providers work in `terraform test`?Advanced