Bylaw

Gallery › PostgreSQL › Azure built-in policies

Configure pgaudit.log to include role, ddl, and misc for PostgreSQL flexible servers

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Configures pgaudit.log to include role, ddl, and misc for PostgreSQL flexible servers to enable comprehensive auditing of role changes, DDL operations, and miscellaneous events.

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

Azure Policy JSONFlexibleServers_PgAuditLog_DINE.json · 92 lines
{
  "properties": {
    "displayName": "Configure pgaudit.log to include role, ddl, and misc for PostgreSQL flexible servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Configures pgaudit.log to include role, ddl, and misc for PostgreSQL flexible servers to enable comprehensive auditing of role changes, DDL operations, and miscellaneous events.",
    "metadata": {
      "version": "1.0.0",
      "category": "PostgreSQL"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "DeployIfNotExists",
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.DBforPostgreSQL/flexibleServers"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.DBforPostgreSQL/flexibleServers/configurations",
          "name": "pgaudit.log",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/configurations/value",
                "contains": "role"
              },
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/configurations/value",
                "contains": "ddl"
              }
            ]
          },
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "serverName": {
                  "value": "[field('name')]"
                }
              },
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "serverName": {
                    "type": "string"
                  }
                },
                "variables": {},
                "resources": [
                  {
                    "type": "Microsoft.DBforPostgreSQL/flexibleServers/configurations",
                    "apiVersion": "2022-12-01",
                    "name": "[concat(parameters('serverName'), '/pgaudit.log')]",
                    "properties": {
                      "value": "role,ddl,misc",
                      "source": "user-override"
                    }
                  }
                ],
                "outputs": {}
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/eadbb524-8644-4a87-8af6-549e1d125982",
  "name": "eadbb524-8644-4a87-8af6-549e1d125982"
}
Bylaweadbb524-8644-4a87-8af6-549e1d125982.bylaw.ps1 · 31 lines
# Converted from FlexibleServers_PgAuditLog_DINE.json by ConvertTo-Bylaw.
Policy 'eadbb524-8644-4a87-8af6-549e1d125982' {

    Properties @{
        DisplayName   = 'Configure pgaudit.log to include role, ddl, and misc for PostgreSQL flexible servers'
        Description   = 'Configures pgaudit.log to include role, ddl, and misc for PostgreSQL flexible servers to enable comprehensive auditing of role changes, DDL operations, and miscellaneous events.'
        Version       = '1.0.0'
        Category      = 'PostgreSQL'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.DBforPostgreSQL/flexibleServers'

    DeployIfNotExists 'Microsoft.DBforPostgreSQL/flexibleServers/configurations' -Role 'Contributor' -Name 'pgaudit.log' -Effect (Param Effect) {
        Require 'value contains role and contains ddl' {
            Field value | Must -ContainText 'role'
            Field value | Must -ContainText 'ddl'
        }
        Deployment -TemplateFile './templates/eadbb524-8644-4a87-8af6-549e1d125982.json' -Parameters ([ordered]@{
                serverName = (Arm '[field(''name'')]')
            })
    }
}

Its deployment templates are written beside it:

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