متقدم
البحث فيالمعامل
طريقة البحث
  • ابحث عن مهمة أو أداة (lvm، selinux، ‎@podman)؛ وصفِّ حسب المستوى والكتاب أو الدورة.
  • مع مربع بحث فارغ، الفلتر وحده يعرض المعامل — مثلًا كل المعامل الصعبة لدورة واحدة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

معمل 2.1AZ-104 on Manara, الفصل 2

Govern a subscription: management group, RBAC, Azure Policy, tags, a lock and a budget

المستوى
متوسط
50 دقيقة
الأجهزة
an Azure subscription where you are Owner, Azure CLI or Cloud Shell
الحالة
لم يبدأ

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

الهدف

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.

المهام

  1. Create the management group mg-lab and move your subscription into it.
  2. Create a custom role Help Desk VM Operator that 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.
  3. Assign the built-in policy Require a tag on resource groups (costCenter) and Allowed locations (westeurope, northeurope) at the management group.
  4. Assign Inherit a tag from the resource group if missing with a managed identity, so resources get costCenter automatically.
  5. Try to create a resource group without the tag, and one in eastus. Both must be denied. Create rg-lab-gov correctly.
  6. Put a CanNotDelete lock on rg-lab-gov and try to delete the group.
  7. Create a monthly budget of 20 EUR on the subscription with an email alert at 80 % (actual) and 100 % (forecast).
  8. 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 create commands fail with RequestDisallowedByPolicy.
  • The lock is listed, and the delete fails with ScopeLocked.
  • The budget budget-lab is listed.

تلميحات

اعرض التلميحات

الحل

اعرض الحل
  1. Management group.
    az account management-group create -n mg-lab --display-name "Lab"
    az account management-group subscription add --name mg-lab --subscription $SUB
  2. 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"]
    }
    sed -i "s/SUBSCRIPTION_ID/$SUB/" helpdesk-role.json
    az role definition create --role-definition @helpdesk-role.json
    az group create -n rg-lab-gov -l $LOC --tags costCenter=it
    az role assignment create --assignee helpdesk@yourtenant.onmicrosoft.com --role "Help Desk VM Operator" -g rg-lab-gov
  3. 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
  4. Test (wait a few minutes after the assignment): the two bad commands from Check your work fail with RequestDisallowedByPolicy.
  5. The lock.
    az lock create -n keep-gov -g rg-lab-gov --lock-type CanNotDelete --notes "critical shared resources"
    az group delete -n rg-lab-gov --yes
    (ScopeLocked) The scope '/subscriptions/.../resourceGroups/rg-lab-gov' cannot perform delete operation because following scope(s) are locked
  6. 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.

  7. Clean up.
    az lock delete -n keep-gov -g rg-lab-gov
    for a in require-costcenter allowed-locations inherit-costcenter; do az policy assignment delete -n $a --scope $MG; done
    az group delete -n rg-lab-gov --yes --no-wait

ملاحظاتي

لا توجد ملاحظات بعد.

دروس هذا المعمل

الأوامر في هذا المعمل