ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Cluster admin ကနေ Kubernetes command 'ဘာမဆို' run နိုင်ပါတယ်, ဒါပေမယ့် team အားလုံးကို admin access ပေးထားရင် အန္တရာယ်ကြီးပါတယ် (မတော်တဆ production deployment ဖျက်မိတာမျိုး)။ RBAC ရဲ့ core concept ၄ ခု ရှိပါတယ် — Role (namespace တစ်ခုအတွင်း permission set, ဥပမာ 'pod ကြည့်ခွင့်'), ClusterRole (cluster level permission), RoleBinding (Role ကို user/group တစ်ခုနဲ့ ချိတ်ဆက်ခြင်း), ClusterRoleBinding (ClusterRole ကို ချိတ်ဆက်ခြင်း)။ Service Account ကလည်း အရေးကြီးပါတယ် — Pod ထဲက app ကိုယ်တိုင်က Kubernetes API ကို ခေါ်သုံးချင်ရင် (ဥပမာ - CI/CD tool), Service Account နဲ့ scoped permission ပေးထားရပါမယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Developer team အတွက် `pod-reader` Role (get, list, watch permission ပဲ ပါ) ကို create လုပ်ပြီး, RoleBinding နဲ့ team member တွေကို ချိတ်ချရင်, သူတို့က pod ကြည့်နိုင်ပေမယ့် delete/create လုပ်ခွင့် မရှိတော့ပါ။ CI/CD pipeline (ဥပမာ - GitHub Actions) ကို deployment update permission ပဲ ပေးထားပြီး, cluster-wide admin permission တော့ မပေးသင့်ပါ.
အတူတူ ကြည့်မယ်
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: staging
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
namespace: staging
subjects:
- kind: User
name: dev-team
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io$ kubectl auth can-i delete pods --as=dev-team -n staging
no
$ kubectl auth can-i get pods --as=dev-team -n staging
yes၅ မိနစ် စမ်းကြည့်
`pod-reader` Role နဲ့ RoleBinding ကို apply လုပ်ပြီး `kubectl auth can-i` command နဲ့ permission ကို confirm လုပ်ကြည့်ပါ။
သတိလေးတစ်ချက်
RBAC ကို production cluster မှာ setup လုပ်တာ 'later' လို့ မဆိုင်းငံ့ပါနှင့် — developer/CI tool အားလုံးကို default admin access နဲ့ start လုပ်ရင် နောက်ပိုင်း tighten လုပ်ဖို့ ခက်ခဲသွားနိုင်ပါတယ်။