Bylaw

Gallery › SQL › Azure Landing Zones Library

Azure Database for MySQL server deploy a specific min TLS version and enforce SSL.

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.2.0

Deploy a specific min TLS version requirement and enforce SSL on Azure Database for MySQL server. Enforce the Server to client applications using minimum version of Tls to secure the connection 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 JSONDeploy-MySQL-sslEnforcement.alz_policy_definition.json · 136 lines
{
  "name": "Deploy-MySQL-sslEnforcement",
  "properties": {
    "description": "Deploy a specific min TLS version requirement and enforce SSL on Azure Database for MySQL server. Enforce the Server to client applications using minimum version of Tls to secure the connection 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.",
    "displayName": "Azure Database for MySQL server deploy a specific min TLS version and enforce SSL.",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "SQL",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.2.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists",
        "metadata": {
          "description": "Enable or disable the execution of the policy minimum TLS version Azure Database for MySQL server",
          "displayName": "Effect minimum TLS version Azure Database for MySQL server"
        },
        "type": "String"
      },
      "minimalTlsVersion": {
        "allowedValues": [
          "TLS1_2",
          "TLS1_0",
          "TLS1_1",
          "TLSEnforcementDisabled"
        ],
        "defaultValue": "TLS1_2",
        "metadata": {
          "description": "Select version  minimum TLS version Azure Database for MySQL server to enforce",
          "displayName": "Select version minimum TLS for MySQL server"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.DBforMySQL/servers",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.DBforMySQL/servers/sslEnforcement",
                "notEquals": "Enabled"
              },
              {
                "field": "Microsoft.DBforMySQL/servers/minimalTlsVersion",
                "less": "[parameters('minimalTlsVersion')]"
              }
            ]
          }
        ]
      },
      "then": {
        "details": {
          "deployment": {
            "properties": {
              "mode": "Incremental",
              "parameters": {
                "location": {
                  "value": "[field('location')]"
                },
                "minimalTlsVersion": {
                  "value": "[parameters('minimalTlsVersion')]"
                },
                "resourceName": {
                  "value": "[field('name')]"
                }
              },
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "outputs": {},
                "parameters": {
                  "location": {
                    "type": "String"
                  },
                  "minimalTlsVersion": {
                    "type": "String"
                  },
                  "resourceName": {
                    "type": "String"
                  }
                },
                "resources": [
                  {
                    "apiVersion": "2017-12-01",
                    "location": "[parameters('location')]",
                    "name": "[concat(parameters('resourceName'))]",
                    "properties": {
                      "minimalTlsVersion": "[parameters('minimalTlsVersion')]",
                      "sslEnforcement": "[if(equals(parameters('minimalTlsVersion'), 'TLSEnforcementDisabled'),'Disabled', 'Enabled')]"
                    },
                    "type": "Microsoft.DBforMySQL/servers"
                  }
                ],
                "variables": {}
              }
            }
          },
          "existenceCondition": {
            "allOf": [
              {
                "equals": "Enabled",
                "field": "Microsoft.DBforMySQL/servers/sslEnforcement"
              },
              {
                "equals": "[parameters('minimalTlsVersion')]",
                "field": "Microsoft.DBforMySQL/servers/minimalTlsVersion"
              }
            ]
          },
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "type": "Microsoft.DBforMySQL/servers"
        },
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeploy-MySQL-sslEnforcement.bylaw.ps1 · 48 lines
# Converted from Deploy-MySQL-sslEnforcement.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deploy-MySQL-sslEnforcement' {

    Properties @{
        DisplayName = 'Azure Database for MySQL server deploy a specific min TLS version and enforce SSL.'
        Description = 'Deploy a specific min TLS version requirement and enforce SSL on Azure Database for MySQL server. Enforce the Server to client applications using minimum version of Tls to secure the connection 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.'
        Category    = 'SQL'
        Version     = '1.2.0'
        Mode        = 'Indexed'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect minimum TLS version Azure Database for MySQL server'
        Description   = 'Enable or disable the execution of the policy minimum TLS version Azure Database for MySQL server'
    }
    Parameter MinimalTlsVersion @{
        AllowedValues = @('TLS1_2', 'TLS1_0', 'TLS1_1', 'TLSEnforcementDisabled')
        Default       = 'TLS1_2'
        DisplayName   = 'Select version minimum TLS for MySQL server'
        Description   = 'Select version  minimum TLS version Azure Database for MySQL server to enforce'
    }

    Resource 'Microsoft.DBforMySQL/servers' {

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

        Require 'minimalTlsVersion is at least the MinimalTlsVersion parameter' {
            Field minimalTlsVersion | Must -BeGreaterOrEqual (Param MinimalTlsVersion) -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.DBforMySQL/servers' -Role 'Contributor' -Effect (Param Effect) {
        Require 'sslEnforcement is Enabled and minimalTlsVersion is the MinimalTlsVersion parameter' {
            Field sslEnforcement | Must -Be 'Enabled'
            Field minimalTlsVersion | Must -Be (Param MinimalTlsVersion)
        }
        Deployment -TemplateFile './templates/Deploy-MySQL-sslEnforcement.json' -Parameters ([ordered]@{
                location          = (Arm '[field(''location'')]')
                minimalTlsVersion = (Param MinimalTlsVersion)
                resourceName      = (Arm '[field(''name'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: policy_definitions/Deploy-MySQL-sslEnforcement.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.