Gallery › Storage › Azure built-in policies
Configure Storage account to use a private link connection
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Private endpoints connect your virtual network to Azure services without a public IP address at the source or destination. By mapping private endpoints to your storage account, you can reduce data leakage risks. Learn more about private links at - https://aka.ms/azureprivatelinkoverview
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONStorageAccountPrivateEndpointEnabled_DINE.json · 207 lines
{
"properties": {
"displayName": "Configure Storage account to use a private link connection",
"description": "Private endpoints connect your virtual network to Azure services without a public IP address at the source or destination. By mapping private endpoints to your storage account, you can reduce data leakage risks. Learn more about private links at - https://aka.ms/azureprivatelinkoverview",
"policyType": "BuiltIn",
"mode": "Indexed",
"metadata": {
"version": "1.0.0",
"category": "Storage"
},
"version": "1.0.0",
"parameters": {
"privateEndpointSubnetId": {
"type": "String",
"metadata": {
"displayName": "Private endpoint subnet id",
"description": "The subnetId that private endpoint connections should link to",
"strongType": "Microsoft.Network/virtualNetworks/subnets"
}
},
"targetSubResource": {
"type": "String",
"metadata": {
"displayName": "Target sub-resource",
"description": "Type of sub-resource for the resource selected above, that your private endpoint will be able to access"
},
"defaultValue": "blob",
"allowedValues": [
"blob",
"blob_secondary",
"table",
"table_secondary",
"queue",
"queue_secondary",
"file",
"web",
"web_secondary",
"dfs",
"dfs_secondary"
]
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"field": "kind",
"in": [
"StorageV2",
"BlobStorage",
"BlockBlobStorage",
"FileStorage"
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Storage/storageAccounts/privateEndpointConnections",
"existenceCondition": {
"field": "Microsoft.Storage/storageAccounts/privateEndpointConnections/privateLinkServiceConnectionState.status",
"equals": "Approved"
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7",
"/providers/Microsoft.Authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab"
],
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"name": {
"value": "[field('name')]"
},
"serviceId": {
"value": "[field('id')]"
},
"privateEndpointSubnetId": {
"value": "[parameters('privateEndpointSubnetId')]"
},
"targetSubResource": {
"value": "[parameters('targetSubResource')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
},
"serviceId": {
"type": "string"
},
"privateEndpointSubnetId": {
"type": "string"
},
"targetSubResource": {
"type": "string"
}
},
"variables": {
"privateEndpointName": "[concat('pe-',substring(parameters('name'),0,min(length(parameters('name')),50)),'-',uniquestring(deployment().name))]"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"name": "[variables('privateEndpointName')]",
"apiVersion": "2020-06-01",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serviceId": {
"type": "string"
},
"privateEndpointSubnetId": {
"type": "string"
},
"targetSubResource": {
"type": "string"
},
"subnetLocation": {
"type": "string"
}
},
"variables": {
"privateEndpointName": "[deployment().name]"
},
"resources": [
{
"name": "[variables('privateEndpointName')]",
"type": "Microsoft.Network/privateEndpoints",
"apiVersion": "2020-07-01",
"location": "[parameters('subnetLocation')]",
"tags": {},
"properties": {
"subnet": {
"id": "[parameters('privateEndpointSubnetId')]"
},
"privateLinkServiceConnections": [
{
"name": "[variables('privateEndpointName')]",
"properties": {
"privateLinkServiceId": "[parameters('serviceId')]",
"groupIds": "[array(parameters('targetSubResource'))]",
"requestMessage": "autoapprove"
}
}
],
"manualPrivateLinkServiceConnections": []
}
}
]
},
"parameters": {
"serviceId": {
"value": "[parameters('serviceId')]"
},
"privateEndpointSubnetId": {
"value": "[parameters('privateEndpointSubnetId')]"
},
"targetSubResource": {
"value": "[parameters('targetSubResource')]"
},
"subnetLocation": {
"value": "[reference(first(take(split(parameters('privateEndpointSubnetId'),'/subnets'),1)),'2020-07-01','Full').location]"
}
}
}
}
]
}
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/9f766f00-8d11-464e-80e1-4091d7874074",
"name": "9f766f00-8d11-464e-80e1-4091d7874074"
}Bylaw9f766f00-8d11-464e-80e1-4091d7874074.bylaw.ps1 · 50 lines
# Converted from StorageAccountPrivateEndpointEnabled_DINE.json by ConvertTo-Bylaw.
Policy '9f766f00-8d11-464e-80e1-4091d7874074' {
Properties @{
DisplayName = 'Configure Storage account to use a private link connection'
Description = 'Private endpoints connect your virtual network to Azure services without a public IP address at the source or destination. By mapping private endpoints to your storage account, you can reduce data leakage risks. Learn more about private links at - https://aka.ms/azureprivatelinkoverview'
Version = '1.0.0'
Category = 'Storage'
PolicyVersion = '1.0.0'
Mode = 'Indexed'
}
Parameter PrivateEndpointSubnetId @{
Type = 'String'
DisplayName = 'Private endpoint subnet id'
Description = 'The subnetId that private endpoint connections should link to'
Metadata = [ordered]@{ strongType = 'Microsoft.Network/virtualNetworks/subnets' }
}
Parameter TargetSubResource @{
AllowedValues = @('blob', 'blob_secondary', 'table', 'table_secondary', 'queue', 'queue_secondary', 'file', 'web', 'web_secondary', 'dfs', 'dfs_secondary')
Default = 'blob'
DisplayName = 'Target sub-resource'
Description = 'Type of sub-resource for the resource selected above, that your private endpoint will be able to access'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.Storage/storageAccounts' {
Require 'kind is not one of 4 values' {
Field kind | Must -Not -BeIn @('StorageV2', 'BlobStorage', 'BlockBlobStorage', 'FileStorage') -IfPresent
}
}
DeployIfNotExists 'Microsoft.Storage/storageAccounts/privateEndpointConnections' -Role 'Network Contributor', 'Storage Account Contributor' -Effect (Param Effect) {
Require 'privateLinkServiceConnectionState.status is Approved' {
Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
}
Deployment -TemplateFile './templates/9f766f00-8d11-464e-80e1-4091d7874074.json' -Parameters ([ordered]@{
name = (Arm '[field(''name'')]')
serviceId = (Arm '[field(''id'')]')
privateEndpointSubnetId = (Param PrivateEndpointSubnetId)
targetSubResource = (Param TargetSubResource)
})
}
}Its deployment templates are written beside it:
templates/9f766f00-8d11-464e-80e1-4091d7874074.json
Source: built-in-policies/policyDefinitions/Storage/StorageAccountPrivateEndpointEnabled_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw