Bylaw

Gallery › SQL › Azure Community Policy

PostgreSQL flexible servers should Log connections.

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

This policy helps audit any PostgreSQL databases in your environment without log_connections setting enabled.

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

Azure Policy JSONazurepolicy.json · 44 lines
{
  "name": "c869af6e-714a-4efc-b750-f5462b43b9c1",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "PostgreSQL flexible servers should Log connections.",
    "description": "This policy helps audit any PostgreSQL databases in your environment without log_connections setting enabled.",
    "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": "log_connections",
          "existenceCondition": {
            "field": "Microsoft.DBforPostgreSQL/flexibleServers/configurations/value",
            "equals": "ON"
          }
        }
      }
    }
  }
}
Bylawc869af6e-714a-4efc-b750-f5462b43b9c1.bylaw.ps1 · 26 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'c869af6e-714a-4efc-b750-f5462b43b9c1' {

    Properties @{
        DisplayName = 'PostgreSQL flexible servers should Log connections.'
        Description = 'This policy helps audit any PostgreSQL databases in your environment without log_connections setting enabled.'
        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 'log_connections' -Effect (Param Effect) {
        Require 'value is ON' {
            Field value | Must -Be 'ON'
        }
    }
}

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