التحكم في الوصول المستند إلى الأدوار (RBAC)
هيّئوا RBAC لإدارة أذونات المستخدمين وحسابات الخدمات بأمان داخل مجموعة Kubernetes.
التحكم في الوصول المستند إلى الأدوار (RBAC) درس مجاني في Docker & Kubernetes for Developers على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Docker & Kubernetes for Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Docker & Kubernetes for Developers 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
What is Kubernetes RBAC?
Welcome to Role-Based Access Control (RBAC)! In Kubernetes, RBAC is a method for regulating access to computer or network resources based on the roles of individual users within your organization.
Think of it as the security guard for your cluster: it decides who can do what.
Why RBAC is Essential
RBAC is critical for cluster security and operational integrity. Without it, any user or process with access could potentially perform any action, leading to security vulnerabilities or accidental misconfigurations.
- Security: Prevents unauthorized access.
- Least Privilege: Ensures users/applications only have necessary permissions.
- Compliance: Helps meet regulatory requirements for access control.
RBAC Core Concepts: Subjects
In RBAC, a Subject is 'who' is performing an action. Kubernetes identifies three types of subjects:
- Users: Human users (often managed externally).
- Service Accounts: Identities for processes running in Pods. These are Kubernetes-native.
- Groups: Collections of Users or Service Accounts.
We'll focus on Service Accounts as they are central to application security within Kubernetes.
RBAC Core Concepts: Roles
A Role defines 'what' actions can be performed. Roles are always namespace-scoped, meaning the permissions they grant apply only within a specific namespace.
A Role contains rules, which are sets of permissions. Each rule specifies:
apiGroups: The API group the resource belongs to (e.g.,""for core,appsfor deployments).resources: The specific resource types (e.g.,pods,deployments).verbs: The actions allowed (e.g.,get,list,create,delete).
RBAC Core Concepts: ClusterRoles
Similar to Roles, a ClusterRole also defines 'what' actions can be performed, but it is cluster-scoped. This means its permissions apply across the entire cluster.
ClusterRoles are used for:
- Granting access to cluster-scoped resources (like nodes).
- Granting access to resources across all namespaces.
- Granting access to non-resource endpoints (like
/healthz).
RBAC Core Concepts: RoleBindings
A RoleBinding is 'how' permissions are granted. It links a Subject (User, ServiceAccount, or Group) to a Role.
Like Roles, RoleBindings are namespace-scoped. This means the binding grants the permissions defined in the Role to the Subject, but only within that specific namespace.
RBAC Core Concepts: ClusterRoleBindings
A ClusterRoleBinding links a Subject to a ClusterRole. Because ClusterRoles are cluster-scoped, a ClusterRoleBinding grants permissions across the entire cluster.
Use ClusterRoleBindings carefully, as they grant broad access. They are typically used for cluster administrators or system-level components.
Example: Creating a Service Account
Let's create a Service Account named my-app-sa in the default namespace. This Service Account will be the identity for a future application pod.
Run this command in your terminal:
kubectl create serviceaccount my-app-sa -n defaultExample: Defining a Pod Reader Role
Now, let's define a Role called pod-reader in the default namespace. This Role will allow subjects to get, list, and watch pods.
Save this YAML as pod-reader-role.yaml and apply it using kubectl apply -f pod-reader-role.yaml:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
namespace: default
rules:
- apiGroups: [""] # Core API group
resources: ["pods", "pods/log"]
verbs: ["get", "list", "watch"]Example: Binding the Role
Finally, let's create a RoleBinding named read-pods-binding that links our my-app-sa Service Account to the pod-reader Role in the default namespace.
Save this YAML as pod-reader-binding.yaml and apply it:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods-binding
namespace: default
subjects:
- kind: ServiceAccount
name: my-app-sa
namespace: default
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.ioQuick Check: RBAC Resources
Which Kubernetes resource is used to grant cluster-wide permissions to a Service Account?
RBAC: Key Takeaways
You've learned the fundamentals of Kubernetes RBAC!
- Subjects: Who is acting (Users, Service Accounts, Groups).
- Roles/ClusterRoles: What actions are allowed (namespace-scoped vs. cluster-scoped).
- RoleBindings/ClusterRoleBindings: How subjects are linked to permissions (namespace-scoped vs. cluster-scoped).
Mastering RBAC is crucial for securing your Kubernetes applications and infrastructure. Keep practicing with different permission sets!
الأسئلة الشائعة
هل درس «التحكم في الوصول المستند إلى الأدوار (RBAC)» مجاني؟
نعم — نص درس «التحكم في الوصول المستند إلى الأدوار (RBAC)» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Docker & Kubernetes for Developers، انتقل إلى CoddyKit PRO. تتضمن دورة Docker & Kubernetes for Developers 4 دروس في المجموع.
ماذا ستتعلم في «التحكم في الوصول المستند إلى الأدوار (RBAC)»؟
هيّئوا RBAC لإدارة أذونات المستخدمين وحسابات الخدمات بأمان داخل مجموعة Kubernetes. تتمرن على Docker & Kubernetes for Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Docker & Kubernetes for Developers؟
لا تُشترط خبرة سابقة. Docker & Kubernetes for Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «التحكم في الوصول المستند إلى الأدوار (RBAC)»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Docker & Kubernetes for Developers هذا؟
نعم. كل درس في Docker & Kubernetes for Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- التحكم في الوصول المستند إلى الأدوار (RBAC)
- أمان Pod وفحص الصور
- تأمين حركة مرور الشبكة في Kubernetes
- إدارة الأسرار بأمان باستخدام مخازن الأسرار الخارجية