Advanced
Searching inLabs
How to search
  • Search a task or a tool (lvm, selinux, @podman); filter by level and by book or course.
  • With an empty search box, a filter alone lists the labs — for example all hard labs of one course.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Lab 4.1AZ-104, Chapter 4

Build a locked-down storage account for a team

Level
Medium
45 min
Machines
Azure subscription (free or pay-as-you-go), Azure CLI or Cloud Shell
Status
Not started

Goal

Create a storage account the way a real admin does: the right type and redundancy, no anonymous access, TLS 1.2 only, access with Entra ID roles instead of keys, a short-lived SAS for one partner, and network access only from your own IP address. At the end you delete everything, so the lab costs almost nothing.

Before you start

  • Open Cloud Shell (Bash) in the Azure portal, or run az login on your computer.
  • Choose a region close to you, for example westeurope. Storage account names are global: use only small letters and numbers, 3–24 characters.
  • Set two variables you use in every task: RG=rg-lab-storage and SA=st<yourname><4 digits>.

Tasks

  1. Make the resource group $RG and a StorageV2 account $SA with ZRS redundancy, hot access tier, minimum TLS 1.2, HTTPS only and anonymous blob access disabled.
  2. Turn off shared key access, so nobody can use the account keys any more.
  3. Give your own user the role Storage Blob Data Contributor on the account only (not on the subscription).
  4. Make a private container reports and upload a small file with your Entra ID login, not with a key.
  5. Make a user delegation SAS for the file that allows only read, works only over HTTPS and ends in 1 hour. Open the file with curl and the SAS.
  6. Allow network access only from your own public IP address (default action Deny). Show the network rules.
  7. Show the encryption settings (key source) and the redundancy of the account.
  8. Delete the resource group.

Check your work

az storage account show -g $RG -n $SA --query "{kind:kind, sku:sku.name, tls:minimumTlsVersion, https:enableHttpsTrafficOnly, anon:allowBlobPublicAccess, keys:allowSharedKeyAccess}" -o table
az role assignment list --scope $(az storage account show -g $RG -n $SA --query id -o tsv) -o table
az storage blob list --account-name $SA -c reports --auth-mode login -o table
az storage account network-rule list -g $RG --account-name $SA
  • kind is StorageV2, sku is Standard_ZRS, tls is TLS1_2, https is True, anon and keys are False.
  • Your user has Storage Blob Data Contributor on the scope of the account.
  • The blob list shows your file. A curl with the SAS gives the text; the same URL without the SAS gives an error.
  • The network rules show your IP address and the default action Deny.

Hints

Show the hints

Solution

Show the solution
  1. Create the group and the account with safe settings.
    RG=rg-lab-storage; SA=sthosamlab1234; LOC=westeurope
    az group create -n $RG -l $LOC
    az storage account create -g $RG -n $SA -l $LOC --kind StorageV2 --sku Standard_ZRS --access-tier Hot --min-tls-version TLS1_2 --https-only true --allow-blob-public-access false
  2. Stop key access.
    az storage account update -g $RG -n $SA --allow-shared-key-access false
  3. Give yourself a data role on the account only.
    ME=$(az ad signed-in-user show --query id -o tsv)
    SCOPE=$(az storage account show -g $RG -n $SA --query id -o tsv)
    az role assignment create --assignee-object-id $ME --assignee-principal-type User --role "Storage Blob Data Contributor" --scope $SCOPE
  4. Make the container and upload with your login.
    echo "monthly report" > report.txt
    az storage container create --account-name $SA -n reports --auth-mode login
    az storage blob upload --account-name $SA -c reports -n report.txt -f report.txt --auth-mode login
  5. Make a read-only user delegation SAS for 1 hour.
    END=$(date -u -d '+1 hour' '+%Y-%m-%dT%H:%MZ')
    SAS=$(az storage blob generate-sas --account-name $SA -c reports -n report.txt --permissions r --expiry $END --https-only --as-user --auth-mode login -o tsv)
    curl -s "https://$SA.blob.core.windows.net/reports/report.txt?$SAS"
    monthly report
  6. Allow only your IP address.
    MYIP=$(curl -s https://ifconfig.me)
    az storage account network-rule add -g $RG --account-name $SA --ip-address $MYIP
    az storage account update -g $RG -n $SA --default-action Deny
    az storage account network-rule list -g $RG --account-name $SA
  7. Read encryption and redundancy.
    az storage account show -g $RG -n $SA --query "{keySource:encryption.keySource, sku:sku.name}" -o table
  8. Clean up.
    az group delete -n $RG --yes --no-wait

My notes

No notes yet.

Lessons for this lab

Commands in this lab