هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
الهدف
Put the governance part of AZ-104 into practice in one sitting: a management group above the subscription, a custom RBAC role for the help desk, Azure Policy that requires a costCenter tag and allows only two regions, tag inheritance, a delete lock on a critical resource group, and a budget with an alert. You test each control by trying to break it.
قبل أن تبدأ
- Cloud Shell (Bash). You must be Owner of the subscription; management groups also need the tenant-level permission (a Global Administrator can give it once with Access management for Azure resources).
- Variables:
SUB=$(az account show --query id -o tsv),LOC=westeurope.
المهام
ضع علامة على المهمة عندما تنتهي منها. متصفحك فقط يتذكر ذلك.
- Create the management group
mg-laband move your subscription into it. - Create a custom role
Help Desk VM Operatorthat can read everything and start, restart and deallocate VMs, but not delete or create them. Assign it to a test user or group on one resource group. - Assign the built-in policy Require a tag on resource groups (
costCenter) and Allowed locations (westeurope,northeurope) at the management group. - Assign Inherit a tag from the resource group if missing with a managed identity, so resources get
costCenterautomatically. - Try to create a resource group without the tag, and one in
eastus. Both must be denied. Createrg-lab-govcorrectly. - Put a CanNotDelete lock on
rg-lab-govand try to delete the group. - Create a monthly budget of 20 EUR on the subscription with an email alert at 80 % (actual) and 100 % (forecast).
- Remove the lock, the assignments and the test resources.
تحقّق من عملك
az account management-group show -n mg-lab --expand -o table
az role definition list --custom-role-only true --query "[].roleName" -o tsv
az group create -n rg-no-tag -l westeurope
az group create -n rg-us -l eastus --tags costCenter=it
az lock list -g rg-lab-gov -o table
az group delete -n rg-lab-gov --yes
az consumption budget list -o table- The subscription is a child of
mg-lab. - The custom role is listed.
- Both bad
az group createcommands fail withRequestDisallowedByPolicy. - The lock is listed, and the delete fails with
ScopeLocked. - The budget
budget-labis listed.
تلميحات
اعرض التلميحات
az account management-group subscription add --name mg-lab --subscription $SUB.- A custom role JSON has
ActionslikeMicrosoft.Compute/virtualMachines/start/action,.../restart/action,.../deallocate/action,*/read, andAssignableScopes. - Find built-in policy IDs:
az policy definition list --query "[?displayName=='Allowed locations'].name" -o tsv. - A
modifypolicy (tag inheritance) needs--mi-system-assigned --locationand the role Tag Contributor for the identity; existing resources need a remediation task.
الحل
اعرض الحل
- Management group.
- Custom role.helpdesk-role.json
{ "Name": "Help Desk VM Operator", "Description": "Read all, start/restart/deallocate VMs. No create or delete.", "Actions": ["*/read", "Microsoft.Compute/virtualMachines/start/action", "Microsoft.Compute/virtualMachines/restart/action", "Microsoft.Compute/virtualMachines/deallocate/action"], "NotActions": [], "AssignableScopes": ["/subscriptions/SUBSCRIPTION_ID"] } - and 4. Policies at the management group.
MG=/providers/Microsoft.Management/managementGroups/mg-lab TAG=$(az policy definition list --query "[?displayName=='Require a tag on resource groups'].name" -o tsv) LOCS=$(az policy definition list --query "[?displayName=='Allowed locations'].name" -o tsv) INH=$(az policy definition list --query "[?displayName=='Inherit a tag from the resource group if missing'].name" -o tsv) az policy assignment create -n require-costcenter --scope $MG --policy $TAG --params '{"tagName":{"value":"costCenter"}}' az policy assignment create -n allowed-locations --scope $MG --policy $LOCS --params '{"listOfAllowedLocations":{"value":["westeurope","northeurope"]}}' az policy assignment create -n inherit-costcenter --scope $MG --policy $INH --params '{"tagName":{"value":"costCenter"}}' --mi-system-assigned --location $LOC --role "Tag Contributor" --identity-scope $MG - Test (wait a few minutes after the assignment): the two bad commands from Check your work fail with
RequestDisallowedByPolicy. - The lock.
- Budget.
az consumption budget create --budget-name budget-lab --amount 20 --category cost --time-grain monthly --start-date $(date +%Y-%m-01) --end-date $(date -d '+1 year' +%Y-%m-01)Add the alert e-mails (80 % actual, 100 % forecast) in the portal: Cost Management → Budgets → budget-lab → Alert conditions.
- Clean up.
ملاحظاتي
لا توجد ملاحظات بعد.
دروس هذا المعمل
- 2.2Role-Based Access Control (RBAC): Assigning Roles for Resource Access
- 2.3Azure Policy & Governance: Ensuring Resource Compliance & Management
- 2.4Managing Azure Subscriptions & Costs: Optimizing Budgets, Resource Tracking & Governance
- 2.1Managing Entra ID: Multi-factor authentication (MFA) Setup, User and Group Management