Kyverno

2026. 3. 9. 14:34·IT/기타
반응형

키베르노란?

Kyverno는 쿠버네티스 클러스터 보안/정책 자동화 도구로, 간단히 말해

쿠버네티스 환경에서 정책을 검증(Validate), 수정(Mutate), 생성(Generate)해주는 정책 엔진  이라고 생각하면 됨.

OPA Gatekeeper와 비슷하지만, 쿠버네티스에 더 특화되고 사용이 훨씬 쉬움.

Kyverno가 할 수 있는 3가지

① Validate (검증)

특정 규칙을 어기는 Pod/Deployment 등을 거부(deny)하거나 경고(warn)

예시:

privileged=true 금지

hostPath 금지

항상 label team=xxx 있어야 함

이미지 태그 latest 사용 금지

 

② Mutate (자동 패치)

리소스가 조건을 만족하지 않으면 자동으로 보정(patch)
예시:

리소스 requests/limits 자동 추가

toleration 자동 추가

sidecar 자동 삽입

특정 label 자동 삽입

“정책으로 쿠버네티스 리소스를 자동 표준화 하는 기능”

③ Generate (자동 생성)

새 Namespace가 생성될 때 자동으로 추가 리소스 생성.

예시:

Namespace 만들면 role-binding 자동 생성

기본 networkPolicy 자동 생성

configMap 템플릿 복제

Kyverno의 장점

YAML만 알면 사용 가능

Rego 같은 새로운 언어 배울 필요 없음.

Mutate 기능이 매우 강력함

Gatekeeper는 mutate가 안되고, Kyverno는 mutate가 기본 기능.

클러스터 기준 정책 표준화

보안

최소 스펙

네임스페이스 표준화
모두 자동화 가능.

CNCF 정식 프로젝트 (Graduated)

프로덕션에서 매우 널리 사용됨.

 


helm repo add kyverno https://kyverno.github.io/kyverno/
helm repo update

helm install kyverno kyverno/kyverno \
  --namespace kyverno \
  --create-namespace

 

 

첫번쨰 정책 생성

-> privileged pod 생성 제한

 

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: disallow-privileged
spec:
  validationFailureAction: enforce
  rules:
    - name: validate-privileged
      match:
        resources:
          kinds:
            - Pod
      validate:
        message: "Privileged containers are not allowed"
        pattern:
          spec:
            containers:
              - securityContext:
                  privileged: false

 

testpod 생성

 

apiVersion: v1
kind: Pod
metadata:
  name: privileged-test
spec:
  containers:
    - name: test
      image: busybox
      command: ["sleep", "3600"]
      securityContext:
        privileged: true

 

생성 거부 확인

 

# kubectl apply -f disallow_privileged_pod_test.yaml

Error from server: error when creating "disallow_privileged_pod_test.yaml": admission webhook "validate.kyverno.svc-fail" denied the request:

resource Pod/default/privileged-test was blocked due to the following policies

disallow-privileged:

 validate-privileged: 'validation error: Privileged containers are not allowed. rule

   validate-privileged failed at path /spec/containers/0/securityContext/privileged/'

 

hostpath를 막아보자

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: disallow-hostpath
spec:
  validationFailureAction: Enforce
  rules:
    - name: validate-hostpath
      match:
        resources:
          kinds:
            - Pod
            - Deployment
            - DaemonSet
            - StatefulSet
      validate:
        message: "HostPath volumes are not allowed."
        pattern:
          spec:
            volumes:
              - X(hostPath): "null"

 

# kubectl apply -f disallow_hostpath_pod_test.yaml

Error from server: error when creating "disallow_hostpath_pod_test.yaml": admission webhook "validate.kyverno.svc-fail" denied the request:

resource Deployment/openlab/openlab-was was blocked due to the following policies

disallow-hostpath:

 validate-hostpath: 'validation error: HostPath volumes are not allowed. rule validate-hostpath

   failed at path /spec/volumes/'

disallow-privileged:

 autogen-validate-privileged: 'validation error: Privileged containers are not allowed.

   rule autogen-validate-privileged failed at path /spec/template/spec/containers/0/securityContext/'

 

막힘. 정책 새로 설정시 이미 running인 pod들은 정책이 적용되지 않는다 (hostpath를 쓰더라도 삭제되지않음)

 

 

반응형
저작자표시 (새창열림)

'IT > 기타' 카테고리의 다른 글

Ansible을 활용한 리눅스 OS 보안 취약점 조치 + Terraform  (0) 2026.03.11
OTEL+Jaeger  (0) 2026.03.09
S3 + velero  (0) 2026.03.09
Node Local DNS Cache  (0) 2026.03.09
OBS <-> PVC 연결  (1) 2026.03.09
'IT/기타' 카테고리의 다른 글
  • Ansible을 활용한 리눅스 OS 보안 취약점 조치 + Terraform
  • OTEL+Jaeger
  • S3 + velero
  • Node Local DNS Cache
nyub
nyub
  • nyub
    xinyub cloud
    nyub
  • 전체
    오늘
    어제
    • 전체 글 (171)
      • Cloud (17)
        • AWS (12)
        • KT (3)
        • NHN (2)
      • IT (137)
        • Network (22)
        • Linux (41)
        • Windows server (30)
        • Docker (9)
        • Terraform (5)
        • Git, Github (3)
        • Kubernetes (9)
        • CI CD (11)
        • 기타 (7)
      • Etc (17)
        • TroubleShooting (12)
        • Other Info (4)
        • 자격증 (1)
  • 반응형
  • hELLO· Designed By정상우.v4.10.3
nyub
Kyverno
상단으로

티스토리툴바