Bylaw

Gallery › SQL › Azure built-in policies

Enforce SSL connection should be enabled for MySQL database servers

Converted Policy Audit Disabled Mode Indexed Version 1.0.1

Azure Database for MySQL supports connecting your Azure Database for MySQL server to client applications using Secure Sockets Layer (SSL). Enforcing SSL connections between your database server and your client applications helps protect against 'man in the middle' attacks by encrypting the data stream between the server and your application. This configuration enforces that SSL is always enabled for accessing your database server.

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

Azure Policy JSONMySQL_EnableSSL_Audit.json · 53 lines
{
  "properties": {
    "displayName": "Enforce SSL connection should be enabled for MySQL database servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Azure Database for MySQL supports connecting your Azure Database for MySQL server to client applications using Secure Sockets Layer (SSL). Enforcing SSL connections between your database server and your client applications helps protect against 'man in the middle' attacks by encrypting the data stream between the server and your application. This configuration enforces that SSL is always enabled for accessing your database server.",
    "metadata": {
      "version": "1.0.1",
      "category": "SQL"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DBforMySQL/servers"
          },
          {
            "field": "Microsoft.DBforMySQL/servers/sslEnforcement",
            "exists": "true"
          },
          {
            "field": "Microsoft.DBforMySQL/servers/sslEnforcement",
            "notEquals": "Enabled"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/e802a67a-daf5-4436-9ea6-f6d821dd0c5d",
  "name": "e802a67a-daf5-4436-9ea6-f6d821dd0c5d"
}
Bylawe802a67a-daf5-4436-9ea6-f6d821dd0c5d.bylaw.ps1 · 33 lines
# Converted from MySQL_EnableSSL_Audit.json by ConvertTo-Bylaw.
Policy 'e802a67a-daf5-4436-9ea6-f6d821dd0c5d' {

    Properties @{
        DisplayName   = 'Enforce SSL connection should be enabled for MySQL database servers'
        Description   = 'Azure Database for MySQL supports connecting your Azure Database for MySQL server to client applications using Secure Sockets Layer (SSL). Enforcing SSL connections between your database server and your client applications helps protect against ''man in the middle'' attacks by encrypting the data stream between the server and your application. This configuration enforces that SSL is always enabled for accessing your database server.'
        Version       = '1.0.1'
        Category      = 'SQL'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.DBforMySQL/servers' {

        When {
            Field sslEnforcement | Must -Exist
        }

        Require 'sslEnforcement is Enabled' {
            Field sslEnforcement | Must -Be 'Enabled'
        }
    }

    Effect (Param Effect)
}

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