Thuta Learning
ရှာဖွေရန်
AdvancedDevOpsintermediate

RBAC & Security Basics

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • RBAC & Security Basics ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် kubectl command/YAML ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

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 တော့ မပေးသင့်ပါ.

အတူတူ ကြည့်မယ်

yaml
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
You should see
$ 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 လုပ်ဖို့ ခက်ခဲသွားနိုင်ပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Everyone ကို cluster-admin ClusterRole ပေးထားခြင်း (least privilege principle ကို ချိုးဖောက်ခြင်း) — troubleshooting/incident risk များစေပါတယ်
  • Service Account ကို default permission (namespace default token) အတိုင်းပဲ run ခြင်း — app compromise ဖြစ်ရင် attacker ရဲ့ access scope ကျယ်သွားနိုင်ပါတယ်

အခု ကိုယ်တိုင် စမ်းကြည့်

`pod-reader` Role နဲ့ RoleBinding ကို apply လုပ်ပြီး `kubectl auth can-i` command နဲ့ permission ကို confirm လုပ်ကြည့်ပါ။

You'll know it worked when: $ kubectl auth can-i delete pods --as=dev-team -n staging no $ kubectl auth can-i get pods --as=dev-team -n staging yes

RBAC & Security Basics | Thuta Learning