Bylaw

Gallery › SQL › Azure Community Policy

Audit private endpoint connections setting for Azure SQL Database

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

Customers enable private endpoint connections to enable private connectivity to Azure SQL Database. This policy audits that private endpoint connections are in use.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONazurepolicy.json · 56 lines
{
  "name": "b44a8c73-72a5-4197-a446-76bc583fb382",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit private endpoint connections setting for Azure SQL Database",
    "description": "Customers enable private endpoint connections to enable private connectivity to Azure SQL Database. This policy audits that private endpoint connections are in use.",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "All",
    "parameters": {
      "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": {
          "name": "default",
          "type": "Microsoft.Sql/servers/privateEndpointConnections",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Sql/servers/privateEndpointConnections/privateEndpoint",
                "exists": true
              },
              {
                "field": "Microsoft.Sql/servers/privateEndpointConnections/privateLinkServiceConnectionState.status",
                "equals": "Approved"
              },
              {
                "field": "Microsoft.Sql/servers/privateEndpointConnections/provisioningState",
                "equals": "Ready"
              }
            ]
          }
        }
      }
    }
  }
}
Bylawb44a8c73-72a5-4197-a446-76bc583fb382.bylaw.ps1 · 28 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'b44a8c73-72a5-4197-a446-76bc583fb382' {

    Properties @{
        DisplayName = 'Audit private endpoint connections setting for Azure SQL Database'
        Description = 'Customers enable private endpoint connections to enable private connectivity to Azure SQL Database. This policy audits that private endpoint connections are in use.'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'All'
    }

    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/privateEndpointConnections' -Name 'default' -Effect (Param Effect) {
        Require 'privateEndpoint, privateLinkServiceConnectionState.status and provisioningState are as required' {
            Field privateEndpoint | Must -Exist
            Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
            Field provisioningState | Must -Be 'Ready'
        }
    }
}

Source: policyDefinitions/SQL/audit-private-endpoint-connections-setting-for-azure-sql-database/azurepolicy.json in Azure/Community-Policy, under the MIT licence.