Bylaw

Gallery › SQL › Azure Landing Zones Library

Azure Database for PostgreSQL server deploy a specific min TLS version requirement 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 PostgreSQL server. 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-PostgreSQL-sslEnforcement.alz_policy_definition.json · 137 lines
{
  "name": "Deploy-PostgreSQL-sslEnforcement",
  "properties": {
    "description": "Deploy a specific min TLS version requirement and enforce SSL on Azure Database for PostgreSQL server. 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": "Azure Database for PostgreSQL server deploy a specific min TLS version requirement 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 PostgreSQL server",
          "displayName": "Effect Azure Database for PostgreSQL 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 PostgreSQL server to enforce",
          "displayName": "Select version for PostgreSQL server"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.DBforPostgreSQL/servers",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.DBforPostgreSQL/servers/sslEnforcement",
                "notEquals": "Enabled"
              },
              {
                "field": "Microsoft.DBforPostgreSQL/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.DBforPostgreSQL/servers"
                  }
                ],
                "variables": {}
              }
            }
          },
          "existenceCondition": {
            "allOf": [
              {
                "equals": "Enabled",
                "field": "Microsoft.DBforPostgreSQL/servers/sslEnforcement"
              },
              {
                "equals": "[parameters('minimalTlsVersion')]",
                "field": "Microsoft.DBforPostgreSQL/servers/minimalTlsVersion"
              }
            ]
          },
          "name": "current",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "type": "Microsoft.DBforPostgreSQL/servers"
        },
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeploy-PostgreSQL-sslEnforcement.bylaw.ps1 · 48 lines
# Converted from Deploy-PostgreSQL-sslEnforcement.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deploy-PostgreSQL-sslEnforcement' {

    Properties @{
        DisplayName = 'Azure Database for PostgreSQL server deploy a specific min TLS version requirement and enforce SSL '
        Description = 'Deploy a specific min TLS version requirement and enforce SSL on Azure Database for PostgreSQL server. 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.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 Azure Database for PostgreSQL server'
        Description   = 'Enable or disable the execution of the policy minimum TLS version Azure Database for PostgreSQL server'
    }
    Parameter MinimalTlsVersion @{
        AllowedValues = @('TLS1_2', 'TLS1_0', 'TLS1_1', 'TLSEnforcementDisabled')
        Default       = 'TLS1_2'
        DisplayName   = 'Select version for PostgreSQL server'
        Description   = 'Select version minimum TLS version Azure Database for PostgreSQL server to enforce'
    }

    Resource 'Microsoft.DBforPostgreSQL/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.DBforPostgreSQL/servers' -Role 'Contributor' -Name 'current' -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-PostgreSQL-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-PostgreSQL-sslEnforcement.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.