Gallery › SQL › Azure Community Policy
Audit SQL Server virtual network rule
Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0
Audits the existence of a rule that enables traffic from a SQL Server to a specific subnet.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 50 lines
{
"name": "b5aca59d-3f7f-45c2-8556-cbb60dec89c7",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Audit SQL Server virtual network rule",
"description": "Audits the existence of a rule that enables traffic from a SQL Server to a specific subnet.",
"metadata": {
"version": "1.0.0",
"category": "SQL"
},
"mode": "All",
"parameters": {
"subnetId": {
"type": "string",
"metadata": {
"displayName": "Subnet ID",
"description": "The resource ID of the virtual network subnet that should have a rule enabled. Example: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "AuditIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Sql/servers"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"existenceCondition": {
"field": "Microsoft.Sql/servers/virtualNetworkRules/virtualNetworkSubnetId",
"equals": "[parameters('subnetId')]"
}
}
}
}
}
}Bylawb5aca59d-3f7f-45c2-8556-cbb60dec89c7.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'b5aca59d-3f7f-45c2-8556-cbb60dec89c7' {
Properties @{
DisplayName = 'Audit SQL Server virtual network rule'
Description = 'Audits the existence of a rule that enables traffic from a SQL Server to a specific subnet.'
Version = '1.0.0'
Category = 'SQL'
Mode = 'All'
}
Parameter SubnetId @{
Type = 'string'
DisplayName = 'Subnet ID'
Description = 'The resource ID of the virtual network subnet that should have a rule enabled. Example: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet'
}
Parameter Effect @{
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Sql/servers'
AuditIfNotExists 'Microsoft.Sql/servers/virtualNetworkRules' -Effect (Param Effect) {
Require 'virtualNetworkSubnetId is the SubnetId parameter' {
Field virtualNetworkSubnetId | Must -Be (Param SubnetId)
}
}
}Source: policyDefinitions/SQL/audit-sql-server-virtual-network-rule/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw