RBAC و ServiceAccounts
ما هو RBAC؟
Section titled “ما هو RBAC؟”RBAC يعني Role-Based Access Control. وظيفته تحديد:
- من يستطيع الوصول؟
- إلى أي موارد؟
- ما العمليات المسموحة؟
الموارد الأساسية
Section titled “الموارد الأساسية”| المورد | معناه |
|---|---|
ServiceAccount | هوية يستخدمها Pod |
Role | صلاحيات داخل Namespace |
ClusterRole | صلاحيات على مستوى Cluster |
RoleBinding | ربط Role بهوية |
ClusterRoleBinding | ربط ClusterRole بهوية |
Role للقراءة فقط
Section titled “Role للقراءة فقط”apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata: name: pod-readerrules: - apiGroups: [""] resources: ["pods"] verbs: ["get", "list", "watch"]RoleBinding
Section titled “RoleBinding”apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata: name: read-podssubjects: - kind: ServiceAccount name: approleRef: kind: Role name: pod-reader apiGroup: rbac.authorization.k8s.ioاختبار الصلاحيات
Section titled “اختبار الصلاحيات”kubectl auth can-i list pods --as=system:serviceaccount:default:appkubectl auth can-i delete pods --as=system:serviceaccount:default:appLab: ServiceAccount محدود
الهدف: إنشاء ServiceAccount يستطيع قراءة Pods فقط.
أنشئ ServiceAccount و Role و RoleBinding، ثم استخدم kubectl auth can-i لاختبار الصلاحيات.