[Kubernetes] APIs and Access(3)[RBAC(Role Based Access Control)]
DevOps/Kubernetes

[Kubernetes] APIs and Access(3)[RBAC(Role Based Access Control)]

목차

Kubernetes APIs and Access(3)

- RBAC(Role Based Access Control)

  - Role, Cluster Role

  - RoleBinding, ClusterRoleBinding

  - Service Account

 


APIs and Access

RBAC(Role Based Access Control)

 - 인증 모듈은 4개가 존재하며, 이중 RBAC이 가장 대표적이고 효과적인 방식

    https://kubernetes.io/docs/reference/access-authn-authz/rbac/

    

그림 출처 : http://logicalshift.blogspot.com/2019/05/kubernetes-rbac.html

Role, Cluster Role

- 작업 수행에 대한 권한. '어떤 resource에 어떤 verb 권한을?'

- 차이 : kind 에 들어가는 종류명, namespace 존재 여부 (범위만 다름)

- Cluster Role 사용 예시 : 클러스터 관리자, 쿠버네티스 컨트롤러

 

 

실습

첫째로는 role 로 만들어 줍니다.

 

kubectl create role pod-reader --verb=get --verb=list --verb=watch --resource=pods --dry-run=client -o yaml > pod-reader-role.yaml

이번엔 clusterrole로 만들어 봅시다.

 

이와 동일한데 role을 clusterrole로 변경한 것입니다.

kubectl create clusterrole pod-reader --verb=get --verb=list --verb=watch --resource=pods --dry-run=client -o yaml > pod-reader-cluster.yaml

다른 방법으로는 

kubectl create clusterrole pod-reader --verb=get,list,watch --resource=pods --dry-run=client -o yaml > pod-reader-role.yaml

kubectl get clusterrole | grep pod 로 pod 확인

diff 로 해당 두 yaml파일을 비교해보면 아래와 같이 kind만 다릅니다.

 

이제 만든 yaml파일로 apply 합니다.

kubectl apply -f pod-reader-role.yaml

kubectl apply -f pod-reader-cluster.yaml

 

kubectl get role

kubectl get clusterrole | grep pod로 확인

 

kubectl get role -A 전체 namespace pod 확인

 

kubectl edit role kube-proxy -n kube-system

kube-system 이라는 namespace에 들어가 직접 edit 하는 명령어입니다.

 


RoleBinding, ClusterRoleBinding

- Role을 사용자/그룹/Service Account에 연결. '어떤 resource에 어떤 verb 권한을, ' + '누구에게 줄 것인가?'

- 차이 : kind에 들어가는 종류명, namespace 존재 여부 (범위만 다름)

- Cluster Role 사용 예시 : 클러스터 관리자, 쿠버네티스 컨트롤러

 

실습

kubectl create rolebinding --help

 

앞서서 serviceaccount를 create 해줍니다.

kubectl create serviceaccount limhs

 

kubectl create rolebinding limhs-pod-reader --role=pod-reader --serviceaccount=defalut:limhs

로 rolebinding을 생성해줍니다.

 

kubectl get rolebinding 

kbuectl describe rolebindings limhs-pod-reader로 확인

 

 

 


Service Account

- 파드 내부에서 실행하는 프로세스가 쿠버네티스 API를 호출하고 싶다면? Service Account 활용

  # kubectl create serviceaccount test

 

 다른 namespace안에 있는 pod에서 cluster에 있는 API를 호출할 때 필요로 한다.

그림 출처 : Kubernetes in Action

 


Reference

https://classlion.net/class/detail/21

 

도커/쿠버네티스 온라인 부트캠프 with 카카오엔터프라이즈

도커/쿠버네티스 온라인 부트캠프 with 카카오엔터프라이즈

www.classlion.net