전공공부
[K8S - CKA] Role Based Access Controls 본문
우리는 전에 ABAC 방식이나 Node 방식등을 알아 봤습니다. 그때, 저희는 Role에 따라서 주는것이 좋은 걸 알았죠.
그리고, core 그룹과 named API 그룹에 대해서 알아봤습니다.
아래와 같이 설정을 하고 Role을 아래와 같이 만들 수 있습니다.
이때, 이렇게 만들어지면 pods 리소스에 대해서는 get 요청 및 list,create,update,delete의 요청이 가능합니다.
또한, 이후에 아래 명령어로 Role 개채 생성 한 후 Role을 각 유저에 바인딩 해줍시다.
RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: developer
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "list", "create", "update", "delete"]
- apiGroups: [""]
resources: ["ConfigMap"]
verbs: ["create"]
kubectl create -f developer-role.yaml
RoleBinding 아래와 같이 dev-user를 apiGroups이 Role과 연결이 되고 developer 직접 작동을 하는 것을 알 수 있습니다.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: devuser-developer-binding
namespace: default
subjects:
- kind: User
name: dev-user
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: developer
apiGroup: rbac.authorization.k8s.io
$ kubectl create -f devuser-developer-binding.yaml
View RBAC
$ kubectl get roles
NAME AGE
developer 15s
$ kubectl get rolebindings
NAME AGE
devuser-developer-binding 5s
role 개채 보기
$ kubectl describe role developer
rolebinding 개채 보기
$ kubectl describe rolebinding devuser-developer-binding
auth can-i 명령어를 쓰면 내가 뒤의 명령어를 쓸 수 있는지 파악 할 수 있다. 그리고, test를 할 수 있다.
$ kubectl auth can-i create deployments
yes
$ kubectl auth can-i delete nodes
no
아래는 내가 관리자 일 때 해당 권한이 해당 유저에 존재하는지 알아 볼 수 있는 권한입니다.
$ kubectl auth can-i create deployments --as dev-user
no
$ kubectl auth can-i create pods --as dev-user
yes
POD 리소스에도 resourceNames을 달아서 만일 green pod, orange pod에서만 해당 동작을 지원하겠다고 Role을 설정 할 수도 있습니다.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: developer
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "create", "update"]
resourceNames: ["green", "orange"]
'Study > K8S' 카테고리의 다른 글
[K8S - CKA] ServiceAccounts (0) | 2024.01.14 |
---|---|
[K8S - CKA] Cluster Role & Role Binding (1) | 2024.01.11 |
[K8S - CKA] Authorization (0) | 2024.01.09 |
[K8S - CKA] API Groups (1) | 2024.01.08 |
[K8S - CKA] CA KubeConfig (0) | 2024.01.07 |