Bylaw

Gallery › PostgreSQL › Azure built-in policies

Auditing with PgAudit should be enabled for PostgreSQL flexible servers

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0

This policy helps audit any PostgreSQL flexible servers in your environment which is not enabled to use pgaudit.

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

Azure Policy JSONFlexibleServers_EnablePgAudit_AINE.json · 49 lines
{
  "properties": {
    "displayName": "Auditing with PgAudit should be enabled for PostgreSQL flexible servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy helps audit any PostgreSQL flexible servers in your environment which is not enabled to use pgaudit.",
    "metadata": {
      "version": "1.0.0",
      "category": "PostgreSQL"
    },
    "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/flexibleServers"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.DBforPostgreSQL/flexibleServers/configurations",
          "name": "pgaudit.log",
          "existenceCondition": {
            "field": "Microsoft.DBforPostgreSQL/flexibleServers/configurations/value",
            "notEquals": "none"
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/4eb5e667-e871-4292-9c5d-8bbb94e0c908",
  "name": "4eb5e667-e871-4292-9c5d-8bbb94e0c908"
}
Bylaw4eb5e667-e871-4292-9c5d-8bbb94e0c908.bylaw.ps1 · 28 lines
# Converted from FlexibleServers_EnablePgAudit_AINE.json by ConvertTo-Bylaw.
Policy '4eb5e667-e871-4292-9c5d-8bbb94e0c908' {

    Properties @{
        DisplayName   = 'Auditing with PgAudit should be enabled for PostgreSQL flexible servers'
        Description   = 'This policy helps audit any PostgreSQL flexible servers in your environment which is not enabled to use pgaudit.'
        Version       = '1.0.0'
        Category      = 'PostgreSQL'
        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/flexibleServers'

    AuditIfNotExists 'Microsoft.DBforPostgreSQL/flexibleServers/configurations' -Name 'pgaudit.log' -Effect (Param Effect) {
        Require 'value is not none' {
            Field value | Must -Not -Be 'none' -IfPresent
        }
    }
}

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