Geavanceerd
Zoeken inLabs
Zo zoek je
  • Zoek een taak of een tool (lvm, selinux, @podman); filter op niveau en op boek of cursus.
  • Met een leeg zoekvak toont een filter alleen al de labs — bijvoorbeeld alle moeilijke labs van één cursus.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Lab 2.1AZ-104 on Manara, Hoofdstuk 2

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

Niveau
Gemiddeld
50 min
Machines
an Azure subscription where you are Owner, Azure CLI or Cloud Shell
Status
Nog niet begonnen

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Doel

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.

Voordat je begint

  • 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.

Taken

  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.

Controleer je werk

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.

Hints

Toon de hints

Oplossing

Toon de oplossing
  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

Mijn notities

Nog geen notities.

Lessen voor dit lab

Commando's in dit lab