Role-Based Access Control (RBAC)는 사용자 또는 시스템이 수행할 수 있는 작업을 제어하는 방법이다.
Kubernetes와 Istio 모두 자체 RBAC 시스템을 가지고 있으며, 둘 다 사용하여 클러스터 내에서 보다 세밀한 액세스 제어를 할 수 있다.
1. RBAC 이해하기
- RBAC(Role-Based Access Control): 사용자의 역할에 따라 Kubernetes 리소스에 대한 접근 권한을 제어한다.
- 주요 구성 요소: Role, ClusterRole, RoleBinding, ClusterRoleBinding.
- Role과 ClusterRole: 리소스에 대한 접근 권한(동작들)을 정의한다.
- RoleBinding과 ClusterRoleBinding: 특정 사용자, 그룹 또는 서비스 어카운트에 Role 또는 ClusterRole을 할당한다.
2. RBAC 구성 요소
- Role: 특정 네임스페이스 내에서 리소스에 대한 접근을 정의
- ClusterRole: 클러스터 전체적으로 리소스에 대한 접근을 정의
- RoleBinding: Role을 하나 이상의 사용자에게 할당
- ClusterRoleBinding: ClusterRole을 하나 이상의 사용자에게 할당
3. RBAC 구성 방법
Role 생성
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
pod-reader 라는 role을 생성하여 default namespace의 파드를 읽을 수 있는 권한
주요 설정 값
- apiGroups: API 그룹을 나타내며, 코어 그룹은 ""로 표시된다. (pods, nodes, services, namespaces 와 같은 기본적인 리소스 포함)
- resources: pods, services, deployments 등의 Kubernetes 리소스를 지정한다.
- verbs: 리소스에 대한 행동 권한을 나타내며, get, list, watch, create, update, patch, delete 등이 있다.
RoleBinding 생성
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
jane이라는 사용자에게 만들었던 pod-reader 역할 부여
context 전환 및 생성한 롤 바인딩(RoleBinding) 확인
# 사용 가능한 context 확인
kubectl config get-contexts
# dev-user context로 전환
# kubectl config use-context [변경할 context]
kubectl config use-context dev-user
# 현재 사용중인 context 확인
kubectl config current-context
'클라우드' 카테고리의 다른 글
Docker, Kubernetes에서의 런타임시 Containerd로의 전환 (0) | 2024.04.10 |
---|---|
EBS 볼륨 확장 및 축소 (0) | 2024.04.02 |
Terraform tfstate 상태 파일 관리 (0) | 2024.03.20 |
Kubernetes liveness, readness, startup probe (0) | 2024.03.13 |
AWS IP당 추가 비용, EBS SSD 스토리지 마이그레이션 (2) | 2024.02.28 |
댓글