CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

Conftest

$ conftest 基金会 低风险
Open Policy Agent · 云原生与基础设施 · Apache-2.0 · macos / linux / windows

conftest 将 OPA Rego 策略引入各类结构化配置文件,包括 Kubernetes 清单、Terraform Plan JSON、Dockerfile、TOML 与 HCL。它可完全离线运行,触发违规时返回非零退出码,并通过 --output json 输出结构化结果。

FCRS-1.0 综合评分
93 /100
极佳 (Excellent)
中置信度 (源码/文档)
零摩擦安装命令
brew install conftest
CLI vs MCP 选型建议 仅 CLI 可用

本地配置策略门禁工具;conftest test -o json 直接作用于仓库文件,无需 MCP 开销。

Agent 友好度体检单

✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
✓ 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 23 / 25

支持 --output json(-o json)、--no-color、deny 非零退出码及标准输入管道(conftest test -)。

  • Native -o json / --output json and --no-color flags
  • Supports stdin (-) and multiple config parsers automatically
安全与权限边界 24 / 25

默认只读策略评估;仅在调用 conftest pull 下载 OCI 策略包时才会写入本地目录。

  • Read-only test and verify commands with zero cloud side effects
安装与运行摩擦 15 / 15

静态 Go 单二进制,全平台覆盖 Homebrew、Go 与 GitHub Releases。

  • Single static Go binary with built-in multi-format parsers
能力覆盖与边际价值 14 / 15

内置 YAML、JSON、HCL、Dockerfile、TOML 与 XML 解析器,无需额外格式转换即可运行 OPA。

  • Auto-detects 15+ config formats for Rego validation
维护与来源背书 9 / 10

归属 open-policy-agent 官方组织,Apache-2.0 协议维护。

  • Maintained under open-policy-agent/conftest
文档与可验证性 8 / 10

conftest.dev 官方文档简明实用,涵盖 Terraform、Kubernetes 与 Dockerfile 示例。

  • Documented CLI flags and parser matrix at conftest.dev

安全边界、鉴权与放权指南

鉴权方式
无需鉴权
凭证存储位置

本地策略测试无需认证;仅使用 conftest pull 拉取 OCI 策略 Bundle 时才会复用 Docker/OCI 凭证助手。

潜在副作用
只读查询
费用与配额提示

Open Policy Agent 旗下 Apache-2.0 开源项目,免费使用。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# Conftest Agent Rules
- Always pass `--output json` (`-o json`) and `--no-color` when parsing violations.
- Avoid `conftest pull` from untrusted OCI registries without verifying policy bundle digests.
- Use `conftest verify -p policy/` after editing Rego policy rules.

Agent 高频安全命令配方

只读查询(安全推荐)

对 Kubernetes 清单运行策略检查并输出 JSON
conftest test deploy.yaml -p policy/ --output json

使用 policy/ 下的 Rego deny/warn 规则校验 deploy.yaml 并输出结构化 JSON 结果。

校验 Rego 策略自身的单元测试
conftest verify -p policy/ --output json

运行 policy/ 目录内的策略单元测试,不改动任何配置文件。

核心优势

  • + 内置 YAML、HCL、Dockerfile、JSON 与 TOML 解析器并直接送入 Rego。
  • + 提供规范的 --output json、--no-color 与清晰退出码。
  • + 支持标准输入流(如 terraform show -json tfplan | conftest test -)。

注意事项与踩坑点

  • ! 非标准扩展名或特殊格式文件有时需显式指定 --parser。
  • ! 不自带默认策略库,需在项目中编写 Rego deny/violation 规则。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI