Conftest is a CLI that tests YAML, JSON, HCL, Dockerfiles, and many other config formats with Rego policies from the Open Policy Agent ecosystem.
Overview
Conftest helps teams validate structured configuration before it reaches production. You write assertions in Rego—the policy language from Open Policy Agent—and point the tool at files such as Kubernetes manifests, Terraform HCL, Tekton pipelines, serverless definitions, or other supported formats. The conftest test command evaluates configs and reports deny, warn, and violation outcomes.
Policies usually live under a policy directory, with defaults for namespace and rule naming that CLI flags can override. Conftest accepts file paths or stdin, exposes contextual data under data.conftest for file name and directory, and can return structured metadata from rules for JSON or GitHub Actions style output including optional location hints.
A verify command runs Rego unit tests alongside policies, and built-in parse helpers let tests load HCL or other formats inside policy code. Supported parsers span YAML, JSON, Dockerfile, HCL2, TOML, XML, nginx config, SPDX, CycloneDX, and additional listed formats.
The tool is format-agnostic beyond Kubernetes examples in documentation; the same workflow applies wherever configuration is stored as structured data under test.
Key features
- Rego policy assertions on configs
- conftest test and verify commands
- Many config format parsers
- Stdin and file path evaluation
- deny, warn, and violation rules
- Structured JSON and GitHub output
- parseconfig builtin for unit tests
- data.conftest file context
Use cases
- Kubernetes manifest guardrails
- Terraform and HCL linting in CI
- Pipeline and Dockerfile policy checks
- Pre-deploy configuration validation