Gallery › Key Vault › Azure Community Policy
Enable soft-delete and purge protection on Key Vaults
Doesn't convert yet Policy Audit Deny Disabled Modify Mode All Version 2.0.0
This Policy will enable soft-delete and purge protection on all Key Vaults.
ConvertTo-Bylaw can't convert this policy yet:
- BYL6003 The converted file doesn't compile, which is a ConvertTo-Bylaw bug: BYL3062: Effect parameter 'Effect' of a Modify policy allows 'Deny'. Allowed values: Modify, Audit, Disabled. A Modify policy changes the request, so it never denies it.
Azure Policy JSONazurepolicy.json · 79 lines
{
"name": "29162fc6-7a8f-4cd4-98d8-99ac1bffa6e5",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Enable soft-delete and purge protection on Key Vaults",
"description": "This Policy will enable soft-delete and purge protection on all Key Vaults.",
"metadata": {
"category": "Key Vault",
"version": "2.0.0"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Modify, Deny, Audit, or Disabled"
},
"allowedValues": [
"Modify",
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Modify"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.KeyVault/vaults"
},
{
"anyOf": [
{
"field": "Microsoft.KeyVault/vaults/enableSoftDelete",
"exists": "false"
},
{
"field": "Microsoft.KeyVault/vaults/enablePurgeProtection",
"exists": "false"
},
{
"field": "Microsoft.KeyVault/vaults/enablePurgeProtection",
"equals": "false"
},
{
"field": "Microsoft.KeyVault/vaults/enableSoftDelete",
"equals": "false"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/f25e0fa2-a7c8-4377-a976-54943a77a395"
],
"operations": [
{
"operation": "addOrReplace",
"field": "Microsoft.KeyVault/vaults/enableSoftDelete",
"value": true
},
{
"operation": "addOrReplace",
"field": "Microsoft.KeyVault/vaults/enablePurgeProtection",
"value": true
}
]
}
}
}
}
}Source: policyDefinitions/Key Vault/enable-soft-delete-and-purge-protection-on-key-vaults/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw