Bylaw

Gallery › SQL › Azure built-in policies

Public network access should be disabled for PostgreSQL flexible servers

Converted Policy Audit Deny Disabled Mode Indexed Version 3.1.0

Disabling the public network access property improves security by ensuring your Azure Database for PostgreSQL flexible servers can only be accessed from a private endpoint. This configuration strictly disables access from any public address space outside of Azure IP range and denies all logins that match IP based firewall rules.

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

Azure Policy JSONPostgreSQL_FlexibleServers_DisablePublicNetworkAccess_Audit.json · 83 lines
{
  "properties": {
    "displayName": "Public network access should be disabled for PostgreSQL flexible servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disabling the public network access property improves security by ensuring your Azure Database for PostgreSQL flexible servers can only be accessed from a private endpoint. This configuration strictly disables access from any public address space outside of Azure IP range and denies all logins that match IP based firewall rules.",
    "metadata": {
      "version": "3.1.0",
      "category": "SQL"
    },
    "version": "3.1.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DBforPostgreSQL/flexibleServers"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/network.delegatedSubnetResourceId",
                "exists": "true"
              },
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/network.privateDnsZoneArmResourceId",
                "exists": "true"
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.DBforPostgreSQL/flexibleServers/network.publicNetworkAccess",
                    "exists": "true"
                  },
                  {
                    "field": "Microsoft.DBforPostgreSQL/flexibleServers/network.publicNetworkAccess",
                    "notEquals": "Disabled"
                  }
                ]
              }
            ]
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/network.delegatedSubnetResourceId",
                "exists": "false"
              },
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/network.privateDnsZoneArmResourceId",
                "exists": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "3.1.0",
      "3.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5e1de0e3-42cb-4ebc-a86d-61d0c619ca48",
  "name": "5e1de0e3-42cb-4ebc-a86d-61d0c619ca48"
}
Bylaw5e1de0e3-42cb-4ebc-a86d-61d0c619ca48.bylaw.ps1 · 44 lines
# Converted from PostgreSQL_FlexibleServers_DisablePublicNetworkAccess_Audit.json by ConvertTo-Bylaw.
Policy '5e1de0e3-42cb-4ebc-a86d-61d0c619ca48' {

    Properties @{
        DisplayName   = 'Public network access should be disabled for PostgreSQL flexible servers'
        Description   = 'Disabling the public network access property improves security by ensuring your Azure Database for PostgreSQL flexible servers can only be accessed from a private endpoint. This configuration strictly disables access from any public address space outside of Azure IP range and denies all logins that match IP based firewall rules.'
        Version       = '3.1.0'
        Category      = 'SQL'
        PolicyVersion = '3.1.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.DBforPostgreSQL/flexibleServers' {

        When {
            AnyOf {
                Field network.delegatedSubnetResourceId | Must -Exist
                Field network.privateDnsZoneArmResourceId | Must -Exist
                AllOf {
                    Field network.publicNetworkAccess | Must -Exist
                    Field network.publicNetworkAccess | Must -Not -Be 'Disabled'
                }
            }
        }

        Require 'network.delegatedSubnetResourceId exists' {
            Field network.delegatedSubnetResourceId | Must -Exist
        }

        Require 'network.privateDnsZoneArmResourceId exists' {
            Field network.privateDnsZoneArmResourceId | Must -Exist
        }
    }

    Effect (Param Effect)
}

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