Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Audit Azure resources for compliance, security best practices, and Key Vault expiration monitoring
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/azqr-remediation-patterns.md
1# Remediation Patterns for Common azqr Findings23This document provides remediation templates for frequently identified compliance issues.45## Storage Account Issues67### Enable Private Endpoints89**Issue:** Storage account accessible via public endpoint1011**Azure CLI:**12```bash13# Create private endpoint14az network private-endpoint create \15--name pe-storage \16--resource-group <rg-name> \17--vnet-name <vnet-name> \18--subnet <subnet-name> \19--private-connection-resource-id $(az storage account show -n <storage-name> -g <rg-name> --query id -o tsv) \20--group-id blob \21--connection-name pe-storage-connection2223# Disable public access24az storage account update \25--name <storage-name> \26--resource-group <rg-name> \27--public-network-access Disabled28```2930**Bicep:**31```bicep32resource privateEndpoint 'Microsoft.Network/privateEndpoints@2023-05-01' = {33name: 'pe-${storageAccount.name}'34location: location35properties: {36subnet: {37id: subnet.id38}39privateLinkServiceConnections: [40{41name: 'pe-${storageAccount.name}-connection'42properties: {43privateLinkServiceId: storageAccount.id44groupIds: ['blob']45}46}47]48}49}50```5152### Enable Soft Delete5354**Issue:** No soft delete protection for blobs5556**Azure CLI:**57```bash58az storage account blob-service-properties update \59--account-name <storage-name> \60--resource-group <rg-name> \61--enable-delete-retention true \62--delete-retention-days 7 \63--enable-container-delete-retention true \64--container-delete-retention-days 765```6667**Bicep:**68```bicep69resource blobServices 'Microsoft.Storage/storageAccounts/blobServices@2023-01-01' = {70parent: storageAccount71name: 'default'72properties: {73deleteRetentionPolicy: {74enabled: true75days: 776}77containerDeleteRetentionPolicy: {78enabled: true79days: 780}81}82}83```8485---8687## Key Vault Issues8889### Enable Purge Protection9091**Issue:** Key Vault can be permanently deleted9293**Azure CLI:**94```bash95az keyvault update \96--name <vault-name> \97--resource-group <rg-name> \98--enable-purge-protection true99```100101**Bicep:**102```bicep103resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {104name: keyVaultName105location: location106properties: {107enableSoftDelete: true108softDeleteRetentionInDays: 90109enablePurgeProtection: true110// ... other properties111}112}113```114115### Use RBAC for Data Plane116117**Issue:** Using access policies instead of RBAC118119**Azure CLI:**120```bash121az keyvault update \122--name <vault-name> \123--resource-group <rg-name> \124--enable-rbac-authorization true125```126127---128129## Virtual Machine Issues130131### Enable Diagnostic Settings132133**Issue:** No diagnostics configured for VM134135**Azure CLI:**136```bash137# Create Log Analytics workspace (if needed)138az monitor log-analytics workspace create \139--resource-group <rg-name> \140--workspace-name <workspace-name>141142# Enable diagnostics143az monitor diagnostic-settings create \144--name diag-vm \145--resource $(az vm show -g <rg-name> -n <vm-name> --query id -o tsv) \146--workspace $(az monitor log-analytics workspace show -g <rg-name> -n <workspace-name> --query id -o tsv) \147--metrics '[{"category": "AllMetrics", "enabled": true}]'148```149150**Bicep:**151```bicep152resource diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {153name: 'diag-${vm.name}'154scope: vm155properties: {156workspaceId: logAnalyticsWorkspace.id157metrics: [158{159category: 'AllMetrics'160enabled: true161}162]163}164}165```166167### Enable Azure Backup168169**Issue:** VM not protected by Azure Backup170171**Azure CLI:**172```bash173# Create Recovery Services vault (if needed)174az backup vault create \175--resource-group <rg-name> \176--name <vault-name> \177--location <location>178179# Enable backup with default policy180az backup protection enable-for-vm \181--resource-group <rg-name> \182--vault-name <vault-name> \183--vm $(az vm show -g <rg-name> -n <vm-name> --query id -o tsv) \184--policy-name DefaultPolicy185```186187---188189## AKS Issues190191### Enable Defender for Containers192193**Issue:** No security monitoring for AKS194195**Azure CLI:**196```bash197az aks update \198--resource-group <rg-name> \199--name <cluster-name> \200--enable-defender201```202203**Bicep:**204```bicep205resource aksCluster 'Microsoft.ContainerService/managedClusters@2024-01-01' = {206name: clusterName207location: location208properties: {209securityProfile: {210defender: {211securityMonitoring: {212enabled: true213}214logAnalyticsWorkspaceResourceId: logAnalyticsWorkspace.id215}216}217// ... other properties218}219}220```221222### Use Managed Identity223224**Issue:** AKS using service principal instead of managed identity225226**Azure CLI:**227```bash228az aks update \229--resource-group <rg-name> \230--name <cluster-name> \231--enable-managed-identity232```233234---235236## SQL Database Issues237238### Enable Auditing239240**Issue:** SQL Server auditing not enabled241242**Azure CLI:**243```bash244# Enable to Log Analytics245az sql server audit-policy update \246--resource-group <rg-name> \247--name <server-name> \248--state Enabled \249--lats Enabled \250--lawri $(az monitor log-analytics workspace show -g <rg-name> -n <workspace-name> --query id -o tsv)251```252253**Bicep:**254```bicep255resource sqlAudit 'Microsoft.Sql/servers/auditingSettings@2023-05-01-preview' = {256parent: sqlServer257name: 'default'258properties: {259state: 'Enabled'260isAzureMonitorTargetEnabled: true261retentionDays: 90262}263}264```265266### Enable Private Endpoint267268**Issue:** SQL Server accessible via public endpoint269270**Azure CLI:**271```bash272# Create private endpoint273az network private-endpoint create \274--name pe-sql \275--resource-group <rg-name> \276--vnet-name <vnet-name> \277--subnet <subnet-name> \278--private-connection-resource-id $(az sql server show -g <rg-name> -n <server-name> --query id -o tsv) \279--group-id sqlServer \280--connection-name pe-sql-connection281282# Disable public access283az sql server update \284--resource-group <rg-name> \285--name <server-name> \286--enable-public-network false287```288289---290291## App Service Issues292293### Use Managed Identity294295**Issue:** App Service not using managed identity296297**Azure CLI:**298```bash299az webapp identity assign \300--resource-group <rg-name> \301--name <app-name>302```303304**Bicep:**305```bicep306resource webApp 'Microsoft.Web/sites@2023-01-01' = {307name: appName308location: location309identity: {310type: 'SystemAssigned'311}312properties: {313// ... other properties314}315}316```317318### Enforce HTTPS Only319320**Issue:** HTTP traffic allowed321322**Azure CLI:**323```bash324az webapp update \325--resource-group <rg-name> \326--name <app-name> \327--https-only true328```329330### Set Minimum TLS Version331332**Issue:** TLS version below 1.2333334**Azure CLI:**335```bash336az webapp config set \337--resource-group <rg-name> \338--name <app-name> \339--min-tls-version 1.2340```341342---343344## Bulk Remediation Script345346For multiple resources of the same type, use a loop:347348```powershell349# Example: Enable soft delete on all storage accounts350$storageAccounts = az storage account list --query "[].{name:name, rg:resourceGroup}" -o json | ConvertFrom-Json351352foreach ($sa in $storageAccounts) {353Write-Host "Enabling soft delete on $($sa.name)..."354az storage account blob-service-properties update `355--account-name $sa.name `356--resource-group $sa.rg `357--enable-delete-retention true `358--delete-retention-days 7359}360```361362---363364## Remediation Validation365366After applying fixes, re-run the azqr scan using the Azure MCP tool to verify the issues have been resolved:367368```369mcp_azure_mcp_extension_azqr370subscription: <subscription-id>371```372373## Additional Resources374375- [Azure CLI Reference](https://learn.microsoft.com/cli/azure/)376- [Bicep Documentation](https://learn.microsoft.com/azure/azure-resource-manager/bicep/)377- [Azure Policy Built-in Definitions](https://learn.microsoft.com/azure/governance/policy/samples/built-in-policies)378