Bylaw

Gallery › SQL › Azure built-in policies

Connection throttling should be enabled for PostgreSQL database servers

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0

This policy helps audit any PostgreSQL databases in your environment without Connection throttling enabled. This setting enables temporary connection throttling per IP for too many invalid password login failures.

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

Azure Policy JSONPostgreSQL_ConnectionThrottling_Enabled_Audit.json · 49 lines
{
  "properties": {
    "displayName": "Connection throttling should be enabled for PostgreSQL database servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy helps audit any PostgreSQL databases in your environment without Connection throttling enabled. This setting enables temporary connection throttling per IP for too many invalid password login failures.",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.DBforPostgreSQL/servers"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.DBforPostgreSQL/servers/configurations",
          "name": "connection_throttling",
          "existenceCondition": {
            "field": "Microsoft.DBforPostgreSQL/servers/configurations/value",
            "equals": "ON"
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5345bb39-67dc-4960-a1bf-427e16b9a0bd",
  "name": "5345bb39-67dc-4960-a1bf-427e16b9a0bd"
}
Bylaw5345bb39-67dc-4960-a1bf-427e16b9a0bd.bylaw.ps1 · 28 lines
# Converted from PostgreSQL_ConnectionThrottling_Enabled_Audit.json by ConvertTo-Bylaw.
Policy '5345bb39-67dc-4960-a1bf-427e16b9a0bd' {

    Properties @{
        DisplayName   = 'Connection throttling should be enabled for PostgreSQL database servers'
        Description   = 'This policy helps audit any PostgreSQL databases in your environment without Connection throttling enabled. This setting enables temporary connection throttling per IP for too many invalid password login failures.'
        Version       = '1.0.0'
        Category      = 'SQL'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.DBforPostgreSQL/servers'

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

Source: built-in-policies/policyDefinitions/SQL/PostgreSQL_ConnectionThrottling_Enabled_Audit.json in Azure/azure-policy, under the MIT licence.