Gallery › Storage › Azure Community Policy
Restrict cloud shell storage account creation
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
Storage accounts that you create in Cloud Shell are tagged with ms-resource-usage:azure-cloud-shell. If you want to disallow users from creating storage accounts in Cloud Shell, create an Azure resource policy for tags that is triggered by this specific tag. https://learn.microsoft.com/en-us/azure/cloud-shell/persisting-shell-storage#restrict-resource-creation-with-an-azure-resource-policy
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 45 lines
{
"name": "dab3c67a-5f00-47ec-bba6-cc6984c33ae0",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Restrict cloud shell storage account creation",
"description": "Storage accounts that you create in Cloud Shell are tagged with ms-resource-usage:azure-cloud-shell. If you want to disallow users from creating storage accounts in Cloud Shell, create an Azure resource policy for tags that is triggered by this specific tag. https://learn.microsoft.com/en-us/azure/cloud-shell/persisting-shell-storage#restrict-resource-creation-with-an-azure-resource-policy",
"metadata": {
"category": "Storage",
"version": "1.0.0"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Deny, Audit or Disabled the execution of the Policy"
},
"allowedValues": [
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"field": "tags['ms-resource-usage']",
"equals": "azure-cloud-shell"
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylawdab3c67a-5f00-47ec-bba6-cc6984c33ae0.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'dab3c67a-5f00-47ec-bba6-cc6984c33ae0' {
Properties @{
DisplayName = 'Restrict cloud shell storage account creation'
Description = 'Storage accounts that you create in Cloud Shell are tagged with ms-resource-usage:azure-cloud-shell. If you want to disallow users from creating storage accounts in Cloud Shell, create an Azure resource policy for tags that is triggered by this specific tag. https://learn.microsoft.com/en-us/azure/cloud-shell/persisting-shell-storage#restrict-resource-creation-with-an-azure-resource-policy'
Category = 'Storage'
Version = '1.0.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource 'Microsoft.Storage/storageAccounts' {
Require 'tag ms-resource-usage is not azure-cloud-shell' {
Tag 'ms-resource-usage' | Must -Not -Be 'azure-cloud-shell' -IfPresent
}
}
Effect (Param Effect)
}Source: policyDefinitions/Storage/restrict-cloud-shell-storage-account-creation/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw