As a DevSecOps practitioner, itβs critical to choose the right Policy-as-Code tool based on your stack and use case. Below is a comparison of 5 key tools used to enforce governance across CI/CD pipelines, Infrastructure as Code, and Kubernetes.
Tool |
Ecosystem Fit |
Policy Language |
Best For |
Realtime Enforcement |
Difficulty |
OPA |
Cloud-native (K8s, Terraform) |
Rego |
Generic policy engine, APIs, Terraform |
β
Yes (via Gatekeeper) |
βοΈ Medium |
Sentinel |
HashiCorp Stack |
Sentinel (HCL-like) |
Terraform Enterprise, Vault, Consul |
β
Yes |
βοΈ Medium |
Checkov |
Terraform, CloudFormation |
YAML + Python |
IaC static security checks |
β No (pre-apply only) |
π’ Easy |
Conftest |
YAML, JSON, Dockerfiles, etc. |
Rego (OPA) |
CI/CD config validation |
β No (CI only) |
βοΈ Medium |
Kyverno |
Kubernetes-native |
Declarative YAML |
Kubernetes admission policies |
β
Yes |
π’ Easy |
π Real-World Use Cases
β
OPA (Open Policy Agent)
- Enforce no unencrypted S3 buckets in Terraform
- Block Kubernetes pods from running as root (via Gatekeeper)
- Apply policies on custom APIs (Envoy/NGINX integration)
1
2
3
4
5
| # Disallow root containers in Kubernetes
violation[{"msg": msg}] {
input.spec.securityContext.runAsNonRoot == false
msg := "Containers must not run as root"
}
|
β
Sentinel
- Block Terraform plans that donβt tag resources
- Ensure Vault secrets are scoped properly
- Enforce job-level access policies in Nomad
1
2
| # Enforce tagging policy
main = rule { all resources.r as r { r.tags contains "env" } }
|
β
Checkov
- Scan Terraform for open security groups
- Ensure RDS has backup retention
- Detect hardcoded secrets
1
2
3
| # Checkov finding example
check: CKV_AWS_24
message: Ensure no open security group to 0.0.0.0/0
|
β
Conftest
- Enforce variables in Ansible playbooks
- Validate GitHub Actions workflows
- Run pre-merge config checks in CI
1
2
3
4
5
| # Required env variable must exist
deny[msg] {
not input.env
msg := "Missing required env key"
}
|
β
Kyverno
- Block use of
latest
image tag
- Auto-label all pods with team info
- Enforce CPU/memory limits
1
2
3
4
5
6
7
8
| # Block latest tag in image
spec:
validation:
message: "Avoid using latest tag"
pattern:
spec:
containers:
- image: "!*:latest"
|
π§ Summary: How to Choose
Scenario |
Start With |
General-purpose policies |
OPA |
You use Terraform Enterprise |
Sentinel |
Quick IaC scan before deploying |
Checkov |
Need portable CI/CD policy checks |
Conftest |
Kubernetes native enforcement |
Kyverno |
π Explore More
Thanks for reading. May your pipelines be green, your infra be tagged, and your security posture be strong!
π Explore my other blogs at opsbygandal.dev
π Check out the GitHub repo [https://github.com/gandalops/portfolio-chirpy]
π Letβs connect on LinkedIn