Bylaw

Gallery › SQL › Azure Landing Zones Library

SQL managed instances deploy a specific min TLS version requirement.

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.3.0

Deploy a specific min TLS version requirement and enforce SSL on SQL managed instances. Enables secure server to client by enforce minimal Tls Version 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-SqlMi-minTLS.alz_policy_definition.json · 124 lines
{
  "name": "Deploy-SqlMi-minTLS",
  "properties": {
    "description": "Deploy a specific min TLS version requirement and enforce SSL on SQL managed instances. Enables secure server to client by enforce  minimal Tls Version 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": "SQL managed instances deploy a specific min TLS version requirement.",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "SQL",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.3.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists",
        "metadata": {
          "description": "Enable or disable the execution of the policy minimum TLS version SQL servers",
          "displayName": "Effect SQL servers"
        },
        "type": "String"
      },
      "minimalTlsVersion": {
        "allowedValues": [
          "1.2",
          "1.1",
          "1.0"
        ],
        "defaultValue": "1.2",
        "metadata": {
          "description": "Select version minimum TLS version SQL servers to enforce",
          "displayName": "Select version for SQL server"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.Sql/managedInstances",
            "field": "type"
          },
          {
            "field": "Microsoft.Sql/managedInstances/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": "2020-02-02-preview",
                    "location": "[parameters('location')]",
                    "name": "[concat(parameters('resourceName'))]",
                    "properties": {
                      "minimalTlsVersion": "[parameters('minimalTlsVersion')]"
                    },
                    "type": "Microsoft.Sql/managedInstances"
                  }
                ],
                "variables": {}
              }
            }
          },
          "evaluationDelay": "AfterProvisioningSuccess",
          "existenceCondition": {
            "allOf": [
              {
                "equals": "[parameters('minimalTlsVersion')]",
                "field": "Microsoft.Sql/managedInstances/minimalTlsVersion"
              }
            ]
          },
          "name": "current",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/4939a1f6-9ae0-4e48-a1e0-f2cbe897382d"
          ],
          "type": "Microsoft.Sql/managedInstances"
        },
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeploy-SqlMi-minTLS.bylaw.ps1 · 43 lines
# Converted from Deploy-SqlMi-minTLS.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deploy-SqlMi-minTLS' {

    Properties @{
        DisplayName = 'SQL managed instances deploy a specific min TLS version requirement.'
        Description = 'Deploy a specific min TLS version requirement and enforce SSL on SQL managed instances. Enables secure server to client by enforce  minimal Tls Version 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.3.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 SQL servers'
        Description   = 'Enable or disable the execution of the policy minimum TLS version SQL servers'
    }
    Parameter MinimalTlsVersion @{
        AllowedValues = @('1.2', '1.1', '1.0')
        Default       = '1.2'
        DisplayName   = 'Select version for SQL server'
        Description   = 'Select version minimum TLS version SQL servers to enforce'
    }

    Resource 'Microsoft.Sql/managedInstances' {

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

    DeployIfNotExists 'Microsoft.Sql/managedInstances' -Role 'SQL Managed Instance Contributor' -Name 'current' -EvaluationDelay AfterProvisioningSuccess -Effect (Param Effect) {
        Require 'minimalTlsVersion is the MinimalTlsVersion parameter' {
            Field minimalTlsVersion | Must -Be (Param MinimalTlsVersion)
        }
        Deployment -TemplateFile './templates/Deploy-SqlMi-minTLS.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-SqlMi-minTLS.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.