Bylaw

Gallery › SQL › Azure Community Policy

PostgreSQL flexible servers should enforce SSL connections

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

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 SSL for accessing your database server.

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

Azure Policy JSONazurepolicy.json · 44 lines
{
  "name": "e27a6dfc-883f-4f9e-97cc-a819fe702401",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "PostgreSQL flexible servers should enforce SSL connections",
    "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 SSL for accessing your database server.",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "AuditIfNotExists or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.DBforPostgreSQL/flexibleServers"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.DBforPostgreSQL/flexibleServers/configurations",
          "name": "require_secure_transport",
          "existenceCondition": {
            "field": "Microsoft.DBforPostgreSQL/flexibleServers/configurations/value",
            "equals": "ON"
          }
        }
      }
    }
  }
}
Bylawe27a6dfc-883f-4f9e-97cc-a819fe702401.bylaw.ps1 · 26 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'e27a6dfc-883f-4f9e-97cc-a819fe702401' {

    Properties @{
        DisplayName = 'PostgreSQL flexible servers should enforce SSL connections'
        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 SSL for accessing your database server.'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'AuditIfNotExists or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.DBforPostgreSQL/flexibleServers'

    AuditIfNotExists 'Microsoft.DBforPostgreSQL/flexibleServers/configurations' -Name 'require_secure_transport' -Effect (Param Effect) {
        Require 'value is ON' {
            Field value | Must -Be 'ON'
        }
    }
}

Source: policyDefinitions/Database for PostgreSQL/postgresql-flexible-servers-should-enforce-ssl-connections/azurepolicy.json in Azure/Community-Policy, under the MIT licence.