Bylaw

Gallery › SQL › Azure built-in policies

Private endpoint should be enabled for MySQL servers

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.2

Private endpoint connections enforce secure communication by enabling private connectivity to Azure Database for MySQL. Configure a private endpoint connection to enable access to traffic coming only from known networks and prevent access from all other IP addresses, including within Azure.

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

Azure Policy JSONMySQL_EnablePrivateEndPoint_Audit.json · 48 lines
{
  "properties": {
    "displayName": "Private endpoint should be enabled for MySQL servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Private endpoint connections enforce secure communication by enabling private connectivity to Azure Database for MySQL. Configure a private endpoint connection to enable access to traffic coming only from known networks and prevent access from all other IP addresses, including within Azure.",
    "metadata": {
      "version": "1.0.2",
      "category": "SQL"
    },
    "version": "1.0.2",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.DBforMySQL/servers"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.DBforMySQL/servers/privateEndpointConnections",
          "existenceCondition": {
            "field": "Microsoft.DBforMySQL/servers/privateEndpointConnections/privateLinkServiceConnectionState.status",
            "equals": "Approved"
          }
        }
      }
    },
    "versions": [
      "1.0.2"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/7595c971-233d-4bcf-bd18-596129188c49",
  "name": "7595c971-233d-4bcf-bd18-596129188c49"
}
Bylaw7595c971-233d-4bcf-bd18-596129188c49.bylaw.ps1 · 28 lines
# Converted from MySQL_EnablePrivateEndPoint_Audit.json by ConvertTo-Bylaw.
Policy '7595c971-233d-4bcf-bd18-596129188c49' {

    Properties @{
        DisplayName   = 'Private endpoint should be enabled for MySQL servers'
        Description   = 'Private endpoint connections enforce secure communication by enabling private connectivity to Azure Database for MySQL. Configure a private endpoint connection to enable access to traffic coming only from known networks and prevent access from all other IP addresses, including within Azure.'
        Version       = '1.0.2'
        Category      = 'SQL'
        PolicyVersion = '1.0.2'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.DBforMySQL/servers'

    AuditIfNotExists 'Microsoft.DBforMySQL/servers/privateEndpointConnections' -Effect (Param Effect) {
        Require 'privateLinkServiceConnectionState.status is Approved' {
            Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
        }
    }
}

Source: built-in-policies/policyDefinitions/SQL/MySQL_EnablePrivateEndPoint_Audit.json in Azure/azure-policy, under the MIT licence.