Bylaw

Gallery › SQL › Azure Landing Zones Library

PostgreSQL database servers enforce SSL connection.

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.1

Azure Database for PostgreSQL supports connecting your Azure Database for PostgreSQL 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 JSONDeny-PostgreSql-http.alz_policy_definition.json · 78 lines
{
  "name": "Deny-PostgreSql-http",
  "properties": {
    "description": "Azure Database for PostgreSQL supports connecting your Azure Database for PostgreSQL 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.",
    "displayName": "PostgreSQL database servers enforce SSL connection.",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "SQL",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.0.1"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "allowedValues": [
          "Audit",
          "Disabled",
          "Deny"
        ],
        "defaultValue": "Deny",
        "metadata": {
          "description": "Enable or disable the execution of the policy",
          "displayName": "Effect"
        },
        "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 minimum TLS for PostgreSQL server"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.DBforPostgreSQL/servers",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "exists": "false",
                "field": "Microsoft.DBforPostgreSQL/servers/sslEnforcement"
              },
              {
                "field": "Microsoft.DBforPostgreSQL/servers/sslEnforcement",
                "notEquals": "Enabled"
              },
              {
                "field": "Microsoft.DBforPostgreSQL/servers/minimalTlsVersion",
                "notequals": "[parameters('minimalTlsVersion')]"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeny-PostgreSql-http.bylaw.ps1 · 42 lines
# Converted from Deny-PostgreSql-http.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deny-PostgreSql-http' {

    Properties @{
        DisplayName = 'PostgreSQL database servers enforce SSL connection.'
        Description = 'Azure Database for PostgreSQL supports connecting your Azure Database for PostgreSQL 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.'
        Category    = 'SQL'
        Version     = '1.0.1'
        Mode        = 'Indexed'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

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

    Resource 'Microsoft.DBforPostgreSQL/servers' {

        Require 'sslEnforcement exists' {
            Field sslEnforcement | Must -Exist
        }

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

        Require 'minimalTlsVersion is the MinimalTlsVersion parameter' {
            Field minimalTlsVersion | Must -Be (Param MinimalTlsVersion)
        }
    }

    Effect (Param Effect)
}

Source: policy_definitions/Deny-PostgreSql-http.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.