This sample demonstrates how to create an Azure Policy definition that enforces secure transfer for Azure Storage accounts. This policy helps ensure that data stored in Azure Storage is protected by requiring that all communications with the storage account are performed over HTTPS.
The following JSON defines the Azure Policy for secure transfer. This definition specifies that if a storage account is created or updated, and its secure transfer setting is disabled, the policy will deny the action.
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"anyOf": [
{
"field": "Microsoft.Storage/storageAccounts/supportsHttpsTrafficOnly",
"exists": "false"
},
{
"field": "Microsoft.Storage/storageAccounts/supportsHttpsTrafficOnly",
"equals": false
}
]
}
]
},
"then": {
"effect": "Deny"
}
},
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "The effect of the policy on the resource."
},
"allowedValues": [
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Deny"
}
}
}
All to evaluate all resource types.Microsoft.Storage/storageAccounts: Ensures the policy applies only to storage accounts.anyOf block checks if the supportsHttpsTrafficOnly property is either not set (implicitly false) or explicitly set to false.if block are met.
Audit (to log non-compliant resources) or Disabled (to turn off the policy).effect parameter can be changed when assigning the policy to choose between Deny, Audit, or Disabled.When using the Deny effect, be aware that it will block the creation or modification of storage accounts that do not meet the secure transfer requirement. Ensure this aligns with your organizational security policies.
You can deploy this policy using the Azure portal, Azure CLI, or Azure PowerShell.
Save the policy definition to a file named policyDefinition.json.
Run the following command to create the policy definition:
az policy definition create --name "SecureTransferForStorage" --display-name "Azure Storage Secure Transfer Required" --description "Enforces that all Azure Storage accounts require secure transfer enabled." --rules policyDefinition.json --params policyDefinition.json
Assign the policy definition to a scope (e.g., subscription or resource group):
az policy assignment create --name "SecureTransferAssignment" --display-name "Enforce Secure Transfer for Storage" --scope "/subscriptions/YOUR_SUBSCRIPTION_ID" --policy "SecureTransferForStorage" --params '{ "effect": "Deny" }'
Replace YOUR_SUBSCRIPTION_ID with your actual Azure subscription ID.
Azure Storage Secure Transfer Required) and Description.Deny).