
Open Policy Agent Rego 쿼리 언어를 사용하여 구조화된 구성 데이터에 대한 테스트를 작성합니다
Conftest는 구조화된 구성 데이터에 대한 테스트를 작성할 수 있도록 도와줍니다. Conftest를 사용하면 Kubernetes 구성, Tekton 파이프라인 정의, Terraform 코드, Serverless 구성 또는 기타 다른 구성 파일에 대한 테스트를 작성할 수 있습니다.
Conftest는 어서션(assertion)을 작성하기 위해 Open Policy Agent의 Rego 언어를 사용합니다. Rego에 대한 자세한 내용은 Open Policy Agent 문서의 Policy Language 섹션에서 확인할 수 있습니다.
다음은 간단한 예제입니다. 아래 내용을 policy/deployment.rego로 저장하세요:
package main
deny contains msg if {
input.kind == "Deployment"
not input.spec.template.spec.securityContext.runAsNonRoot
msg := "Containers must not run as root"
}
deny contains msg if {
input.kind == "Deployment"
not input.spec.selector.matchLabels.app
msg := "Containers must provide app label for pod selectors"
}
deployment.yaml에 Kubernetes 배포(deployment)가 있다고 가정하면 다음과 같이 Conftest를 실행할 수 있습니다:
$ conftest test deployment.yaml
FAIL - deployment.yaml - Containers must not run as root
FAIL - deployment.yaml - Containers must provide app label for pod selectors
2 tests, 0 passed, 0 warnings, 2 failures, 0 exceptions
Conftest는 Kubernetes에 국한되지 않습니다. 다양한 형식의 모든 구성 파일에 대한 테스트를 자유롭게 작성할 수 있습니다. 설치 방법과 기능에 대한 자세한 내용은 문서를 참조하세요.
토론과 질문이 있으시면 Open Policy Agent Slack의 #opa-conftest 채널에서 함께해 주세요.