🐳 Container/K8S

[K8s][CKS] Admission Controller

heywantodo 2024. 6. 19. 14:10
728x90
반응형

[K8s][CKS] Admission Controller

쿠버네티스의 접근제어에는 크게 3가지가 있다.

Authentication 접속한 사람의 신분을 시스템이 인증
Authorization 누가 어떤 권한을 가지고 어떤 행동을 할 수 있는지 확인
Admission Control 인증과 권한 확인 이후에 추가적으로 요청 내용에 대한 검증이나 요청 내용을 수정 할 때 사용

 

이 중 쿠버네티스의 Admission Control은 요청이 인증되고 권한이 부여된 후에

Kubernetes API 서버에 대한 승인한 요청과 관련된 객체를 수정 할 수 있다.

 

Admission Controller Plugins

Admission Controller는 관리자의 특정 정책을 수행하는 주체라고 볼 수 있다.

다시 말해 Admission Control을 수행하는 주체다.

 

쿠버네티스 1.30 버전의 승인 컨트롤러는, 아래 링크에서 확인할 수 있으며

kube-apiserver 클러스터 관리자만 구성이 가능하다.

 

Admission Controllers Reference

This page provides an overview of Admission Controllers. What are they? An admission controller is a piece of code that intercepts requests to the Kubernetes API server prior to persistence of the object, but after the request is authenticated and authoriz

kubernetes.io

 

Admission Control 단계

승인 제어 프로세스는 두 단계로 진행된다.

 

1. 변경 허용 컨트롤러가 실행

2. 승인 컨트롤러 유효성 검사 실행

 

두 단꼐 중 하나라도 요청을 거부하면, 전체 요청이 즉시 거부되고 오류가 반환된다.

 

Admission Controller 실행

Kubernetes API 서버에서 다음과 같은 파라미터로 활성화 할 수 있다.

 --enable-admission-plugins=NamespaceLifecycle

 

어떤 승인 플러그인이 활성화되어있는지 확인하기 위해선 다음 명령어를 사용할 수 있다.

kube-apiserver -h | grep enable-admission-plugins

 

Admission Controller 예시

Admission Controller는 위 링크에서 확인할 수 있듯이 다양한 구성이 있으며,

그중 ImagePolicyWebhook 구성을 하는 방법에 대해 알아보고자 한다.

 

ImagePolicyWebhook

해당 승인 컨트롤러를 사용하면 백엔드 웹훅이 허용 결정을 내릴 수 있다.

해당 컨트롤러는 기본적으로 비활성화 되어있다.

 

ImagePolicyWebhook은 구성 파일을 사용하여 백엔드 동작에 대한 옵션을 결정하며 (json, yaml)

구성 파일 형식은 다음과 같다.

imagePolicy:
  kubeConfigFile: /path/to/kubeconfig/for/backend
  # time in s to cache approval
  allowTTL: 50
  # time in s to cache denial
  denyTTL: 50
  # time in ms to wait between retries
  retryBackoff: 500
  # determines behavior if the webhook backend fails
  defaultAllow: true

 

API 서버에 ImagePolicyWebhook 구성 파일을 다음 파라미터를 통해 추가가 가능하다.

--admission-control-config-file

ImagePolicyWebhook 구성 파일은 백엔드에 대한 연결을 설정하는 kubeconfig 형식의 파일을 참조해야 하며,

백엔드는 TLS를 통해 통신해야 한다. kubeconfig 파일의 cluster 필드는 원격 서비스를 가리켜야 하며 필드엔 user 반환된 권한 부여자가 포함되어야 한다.

# clusters refers to the remote service.
clusters:
  - name: name-of-remote-imagepolicy-service
    cluster:
      certificate-authority: /path/to/ca.pem    # CA for verifying the remote service.
      server: https://images.example.com/policy # URL of remote service to query. Must use 'https'.

# users refers to the API server's webhook configuration.
users:
  - name: name-of-api-server
    user:
      client-certificate: /path/to/cert.pem # cert for the webhook admission controller to use
      client-key: /path/to/key.pem          # key matching the cert

 

추가 HTTP 구성은 kubeconfig 설명서를 참조하면 된다.

 

Configure Access to Multiple Clusters

This page shows how to configure access to multiple clusters by using configuration files. After your clusters, users, and contexts are defined in one or more configuration files, you can quickly switch between clusters by using the kubectl config use-cont

kubernetes.io

 

728x90
반응형