إضافة شروط تعيين دور Azure أو تحريرها باستخدام Azure CLI

شرط تعيين دور Azure هو فحص إضافي يمكنك إضافته اختياريا إلى تعيين الدور الخاص بك لتوفير مزيد من التحكم في الوصول الدقيق. مثلاً، يمكنك إضافة شرط يتطلب كائناً ذا علامة معينة لقراءة الكائن. توضح هذه المقالة كيفية إضافة شروط تعيينات الدور أو تحريرها أو سردها أو حذفها باستخدام Azure CLI.

المتطلبات الأساسية

للحصول على معلومات حول المتطلبات الأساسية لإضافة شروط تعيين الدور أو تحريرها، انظر الشروط المطلوبة.

إضافة شرط

لإضافة شرط تعيين دور، استخدم az role assignment create. يتضمن الأمر az role assignment create المعلمات التالية المتعلقة بالشروط.

المعلمة النوع الوصف
condition السلسلة الشرط الذي يمكن بموجبه منح المستخدم الإذن.
condition-version السلسلة إصدار بناء جملة الشرط. إذا --condition تم تحديد بدون --condition-version، يتم تعيين الإصدار إلى القيمة الافتراضية 2.0.

يوضح المثال التالي كيفية تعيين دور Storage Blob Data Reader بشرط. يتحقق الشرط ما إذا كان اسم الحاوية يساوي "blobs-example-container".

az role assignment create --role "Storage Blob Data Reader" --scope /subscriptions/mySubscriptionID/resourceGroups/myResourceGroupName --assignee "user1@contoso.com" \
--description "Read access if container name equals blobs-example-container" \
--condition "((!(ActionMatches{'Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read'})) OR (@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:name] StringEquals 'blobs-example-container'))" \
--condition-version "2.0"

يوضح ما يلي مثالا على الإخراج:

{
    "canDelegate": null,
    "condition": "((!(ActionMatches{'Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read'})) OR (@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:name] StringEquals 'blobs-example-container'))",
    "conditionVersion": "2.0",
    "description": "Read access if container name equals blobs-example-container",
    "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}",
    "name": "{roleAssignmentId}",
    "principalId": "{userObjectId}",
    "principalType": "User",
    "resourceGroup": "{resourceGroup}",
    "roleDefinitionId": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/2a2b9908-6ea1-4ae2-8e65-a410df84e7d1",
    "scope": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}",
    "type": "Microsoft.Authorization/roleAssignments"
}

تحرير شرط

لتحرير شرط تعيين دور موجود، استخدم az role assignment update وملف JSON كإدخل. يظهر التالي مثالا لملف JSON حيث يتم تحديث الشرط والوصف. يمكن تحرير الخصائص conditionconditionVersionو و description فقط. يجب تحديد كافة الخصائص لتحديث شرط تعيين الدور.

{
    "canDelegate": null,
    "condition": "((!(ActionMatches{'Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read'})) OR (@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:name] StringEquals 'blobs-example-container' OR @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:name] StringEquals 'blobs-example-container2'))",
    "conditionVersion": "2.0",
    "description": "Read access if container name equals blobs-example-container or blobs-example-container2",
    "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}",
    "name": "{roleAssignmentId}",
    "principalId": "{userObjectId}",
    "principalType": "User",
    "resourceGroup": "{resourceGroup}",
    "roleDefinitionId": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/2a2b9908-6ea1-4ae2-8e65-a410df84e7d1",
    "scope": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}",
    "type": "Microsoft.Authorization/roleAssignments"
}

استخدم Set-AzRoleAssignment لتحديث شرط تعيين الدور.

az role assignment update --role-assignment "./path/roleassignment.json"

يوضح ما يلي مثالا على الإخراج:

{
    "canDelegate": null,
    "condition": "((!(ActionMatches{'Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read'})) OR (@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:name] StringEquals 'blobs-example-container' OR @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:name] StringEquals 'blobs-example-container2'))",
    "conditionVersion": "2.0",
    "description": "Read access if container name equals blobs-example-container or blobs-example-container2",
    "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}",
    "name": "{roleAssignmentId}",
    "principalId": "{userObjectId}",
    "principalType": "User",
    "resourceGroup": "{resourceGroup}",
    "roleDefinitionId": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/2a2b9908-6ea1-4ae2-8e65-a410df84e7d1",
    "scope": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}",
    "type": "Microsoft.Authorization/roleAssignments"
}

سرد شرط

لسرد شرط تعيين دور، استخدم az role assignment list. لمزيد من المعلومات، راجع سرد تعيينات دور Azure باستخدام Azure CLI.

حذف شرط

لحذف شرط تعيين دور، قم بتحرير شرط تعيين الدور وتعيين الخاصيتين condition و condition-version إما إلى سلسلة فارغة ("") أو null.

بدلا من ذلك، إذا كنت تريد حذف كل من تعيين الدور والشرط، يمكنك استخدام الأمر az role assignment delete . لمزيد من المعلومات، راجع إزالة تعيينات دور Azure.

الخطوات التالية