dcg

Azure CLI

cloud.azure

Protects against destructive Azure CLI operations like vm delete, storage account delete, and resource group delete

  • 29blocking rules
  • 6safe patterns
  • 16Critical
  • 11High
  • 2Medium
~/.config/dcg/config.toml
[packs]
enabled = ["cloud.azure"]

Evaluated when a command contains az, delete, vm, storage, acr, registry, keyvault, role, ad, dns.

Blocking rules

Each rule ID is cloud.azure:<name>. Use it in allowlists and [policy.rules].

  1. account-management-group-delete

    Critical

    az account management-group delete removes a management group from the tenant hierarchy.

    Explanation
    account management-group delete removes an Azure management group: - Azure Policy and RBAC assignments scoped to the group are lost - Child subscriptions and groups are reparented to the root group, silently widening or dropping inherited governance - The group must be empty; the CLI deletes it without a second prompt - There is no undelete — the hierarchy must be rebuilt by hand Inspect the subtree first: az account management-group show --name GROUP -e -r
  2. account-subscription-cancel

    Critical

    az account subscription cancel cancels an entire Azure subscription and everything in it.

    Explanation
    account subscription cancel (azure-cli `account` extension) cancels a whole subscription: - EVERY resource in the subscription is deprovisioned - Resources are retained only for a short grace period, then deleted permanently - Reactivation is a support/billing operation, not a CLI one This is one of the most destructive Azure commands. Confirm the subscription id first: az account show --subscription SUB --query id
  3. acr-delete

    Critical

    az acr delete removes the container registry and all images.

    Explanation
    acr delete removes entire container registry: - ALL repositories and images deleted - All tags and manifests gone - Webhooks and replications removed - Registry name becomes available to others List repos: az acr repository list --name REGISTRY
  4. ad-app-delete

    Critical

    az ad app delete removes an Azure AD app registration — every service principal for it stops working.

    Explanation
    ad app delete removes the Azure AD application registration: - All service principals derived from this app break - OAuth grants to this app are invalidated - Associated federated credentials are deleted - Can restore within 30 days via Graph API soft-delete Consider disabling instead: az ad app update --id APP-ID --set disabledByMicrosoftStatus=None
  5. ad-sp-delete

    Critical

    az ad sp delete removes a service principal — workloads using it lose auth.

    Explanation
    ad sp delete removes an Azure AD service principal: - All workloads authenticating via this SP lose access - SP credentials (client secrets, certs) are invalidated - Can soft-delete and restore within 30 days via Graph API - Associated app registration is NOT deleted (requires `az ad app delete`) Preview usages: az role assignment list --assignee SP-APP-ID
  6. aks-delete

    Critical

    az aks delete removes the entire AKS cluster.

    Explanation
    aks delete removes the entire Kubernetes cluster: - All nodes and workloads terminated - Persistent volumes may be deleted - Load balancers and IPs released - Node resource group also deleted Backup workloads: kubectl get all -A -o yaml > backup.yaml
  7. cosmosdb-delete

    Critical

    az cosmosdb delete permanently destroys the Cosmos DB resource.

    Explanation
    cosmosdb delete destroys Cosmos DB resources: - Account delete removes entire Cosmos DB account - Database delete removes database and all containers - Collection delete removes container and data Enable point-in-time restore for recovery options.
  8. cosmosdb-sql-container-delete

    Critical

    az cosmosdb <api> <db|container|keyspace> delete permanently destroys Cosmos DB data.

    Explanation
    cosmosdb <api> delete destroys Cosmos DB SQL/Mongo/Cassandra/Gremlin/Table API resources: - Container/keyspace deletion removes ALL documents/rows inside - Point-in-time restore is only available if continuous backup is enabled - Periodic backups can restore within retention, with a new account name Enable continuous backup for safer recovery: az cosmosdb update --name ACCOUNT --resource-group RG \ --backup-policy-type Continuous
  9. group-delete

    Critical

    az group delete removes the entire resource group and ALL resources within it!

    Explanation
    group delete removes ENTIRE resource group: - ALL resources in the group deleted - VMs, storage, databases, networks - everything - Cannot be undone - --no-wait returns immediately (deletion continues) This is one of the most destructive Azure commands!
  10. keyvault-delete

    Critical

    az keyvault delete removes the Key Vault. Secrets may be unrecoverable.

    Explanation
    keyvault delete removes Key Vault: - All secrets, keys, certificates deleted - Soft delete allows recovery (if enabled) - Purge protection prevents permanent deletion - Vault name reserved for recovery period Check protection: az keyvault show --name NAME --query properties.enablePurgeProtection
  11. keyvault-item-delete-or-purge

    Critical

    Key Vault item delete/purge (az keyvault <key|secret|certificate|storage> …) — purge bypasses soft-delete and is irreversible.

    Explanation
    keyvault delete/purge on a Key Vault sub-resource: - delete: soft-delete (recoverable within retention window) - purge: PERMANENT; cannot be recovered; bypasses retention - Purging a KEK (Key-Encryption-Key) makes all data encrypted under it unrecoverable - Applications/services bound to the item fail immediately Restore soft-deleted items within retention: az keyvault <sub> recover --name NAME --vault-name VAULT Check purge protection: az keyvault show --name VAULT --query properties.enablePurgeProtection
  12. keyvault-purge

    Critical

    az keyvault purge permanently destroys a soft-deleted Key Vault and every secret, key and certificate in it.

    Explanation
    Purging bypasses soft-delete: the vault and ALL of its contents are destroyed immediately and cannot be recovered. Safer alternatives: - az keyvault list-deleted: Review soft-deleted vaults first - az keyvault recover --name NAME: Restore it instead - Let the retention period expire rather than purging early
  13. network-dns-zone-delete

    Critical

    az network dns zone delete removes an Azure DNS zone — domains stop resolving.

    Explanation
    network dns zone delete removes an Azure DNS zone: - All record sets in the zone are deleted - Domains delegated to this zone's nameservers stop resolving - Production traffic goes dark - No undelete Export records first: az network dns record-set list -g RG -z ZONE -o json > zone-backup.json
  14. sql-delete

    Critical

    az sql server/db delete permanently destroys the database.

    Explanation
    sql server/db delete destroys databases: - Server delete removes ALL databases on server - Database delete removes specific database - Point-in-time restore possible within retention period Create backup: az sql db export --name DB --server SRV --storage-uri URI
  15. storage-delete

    Critical

    az storage account delete permanently destroys the storage account and all data.

    Explanation
    storage account delete destroys entire storage account: - ALL blobs, files, queues, tables deleted - All containers and their contents gone - Cannot be recovered without backups List contents first: az storage container list --account-name NAME
  16. vm-delete

    Critical

    az vm delete permanently destroys virtual machines.

    Explanation
    vm delete permanently destroys Azure VMs: - VM is deallocated and deleted - OS disk deleted (unless --os-disk=detach) - Data disks detached but not deleted - Public IP released Preserve disks: az vm delete --os-disk detach --data-disks detach
  17. account-alias-delete

    High

    az account alias delete removes the subscription alias used to manage a subscription declaratively.

    Explanation
    account alias delete removes a subscription alias: - The subscription itself survives, but the alias that IaC and billing automation address it by is gone - Alias names are not reusable immediately, so a re-create may fail - Pipelines that look the subscription up by alias start failing List aliases first: az account alias list
  18. account-lock-delete

    High

    az account lock delete removes a subscription-level management lock — the guardrail against deletion.

    Explanation
    account lock delete removes a subscription management lock: - A `CanNotDelete` / `ReadOnly` lock is the last guardrail against an accidental `az group delete` across the subscription - Removing it is usually the FIRST step of a destructive sequence - Nothing else is destroyed by this command itself Inspect the lock before removing it: az account lock show --name LOCK
  19. account-management-group-hierarchy-settings-delete

    High

    az account management-group hierarchy-settings delete drops tenant-root hierarchy settings.

    Explanation
    account management-group hierarchy-settings delete removes settings that can only be defined on the ROOT management group: - `requireAuthorizationForGroupCreation` reverts, so any user may create management groups again - `defaultManagementGroup` reverts to the root group, so NEW subscriptions land outside their intended policy scope Capture the current settings first: az account management-group hierarchy-settings list --name ROOT-GROUP
  20. account-management-group-subscription-remove

    High

    az account management-group subscription remove detaches a subscription from its management group.

    Explanation
    account management-group subscription remove reparents a subscription: - The subscription moves to the tenant root group - Policy assignments, initiatives and RBAC inherited from the old group stop applying immediately — controls silently disappear - Cost/management reporting grouped by the old hierarchy changes Re-attach with: az account management-group subscription add --name GROUP --subscription SUB
  21. acr-repository-delete

    High

    az acr repository delete permanently deletes the repository and its images.

    Explanation
    acr repository delete removes repository: - All tags and images in repository deleted - Running containers unaffected (cached) - New pulls will fail List tags: az acr repository show-tags --name REG --repository REPO
  22. blob-delete

    High

    az storage blob/container delete permanently removes data.

    Explanation
    storage blob/container delete removes data: - Blob delete removes individual blobs - Container delete removes container and ALL blobs - Soft delete may allow recovery if enabled Check soft delete: az storage account show --name NAME --query blobServiceProperties
  23. functionapp-delete

    High

    az functionapp delete removes the Azure Function App.

    Explanation
    functionapp delete removes Azure Functions: - All functions and configuration deleted - Triggers and bindings removed - Function keys lost - Associated storage may be affected Export functions if not in version control.
  24. monitor-log-profiles-delete

    High

    az monitor log-profiles delete removes a subscription activity-log export — compliance/forensics.

    Explanation
    monitor log-profiles delete stops exporting the Azure activity log: - Historical entries at the destination (Storage/Event Hub) are preserved - Future activity events stop flowing to the configured export - Compliance audit (SOC2, ISO 27001, FedRAMP) may require this profile Each subscription only supports one log profile at a time.
  25. role-assignment-delete

    High

    az role assignment delete removes an RBAC binding — users/SPs lose permissions.

    Explanation
    role assignment delete revokes an RBAC assignment: - The target user / service principal / group loses the role's permissions - Can cascade — CI/CD pipelines, workloads, operators lose access - Re-adding via `az role assignment create` is possible if IDs are known List bindings first: az role assignment list --assignee PRINCIPAL-ID
  26. vnet-delete

    High

    az network vnet delete removes the virtual network.

    Explanation
    network vnet delete removes virtual network: - Network must be empty (no subnets in use) - Connected resources lose connectivity - Peerings to other VNets broken - Network security groups may remain Check usage: az network vnet subnet list --vnet-name VNET -g RG
  27. webapp-delete

    High

    az webapp delete removes the App Service.

    Explanation
    webapp delete removes App Service: - Application code and configuration deleted - Custom domain mappings removed - SSL certificates may be deleted - Deployment slots also deleted Backup config: az webapp config show --name NAME -g RG
  28. account-clear

    Medium

    az account clear wipes every cached subscription and credential from the local CLI profile.

    Explanation
    account clear empties the local Azure CLI account cache: - All logged-in accounts and cached subscriptions are removed - Nothing in Azure is destroyed, but every later `az` command in this environment fails until `az login` runs again - Automation running under a service principal loses its context To drop only the current subscription, use `az logout`.
  29. acr-repository-untag

    Medium

    az acr repository untag removes tags from images.

    Explanation
    acr repository untag removes image tags: - Tag removed from manifest - Image still exists if other tags reference it - Untagged images may be garbage collected Lower risk: manifests can be re-tagged if digest known.

Safe patterns

Checked first. A command that matches one is never blocked by this pack.

  • az-show
  • az-list
  • az-help
  • az-help-short
  • az-deployment-what-if
  • az-deployment-create-what-if