PostgreSQL Database Server Log Connections Disabled

  • Query id: e69bda39-e1e2-47ca-b9ee-b6531b23aedd
  • Query name: PostgreSQL Database Server Log Connections Disabled
  • Platform: AzureResourceManager
  • Severity: Medium
  • Category: Networking and Firewall
  • URL: Github

Description

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

Code samples

Code samples with security vulnerabilities

Positive test num. 1 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "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": [
            "[resourceId('Microsoft.DBforPostgreSQL/servers', 'MyDBServer1')]"
          ],
          "name": "log_connections",
          "properties": {
            "configurationSets": [
              {
                "configurationSetType": "Microsoft.DBforPostgreSQL/servers/configurations/dbconfig",
                "configurationSet": {
                  "name": "dbconfig"
                }
              }
            ]
          },
          "location": "[resourceGroup().location]"
        }
      ]
    }
  ]
}
Positive 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": [
            "[resourceId('Microsoft.DBforPostgreSQL/servers', 'MyDBServer2')]"
          ],
          "name": "log_connections",
          "properties": {
            "value": "off"
          },
          "location": "[resourceGroup().location]"
        }
      ]
    }
  ],
  "outputs": {}
}
Positive 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_connections",
      "properties": {
        "value": "off"
      },
      "dependsOn": [
        "MyDBServer"
      ],
      "location": "[resourceGroup().location]"
    }
  ],
  "outputs": {}
}

Positive 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_connections",
      "properties": {
        "configurationSets": [
          {
            "configurationSetType": "Microsoft.DBforPostgreSQL/servers/configurations/dbconfig",
            "configurationSet": {
              "name": "dbconfig"
            }
          }
        ]
      },
      "dependsOn": [
        "MyDBServer"
      ],
      "location": "[resourceGroup().location]"
    }
  ],
  "outputs": {}
}
Positive test num. 5 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "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": [
                "[resourceId('Microsoft.DBforPostgreSQL/servers', 'MyDBServer1')]"
              ],
              "name": "log_connections",
              "properties": {
                "configurationSets": [
                  {
                    "configurationSetType": "Microsoft.DBforPostgreSQL/servers/configurations/dbconfig",
                    "configurationSet": {
                      "name": "dbconfig"
                    }
                  }
                ]
              },
              "location": "[resourceGroup().location]"
            }
          ]
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}
Positive 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": [
                "[resourceId('Microsoft.DBforPostgreSQL/servers', 'MyDBServer2')]"
              ],
              "name": "log_connections",
              "properties": {
                "value": "off"
              },
              "location": "[resourceGroup().location]"
            }
          ]
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}
Positive 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_connections",
          "properties": {
            "value": "off"
          },
          "dependsOn": [
            "MyDBServer"
          ],
          "location": "[resourceGroup().location]"
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}
Positive 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_connections",
          "properties": {
            "configurationSets": [
              {
                "configurationSetType": "Microsoft.DBforPostgreSQL/servers/configurations/dbconfig",
                "configurationSet": {
                  "name": "dbconfig"
                }
              }
            ]
          },
          "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",
  "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"
      },
      "type": "Microsoft.DBforPostgreSQL/servers",
      "resources": [
        {
          "type": "configurations",
          "apiVersion": "2017-12-01",
          "dependsOn": [
            "Microsoft.DBforPostgreSQL/servers/MyDBServer"
          ],
          "name": "log_connections",
          "properties": {
            "value": "on"
          },
          "location": "[resourceGroup().location]"
        }
      ]
    }
  ]
}
Negative 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": [
    {
      "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_connections",
      "properties": {
        "value": "on"
      },
      "dependsOn": [
        "MyDBServer"
      ],
      "location": "[resourceGroup().location]"
    }
  ],
  "outputs": {}
}
Negative test num. 3 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "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"
          },
          "type": "Microsoft.DBforPostgreSQL/servers",
          "resources": [
            {
              "type": "configurations",
              "apiVersion": "2017-12-01",
              "dependsOn": [
                "Microsoft.DBforPostgreSQL/servers/MyDBServer"
              ],
              "name": "log_connections",
              "properties": {
                "value": "on"
              },
              "location": "[resourceGroup().location]"
            }
          ]
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}

Negative test num. 4 - 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_connections",
          "properties": {
            "value": "on"
          },
          "dependsOn": [
            "MyDBServer"
          ],
          "location": "[resourceGroup().location]"
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}