PostgreSQL Database Server Log Checkpoints Disabled

  • Query id: f9112910-c7bb-4864-9f5e-2059ba413bb7
  • Query name: PostgreSQL Database Server Log Checkpoints Disabled
  • Platform: AzureResourceManager
  • Severity: Medium
  • Category: Networking and Firewall
  • URL: Github

Description

Microsoft.DBforPostgreSQL/servers/configurations should have 'log_checkpoint' property set to 'on'
Documentation

Code samples

Code samples with security vulnerabilities

Postitive test num. 1 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "functions": [],
  "variables": {},
  "resources": [
    {
      "apiVersion": "2017-12-01",
      "kind": "",
      "location": "[resourceGroup().location]",
      "name": "MyDBServer1",
      "properties": {
        "sslEnforcement": "Disabled",
        "version": "11",
        "administratorLogin": "root",
        "administratorLoginPassword": "12345",
        "storageMB": "2048",
        "createMode": "Default",
        "collation": "SQL_Latin1_General_CP1_CI_AS",
        "creationDate": "2019-04-01T00:00:00Z",
        "lastModifiedDate": "2019-04-01T00:00:00Z",
        "maxSizeUnits": "SizeUnit.megabytes",
        "isReadOnly": "false",
        "isAutoUpgradeEnabled": "true",
        "isStateful": "false",
        "isExternal": "false"
      },
      "sku": {
        "name": "S0",
        "tier": "Basic",
        "capacity": 1,
        "family": "GeneralPurpose"
      },
      "type": "Microsoft.DBforPostgreSQL/servers",
      "resources": [
        {
          "type": "configurations",
          "apiVersion": "2017-12-01",
          "dependsOn": [
            "Microsoft.DBforPostgreSQL/servers/MyDBServer"
          ],
          "name": "log_checkpoints",
          "properties": {
            "configurationSets": [
              {
                "configurationSetType": "Microsoft.DBforPostgreSQL/servers/configurations/dbconfig",
                "configurationSet": {
                  "name": "dbconfig",
                  "configurationParameters": [
                    {
                      "name": "data_directory",
                      "value": "[parameters('dataDirectory')]"
                    },
                    {
                      "name": "max_size",
                      "value": "[parameters('maxSizeMB')]"
                    },
                    {
                      "name": "min_size",
                      "value": "[parameters('minSizeMB')]"
                    },
                    {
                      "name": "page_size",
                      "value": "[parameters('pageSizeMB')]"
                    },
                    {
                      "name": "work_mem",
                      "value": "[parameters('workMemMB')]"
                    },
                    {
                      "name": "maintenance_work_mem",
                      "value": "[parameters('maintenanceMemMB')]"
                    },
                    {
                      "name": "checkpoint_segments",
                      "value": "[parameters('checkpointSegments')]"
                    },
                    {
                      "name": "checkpoint_completion_target",
                      "value": "[parameters('checkpointCompletionTarget')]"
                    }
                  ]
                }
              }
            ]
          },
          "location": "[resourceGroup().location]"
        }
      ]
    }
  ],
  "outputs": {}
}
Postitive test num. 2 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "functions": [],
  "variables": {},
  "resources": [
    {
      "apiVersion": "2017-12-01",
      "kind": "",
      "location": "[resourceGroup().location]",
      "name": "MyDBServer2",
      "properties": {
        "sslEnforcement": "Disabled",
        "version": "11",
        "administratorLogin": "root",
        "administratorLoginPassword": "12345",
        "storageMB": "2048",
        "createMode": "Default",
        "collation": "SQL_Latin1_General_CP1_CI_AS",
        "creationDate": "2019-04-01T00:00:00Z",
        "lastModifiedDate": "2019-04-01T00:00:00Z",
        "maxSizeUnits": "SizeUnit.megabytes",
        "isReadOnly": "false",
        "isAutoUpgradeEnabled": "true",
        "isStateful": "false",
        "isExternal": "false"
      },
      "sku": {
        "name": "S0",
        "tier": "Basic",
        "capacity": 1,
        "family": "GeneralPurpose"
      },
      "type": "Microsoft.DBforPostgreSQL/servers",
      "resources": [
        {
          "type": "configurations",
          "apiVersion": "2017-12-01",
          "dependsOn": [
            "Microsoft.DBforPostgreSQL/servers/MyDBServer"
          ],
          "name": "log_checkpoints",
          "properties": {
            "value": "off"
          },
          "location": "[resourceGroup().location]"
        }
      ]
    }
  ],
  "outputs": {}
}
Postitive test num. 3 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "functions": [],
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.DBforPostgreSQL/servers",
      "apiVersion": "2017-12-01",
      "kind": "",
      "location": "[resourceGroup().location]",
      "name": "MyDBServer3",
      "properties": {
        "sslEnforcement": "Disabled",
        "version": "11",
        "administratorLogin": "root",
        "administratorLoginPassword": "12345",
        "storageMB": "2048",
        "createMode": "Default",
        "collation": "SQL_Latin1_General_CP1_CI_AS",
        "creationDate": "2019-04-01T00:00:00Z",
        "lastModifiedDate": "2019-04-01T00:00:00Z",
        "maxSizeUnits": "SizeUnit.megabytes",
        "isReadOnly": "false",
        "isAutoUpgradeEnabled": "true",
        "isStateful": "false",
        "isExternal": "false"
      },
      "sku": {
        "name": "S0",
        "tier": "Basic",
        "capacity": 1,
        "family": "GeneralPurpose"
      },
      "resources": [
      ]
    },
    {
      "type": "Microsoft.DBforPostgreSQL/servers/configurations",
      "apiVersion": "2017-12-01",
      "name": "MyDBServer/log_checkpoints",
      "properties": {
        "value": "off"
      },
      "dependsOn": [
        "MyDBServer"
      ],
      "location": "[resourceGroup().location]"
    }
  ],
  "outputs": {}
}

Postitive test num. 4 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "functions": [],
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.DBforPostgreSQL/servers",
      "apiVersion": "2017-12-01",
      "kind": "",
      "location": "[resourceGroup().location]",
      "name": "MyDBServer3",
      "properties": {
        "sslEnforcement": "Disabled",
        "version": "11",
        "administratorLogin": "root",
        "administratorLoginPassword": "12345",
        "storageMB": "2048",
        "createMode": "Default",
        "collation": "SQL_Latin1_General_CP1_CI_AS",
        "creationDate": "2019-04-01T00:00:00Z",
        "lastModifiedDate": "2019-04-01T00:00:00Z",
        "maxSizeUnits": "SizeUnit.megabytes",
        "isReadOnly": "false",
        "isAutoUpgradeEnabled": "true",
        "isStateful": "false",
        "isExternal": "false"
      },
      "sku": {
        "name": "S0",
        "tier": "Basic",
        "capacity": 1,
        "family": "GeneralPurpose"
      },
      "resources": [
      ]
    },
    {
      "type": "Microsoft.DBforPostgreSQL/servers/configurations",
      "apiVersion": "2017-12-01",
      "name": "MyDBServer/log_checkpoints",
      "properties": {
        "source": "source"
      },
      "dependsOn": [
        "MyDBServer"
      ],
      "location": "[resourceGroup().location]"
    }
  ],
  "outputs": {}
}
Postitive test num. 5 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {},
      "functions": [],
      "variables": {},
      "resources": [
        {
          "apiVersion": "2017-12-01",
          "kind": "",
          "location": "[resourceGroup().location]",
          "name": "MyDBServer1",
          "properties": {
            "sslEnforcement": "Disabled",
            "version": "11",
            "administratorLogin": "root",
            "administratorLoginPassword": "12345",
            "storageMB": "2048",
            "createMode": "Default",
            "collation": "SQL_Latin1_General_CP1_CI_AS",
            "creationDate": "2019-04-01T00:00:00Z",
            "lastModifiedDate": "2019-04-01T00:00:00Z",
            "maxSizeUnits": "SizeUnit.megabytes",
            "isReadOnly": "false",
            "isAutoUpgradeEnabled": "true",
            "isStateful": "false",
            "isExternal": "false"
          },
          "sku": {
            "name": "S0",
            "tier": "Basic",
            "capacity": 1,
            "family": "GeneralPurpose"
          },
          "type": "Microsoft.DBforPostgreSQL/servers",
          "resources": [
            {
              "type": "configurations",
              "apiVersion": "2017-12-01",
              "dependsOn": [
                "Microsoft.DBforPostgreSQL/servers/MyDBServer"
              ],
              "name": "log_checkpoints",
              "properties": {
                "configurationSets": [
                  {
                    "configurationSetType": "Microsoft.DBforPostgreSQL/servers/configurations/dbconfig",
                    "configurationSet": {
                      "name": "dbconfig",
                      "configurationParameters": [
                        {
                          "name": "data_directory",
                          "value": "[parameters('dataDirectory')]"
                        },
                        {
                          "name": "max_size",
                          "value": "[parameters('maxSizeMB')]"
                        },
                        {
                          "name": "min_size",
                          "value": "[parameters('minSizeMB')]"
                        },
                        {
                          "name": "page_size",
                          "value": "[parameters('pageSizeMB')]"
                        },
                        {
                          "name": "work_mem",
                          "value": "[parameters('workMemMB')]"
                        },
                        {
                          "name": "maintenance_work_mem",
                          "value": "[parameters('maintenanceMemMB')]"
                        },
                        {
                          "name": "checkpoint_segments",
                          "value": "[parameters('checkpointSegments')]"
                        },
                        {
                          "name": "checkpoint_completion_target",
                          "value": "[parameters('checkpointCompletionTarget')]"
                        }
                      ]
                    }
                  }
                ]
              },
              "location": "[resourceGroup().location]"
            }
          ]
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}
Postitive test num. 6 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {},
      "functions": [],
      "variables": {},
      "resources": [
        {
          "apiVersion": "2017-12-01",
          "kind": "",
          "location": "[resourceGroup().location]",
          "name": "MyDBServer2",
          "properties": {
            "sslEnforcement": "Disabled",
            "version": "11",
            "administratorLogin": "root",
            "administratorLoginPassword": "12345",
            "storageMB": "2048",
            "createMode": "Default",
            "collation": "SQL_Latin1_General_CP1_CI_AS",
            "creationDate": "2019-04-01T00:00:00Z",
            "lastModifiedDate": "2019-04-01T00:00:00Z",
            "maxSizeUnits": "SizeUnit.megabytes",
            "isReadOnly": "false",
            "isAutoUpgradeEnabled": "true",
            "isStateful": "false",
            "isExternal": "false"
          },
          "sku": {
            "name": "S0",
            "tier": "Basic",
            "capacity": 1,
            "family": "GeneralPurpose"
          },
          "type": "Microsoft.DBforPostgreSQL/servers",
          "resources": [
            {
              "type": "configurations",
              "apiVersion": "2017-12-01",
              "dependsOn": [
                "Microsoft.DBforPostgreSQL/servers/MyDBServer"
              ],
              "name": "log_checkpoints",
              "properties": {
                "value": "off"
              },
              "location": "[resourceGroup().location]"
            }
          ]
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}
Postitive test num. 7 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {},
      "functions": [],
      "variables": {},
      "resources": [
        {
          "type": "Microsoft.DBforPostgreSQL/servers",
          "apiVersion": "2017-12-01",
          "kind": "",
          "location": "[resourceGroup().location]",
          "name": "MyDBServer3",
          "properties": {
            "sslEnforcement": "Disabled",
            "version": "11",
            "administratorLogin": "root",
            "administratorLoginPassword": "12345",
            "storageMB": "2048",
            "createMode": "Default",
            "collation": "SQL_Latin1_General_CP1_CI_AS",
            "creationDate": "2019-04-01T00:00:00Z",
            "lastModifiedDate": "2019-04-01T00:00:00Z",
            "maxSizeUnits": "SizeUnit.megabytes",
            "isReadOnly": "false",
            "isAutoUpgradeEnabled": "true",
            "isStateful": "false",
            "isExternal": "false"
          },
          "sku": {
            "name": "S0",
            "tier": "Basic",
            "capacity": 1,
            "family": "GeneralPurpose"
          },
          "resources": [
          ]
        },
        {
          "type": "Microsoft.DBforPostgreSQL/servers/configurations",
          "apiVersion": "2017-12-01",
          "name": "MyDBServer/log_checkpoints",
          "properties": {
            "value": "off"
          },
          "dependsOn": [
            "MyDBServer"
          ],
          "location": "[resourceGroup().location]"
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}
Postitive test num. 8 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {},
      "functions": [],
      "variables": {},
      "resources": [
        {
          "type": "Microsoft.DBforPostgreSQL/servers",
          "apiVersion": "2017-12-01",
          "kind": "",
          "location": "[resourceGroup().location]",
          "name": "MyDBServer3",
          "properties": {
            "sslEnforcement": "Disabled",
            "version": "11",
            "administratorLogin": "root",
            "administratorLoginPassword": "12345",
            "storageMB": "2048",
            "createMode": "Default",
            "collation": "SQL_Latin1_General_CP1_CI_AS",
            "creationDate": "2019-04-01T00:00:00Z",
            "lastModifiedDate": "2019-04-01T00:00:00Z",
            "maxSizeUnits": "SizeUnit.megabytes",
            "isReadOnly": "false",
            "isAutoUpgradeEnabled": "true",
            "isStateful": "false",
            "isExternal": "false"
          },
          "sku": {
            "name": "S0",
            "tier": "Basic",
            "capacity": 1,
            "family": "GeneralPurpose"
          },
          "resources": [
          ]
        },
        {
          "type": "Microsoft.DBforPostgreSQL/servers/configurations",
          "apiVersion": "2017-12-01",
          "name": "MyDBServer/log_checkpoints",
          "properties": {
            "source": "source"
          },
          "dependsOn": [
            "MyDBServer"
          ],
          "location": "[resourceGroup().location]"
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "functions": [],
  "variables": {},
  "resources": [
    {
      "apiVersion": "2017-12-01",
      "kind": "",
      "location": "[resourceGroup().location]",
      "name": "MyDBServerNeg1",
      "properties": {
        "sslEnforcement": "Disabled",
        "version": "11",
        "administratorLogin": "root",
        "administratorLoginPassword": "12345",
        "storageMB": "2048",
        "createMode": "Default",
        "collation": "SQL_Latin1_General_CP1_CI_AS",
        "creationDate": "2019-04-01T00:00:00Z",
        "lastModifiedDate": "2019-04-01T00:00:00Z",
        "maxSizeUnits": "SizeUnit.megabytes",
        "isReadOnly": "false",
        "isAutoUpgradeEnabled": "true",
        "isStateful": "false",
        "isExternal": "false"
      },
      "sku": {
        "name": "[parameters('databaseSkuName')]",
        "tier": "[parameters('databaseSkuTier')]",
        "capacity": "[parameters('databaseDTU')]",
        "size": "[parameters('databaseSkuSizeMB')]",
        "family": "SkuFamily"
      },
      "type": "Microsoft.DBforPostgreSQL/servers",
      "resources": [
        {
          "type": "configurations",
          "apiVersion": "2017-12-01",
          "dependsOn": [
            "Microsoft.DBforPostgreSQL/servers/MyDBServer"
          ],
          "name": "log_checkpoints",
          "properties": {
            "value": "on"
          },
          "location": "[resourceGroup().location]"
        }
      ]
    }
  ],
  "outputs": {}
}
Negative test num. 2 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {},
      "functions": [],
      "variables": {},
      "resources": [
        {
          "apiVersion": "2017-12-01",
          "kind": "",
          "location": "[resourceGroup().location]",
          "name": "MyDBServerNeg1",
          "properties": {
            "sslEnforcement": "Disabled",
            "version": "11",
            "administratorLogin": "root",
            "administratorLoginPassword": "12345",
            "storageMB": "2048",
            "createMode": "Default",
            "collation": "SQL_Latin1_General_CP1_CI_AS",
            "creationDate": "2019-04-01T00:00:00Z",
            "lastModifiedDate": "2019-04-01T00:00:00Z",
            "maxSizeUnits": "SizeUnit.megabytes",
            "isReadOnly": "false",
            "isAutoUpgradeEnabled": "true",
            "isStateful": "false",
            "isExternal": "false"
          },
          "sku": {
            "name": "[parameters('databaseSkuName')]",
            "tier": "[parameters('databaseSkuTier')]",
            "capacity": "[parameters('databaseDTU')]",
            "size": "[parameters('databaseSkuSizeMB')]",
            "family": "SkuFamily"
          },
          "type": "Microsoft.DBforPostgreSQL/servers",
          "resources": [
            {
              "type": "configurations",
              "apiVersion": "2017-12-01",
              "dependsOn": [
                "Microsoft.DBforPostgreSQL/servers/MyDBServer"
              ],
              "name": "log_checkpoints",
              "properties": {
                "value": "on"
              },
              "location": "[resourceGroup().location]"
            }
          ]
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}