إتقان Azure RBAC: built-in roles (Owner، Contributor، Reader)، custom roles، scopes (Management Group، Subscription، Resource Group، Resource)، Just-In-Time access عبر PIM، Azure Policy، Resource Locks.
للسياق: الدليل الرئيسي Azure AZ-104 · Microsoft Entra ID.
المقدّمة
Azure RBAC (Role-Based Access Control) هو ترخيص الوصول إلى موارد Azure. مختلف عن Entra ID (الذي يستوثق). هذا الدرس يُغطّي RBAC + Azure Policy + Resource Locks للحوكمة الكاملة.
المتطلّبات
- Tenant Azure مُهيَّأ.
- فهم Entra ID users/groups.
- المستوى المتوسّط.
- الوقت: ساعتان.
الخطوة 1 — RBAC: 3 مكوّنات
Security Principal (من) : User، Group، Service Principal، Managed Identity
Role Definition (ماذا) : permissions (Microsoft.Compute/virtualMachines/start/action)
Scope (أين) : Management Group / Subscription / RG / Resource
role assignment واحد = ربط الثلاثة. مثلاً: User Mariam (security principal) + Contributor (role) + RG-Production (scope).
الخطوة 2 — Built-in roles
Azure تُوفّر ~120 built-in roles. الأساسيّون:
Owner : full control + manage access (تعيين أدوار أخرى)
Contributor : full control ما عدا manage access
Reader : view only
User Access Admin : إدارة access RBAC فقط
أدوار حسب الخدمة (>100):
- Virtual Machine Contributor
- Storage Blob Data Reader
- Network Contributor
- Key Vault Secrets User
- AcrPull (Azure Container Registry pull)
في الاختبار: اختر الدور least privilege حسب الـ use case.
الخطوة 3 — تعيين role
# User
USER_ID=$(az ad user show --id mniang@yourtenant.onmicrosoft.com --query id -o tsv)
# Resource Group ID
RG_ID=$(az group show --name RG-Production --query id -o tsv)
# Assignment
az role assignment create \
--assignee $USER_ID \
--role "Contributor" \
--scope $RG_ID
# قائمة assignments
az role assignment list --scope $RG_ID --output table
# حذف
az role assignment delete --assignee $USER_ID --role "Contributor" --scope $RG_ID
الخطوة 4 — Inheritance و scopes
Management Group (root tenant)
└── Management Group (Production division)
└── Subscription (PROD-001)
└── Resource Group (RG-Web)
└── Resource (VM-Web-01)
الدور المُعيَّن على Management Group ← مُورَّث لكلّ subscriptions و RGs و resources تحت. granularité دقيق عبر scope محدّد.
في الاختبار: إذا كان user Contributor على Subscription و Reader على RG، فهو Contributor على الـ RG (Allow يَغلب). لا Deny في RBAC القياسي.
الخطوة 5 — Custom roles
إذا لم تكفي built-in، أنشئ custom role JSON:
{
"Name": "Junior VM Operator",
"Description": "Can start/stop VMs, no other action",
"Actions": [
"Microsoft.Compute/virtualMachines/start/action",
"Microsoft.Compute/virtualMachines/restart/action",
"Microsoft.Compute/virtualMachines/deallocate/action",
"Microsoft.Compute/virtualMachines/read"
],
"NotActions": [],
"DataActions": [],
"NotDataActions": [],
"AssignableScopes": ["/subscriptions/<sub-id>"]
}
az role definition create --role-definition role.json
az role assignment create --assignee $USER_ID --role "Junior VM Operator" --scope $SUB_ID
في الاختبار: custom roles محدودة بـ 5000 لكلّ tenant. AssignableScopes إلزاميّة.
الخطوة 6 — Deny Assignments
Deny = حجب صريح يتجاوز Allow. تُنشَأ تلقائياً من Azure (مثل Azure Blueprints، managed apps)، لا من users.
للمعرفة: ترتيب التقييم = Deny > Allow. لا يمكنك إنشاء Deny عبر portal/CLI القياسيين.
الخطوة 7 — PIM: Privileged Identity Management (P2)
لأدوار مُمتازة (Owner، Subscription Owner، Global Admin)، PIM يحوّل التعيينات الدائمة إلى eligibility مع activation عند الطلب.
التهيئة:
1. Portal > Entra ID > Privileged Identity Management
2. Azure resources > اختر subscription
3. Roles > اختر "Owner" > Settings
4. Activation maximum duration: 4 hours
5. Require justification: Yes
6. Require approval: Yes (اختر approvers)
7. Require MFA on activation: Yes
8. Enable activation maximum sign-ins per role per user per day: 1
Workflow:
- User eligible لـ Owner (غير نشط)
- عند الحاجة، user يطلب activation مع justification
- Approver يُوافق
- User نشط Owner لـ 4 ساعات كحدّ أقصى
- Audit كامل في logs
الخطوة 8 — Azure Policy
يُعرّف قواعد يجب على الموارد احترامها. ليس RBAC، بل governance.
أمثلة policies built-in:
- "Allowed locations": تقييد النشر بالمناطق المسموحة (مثل France Central فقط)
- "Allowed VM SKUs": فقط B-series مسموح
- "Require tag and value": tag "CostCenter" إلزاميّ
- "Audit VMs without managed disks"
- "Storage accounts should restrict network access"
Effects: Audit، Deny، DeployIfNotExists، Modify، Append
# تعيين policy "Allowed locations"
az policy assignment create \
--name "allowed-locations-fr" \
--display-name "Restrict to France Central" \
--policy "e56962a6-4747-49cd-b67b-bf8b01975c4c" \
--params '{"listOfAllowedLocations":{"value":["francecentral"]}}' \
--scope $SUB_ID
Compliance dashboard يُظهر الموارد التي تحترم / تخالف policies.
في الاختبار: policies تُطبَّق بالتسلسل من Management Group. اجمع مع RBAC لحوكمة كاملة.
الخطوة 9 — Resource Locks
منع التعديل/الحذف العرضيّ لموارد حرجة.
ReadOnly : لا تعديل ولا حذف
CanNotDelete: تعديل ممكن، حذف محجوب
# Lock subscription
az lock create --name lock-prod --resource-group RG-Production --lock-type CanNotDelete
# Lock VM specifique
az lock create --name lock-vm --lock-type ReadOnly \
--resource-group RG-Production --resource VM-Critical \
--resource-type Microsoft.Compute/virtualMachines
# قائمة locks
az lock list --resource-group RG-Production --output table
# حذف lock
az lock delete --name lock-prod --resource-group RG-Production
في الاختبار: Locks تطبّق على كلّ users و service principals، حتى Owner. لإزالة، يجب admin privileges + حذف explicit.
الخطوة 10 — Best practices RBAC
1. Least privilege : Reader par défaut، élever si nécessaire
2. Use groups, not users : assigner roles à Entra ID groups
3. PIM pour privileged : Owner/Contributor au niveau Subscription via PIM
4. Audit roles trimestriels : Access Reviews (P2)
5. Custom roles si besoin : éviter Contributor trop large
6. Resource locks production: CanNotDelete sur tous RG prod
7. Policy + RBAC ensemble : policy = règles، RBAC = qui peut faire quoi
8. Tags + Cost management : suivre coûts par projet/département
الأخطاء المتكرّرة
| الخطأ | الحلّ |
|---|---|
| Contributor sur subscription = Owner partial | Préférer Resource Group level |
| Policy en mode Deny bloque déploiement | Tester en Audit mode d’abord |
| Lock ReadOnly bloque updates Azure Update Manager | Utiliser CanNotDelete pour balance |
| Custom role inutilisable hors scope | AssignableScopes doit couvrir scope cible |
| PIM activation MFA échoue | User doit avoir MFA enregistré au préalable |
تكيّفات إقليميّة
Banques: PIM obligatoire pour Owner، Access Reviews trimestriels، Resource Locks sur prod، Policy « Allowed locations » = EU only.
Startups: simple RBAC avec 3-4 groups (Admins، Devs، Readers)، pas de PIM (Free tier).
ESN: multi-subscription par client + Management Groups pour governance unifiée + custom roles pour permissions client.
أسئلة شائعة
Owner vs Contributor? Owner peut assigner d’autres rôles، Contributor non.
PIM disponible Free? Non، Entra ID P2 obligatoire.
Resource Lock vs Azure Policy Deny? Lock = sur ressource existante، Policy Deny = sur création.
للتعمّق
- الدليل الرئيسي: Azure AZ-104
- التتمّة: Azure Backup، Monitor، Log Analytics.
- التوثيق: Azure RBAC docs.
الكلمات المفتاحيّة: Azure RBAC، Built-in roles، Custom roles، Management Groups، PIM، Azure Policy، Resource Locks، Least privilege.
تعميق
Banque ivoirienne: Management Groups (Prod، Dev، Test) + Policy « EU regions only » + PIM Owner approval Bank Council + Resource Locks tous prod RGs.
Startup Dakar: 1 subscription + 2 RG (Prod، Dev) + 3 groups Entra + RBAC Contributor sur Dev RG.
ESN multi-clients: Management Group par client + custom roles « ClientAdmin » + Policy isolement réseau + Access Reviews trimestriels.
أدوات تكميليّة
Azure Policy، Azure Blueprints (deprecated)، Azure Landing Zones، Microsoft Defender for Cloud Recommendations، Microsoft Entra Permissions Management (multicloud)، Azure Cost Management + Tagging strategy.