PostgreSQL Database Server SSL Disabled
- Query id: bf500309-da53-4dd3-bcf7-95f7974545a5
- Query name: PostgreSQL Database Server SSL Disabled
- Platform: AzureResourceManager
- Severity: Medium
- Category: Networking and Firewall
- CWE: 732
- URL: Github
Description¶
Microsoft.DBforPostgreSQL/servers sslEnforcement property should be set to 'Enabled'
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Positive test num. 1 - bicep file
param databaseSkuName int = 5
param databaseSkuTier int = 5
param databaseDTU int = 5
param databaseSkuSizeMB int = 5
var serverName = 'server'
resource MyDBServer 'Microsoft.DBforPostgreSQL/servers@2017-12-01' = {
kind: ''
location: resourceGroup().location
name: 'MyDBServer'
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: databaseSkuName
tier: databaseSkuTier
capacity: databaseDTU
size: databaseSkuSizeMB
family: 'SkuFamily'
}
}
resource MyDBServer_serverName_firewall 'Microsoft.DBforPostgreSQL/servers/firewallrules@2017-12-01' = {
parent: MyDBServer
location: resourceGroup().location
name: '${serverName}firewall'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
dependsOn: [
'Microsoft.DBforPostgreSQL/servers/${serverName}'
]
}
resource MyDBServer_myDB1 'Microsoft.DBforPostgreSQL/servers/databases@2017-12-01' = {
parent: MyDBServer
name: 'myDB1'
properties: {
charset: 'utf8'
collation: 'English_United States.1252'
}
}
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": "MyDBServer",
"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": "firewallrules",
"apiVersion": "2017-12-01",
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', variables('serverName'))]"
],
"location": "[resourceGroup().location]",
"name": "[concat(variables('serverName'),'firewall')]",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255"
}
},
{
"name": "myDB1",
"type": "databases",
"apiVersion": "2017-12-01",
"properties": {
"charset": "utf8",
"collation": "English_United States.1252"
},
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', 'MyDBServer')]"
]
}
]
}
],
"outputs": {}
}
Positive test num. 3 - bicep file
param databaseSkuName int = 5
param databaseSkuTier int = 5
param databaseDTU int = 5
param databaseSkuSizeMB int = 5
var serverName = 'server'
resource MyDBServer 'Microsoft.DBforPostgreSQL/servers@2017-12-01' = {
kind: ''
location: resourceGroup().location
name: 'MyDBServer'
properties: {
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'
defaultSecondaryLocation: resourceGroup().location
maxSizeInGB: '10'
isEncrypted: 'false'
isNetworkAccessible: 'true'
identity: ''
}
sku: {
name: databaseSkuName
tier: databaseSkuTier
capacity: databaseDTU
size: databaseSkuSizeMB
family: 'SkuFamily'
}
}
resource MyDBServer_serverName_firewall 'Microsoft.DBforPostgreSQL/servers/firewallrules@2017-12-01' = {
parent: MyDBServer
location: resourceGroup().location
name: '${serverName}firewall'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
dependsOn: [
'Microsoft.DBforPostgreSQL/servers/${serverName}'
]
}
resource MyDBServer_myDB1 'Microsoft.DBforPostgreSQL/servers/databases@2017-12-01' = {
parent: MyDBServer
name: 'myDB1'
properties: {
charset: 'utf8'
collation: 'English_United States.1252'
}
}
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": [
{
"apiVersion": "2017-12-01",
"kind": "",
"location": "[resourceGroup().location]",
"name": "MyDBServer",
"properties": {
"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",
"defaultSecondaryLocation": "[resourceGroup().location]",
"maxSizeInGB": "10",
"isEncrypted": "false",
"isNetworkAccessible": "true",
"identity": ""
},
"sku": {
"name": "[parameters('databaseSkuName')]",
"tier": "[parameters('databaseSkuTier')]",
"capacity": "[parameters('databaseDTU')]",
"size": "[parameters('databaseSkuSizeMB')]",
"family": "SkuFamily"
},
"type": "Microsoft.DBforPostgreSQL/servers",
"resources": [
{
"type": "firewallrules",
"apiVersion": "2017-12-01",
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', variables('serverName'))]"
],
"location": "[resourceGroup().location]",
"name": "[concat(variables('serverName'),'firewall')]",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255"
}
},
{
"name": "myDB1",
"type": "databases",
"apiVersion": "2017-12-01",
"properties": {
"charset": "utf8",
"collation": "English_United States.1252"
},
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', 'MyDBServer')]"
]
}
]
}
],
"outputs": {}
}
Positive test num. 5 - bicep file
param databaseSkuName int = 5
param databaseSkuTier int = 5
param databaseDTU int = 5
param databaseSkuSizeMB int = 5
var serverName = 'server'
resource MyDBServer 'Microsoft.DBforPostgreSQL/servers@2017-12-01' = {
kind: ''
location: resourceGroup().location
name: 'MyDBServer'
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: databaseSkuName
tier: databaseSkuTier
capacity: databaseDTU
size: databaseSkuSizeMB
family: 'SkuFamily'
}
}
resource MyDBServer_serverName_firewall 'Microsoft.DBforPostgreSQL/servers/firewallrules@2017-12-01' = {
parent: MyDBServer
location: resourceGroup().location
name: '${serverName}firewall'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
dependsOn: [
'Microsoft.DBforPostgreSQL/servers/${serverName}'
]
}
resource MyDBServer_myDB1 'Microsoft.DBforPostgreSQL/servers/databases@2017-12-01' = {
parent: MyDBServer
name: 'myDB1'
properties: {
charset: 'utf8'
collation: 'English_United States.1252'
}
}
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": "MyDBServer",
"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": "firewallrules",
"apiVersion": "2017-12-01",
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', variables('serverName'))]"
],
"location": "[resourceGroup().location]",
"name": "[concat(variables('serverName'),'firewall')]",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255"
}
},
{
"name": "myDB1",
"type": "databases",
"apiVersion": "2017-12-01",
"properties": {
"charset": "utf8",
"collation": "English_United States.1252"
},
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', 'MyDBServer')]"
]
}
]
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}
Positive test num. 7 - bicep file
param databaseSkuName int = 5
param databaseSkuTier int = 5
param databaseDTU int = 5
param databaseSkuSizeMB int = 5
var serverName = 'server'
resource MyDBServer 'Microsoft.DBforPostgreSQL/servers@2017-12-01' = {
kind: ''
location: resourceGroup().location
name: 'MyDBServer'
properties: {
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'
defaultSecondaryLocation: resourceGroup().location
maxSizeInGB: '10'
isEncrypted: 'false'
isNetworkAccessible: 'true'
identity: ''
}
sku: {
name: databaseSkuName
tier: databaseSkuTier
capacity: databaseDTU
size: databaseSkuSizeMB
family: 'SkuFamily'
}
}
resource MyDBServer_serverName_firewall 'Microsoft.DBforPostgreSQL/servers/firewallrules@2017-12-01' = {
parent: MyDBServer
location: resourceGroup().location
name: '${serverName}firewall'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
dependsOn: [
'Microsoft.DBforPostgreSQL/servers/${serverName}'
]
}
resource MyDBServer_myDB1 'Microsoft.DBforPostgreSQL/servers/databases@2017-12-01' = {
parent: MyDBServer
name: 'myDB1'
properties: {
charset: 'utf8'
collation: 'English_United States.1252'
}
}
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": [
{
"apiVersion": "2017-12-01",
"kind": "",
"location": "[resourceGroup().location]",
"name": "MyDBServer",
"properties": {
"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",
"defaultSecondaryLocation": "[resourceGroup().location]",
"maxSizeInGB": "10",
"isEncrypted": "false",
"isNetworkAccessible": "true",
"identity": ""
},
"sku": {
"name": "[parameters('databaseSkuName')]",
"tier": "[parameters('databaseSkuTier')]",
"capacity": "[parameters('databaseDTU')]",
"size": "[parameters('databaseSkuSizeMB')]",
"family": "SkuFamily"
},
"type": "Microsoft.DBforPostgreSQL/servers",
"resources": [
{
"type": "firewallrules",
"apiVersion": "2017-12-01",
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', variables('serverName'))]"
],
"location": "[resourceGroup().location]",
"name": "[concat(variables('serverName'),'firewall')]",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255"
}
},
{
"name": "myDB1",
"type": "databases",
"apiVersion": "2017-12-01",
"properties": {
"charset": "utf8",
"collation": "English_United States.1252"
},
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', 'MyDBServer')]"
]
}
]
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}
Code samples without security vulnerabilities¶
Negative test num. 1 - bicep file
param databaseSkuName int = 5
param databaseSkuTier int = 5
param databaseDTU int = 5
param databaseSkuSizeMB int = 5
var serverName = 'server'
resource MyDBServer 'Microsoft.DBforPostgreSQL/servers@2017-12-01' = {
kind: ''
location: resourceGroup().location
name: 'MyDBServer'
properties: {
version: '11'
administratorLogin: 'root'
administratorLoginPassword: '12345'
storageMB: '2048'
sslEnforcement: 'Enabled'
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'
defaultSecondaryLocation: resourceGroup().location
maxSizeInGB: '10'
isEncrypted: 'false'
isNetworkAccessible: 'true'
identity: ''
}
sku: {
name: databaseSkuName
tier: databaseSkuTier
capacity: databaseDTU
size: databaseSkuSizeMB
family: 'SkuFamily'
}
}
resource MyDBServer_serverName_firewall 'Microsoft.DBforPostgreSQL/servers/firewallrules@2017-12-01' = {
parent: MyDBServer
location: resourceGroup().location
name: '${serverName}firewall'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
dependsOn: [
'Microsoft.DBforPostgreSQL/servers/${serverName}'
]
}
resource MyDBServer_myDB1 'Microsoft.DBforPostgreSQL/servers/databases@2017-12-01' = {
parent: MyDBServer
name: 'myDB1'
properties: {
charset: 'utf8'
collation: 'English_United States.1252'
}
}
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": [
{
"apiVersion": "2017-12-01",
"kind": "",
"location": "[resourceGroup().location]",
"name": "MyDBServer",
"properties": {
"version": "11",
"administratorLogin": "root",
"administratorLoginPassword": "12345",
"storageMB": "2048",
"sslEnforcement": "Enabled",
"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",
"defaultSecondaryLocation": "[resourceGroup().location]",
"maxSizeInGB": "10",
"isEncrypted": "false",
"isNetworkAccessible": "true",
"identity": ""
},
"sku": {
"name": "[parameters('databaseSkuName')]",
"tier": "[parameters('databaseSkuTier')]",
"capacity": "[parameters('databaseDTU')]",
"size": "[parameters('databaseSkuSizeMB')]",
"family": "SkuFamily"
},
"type": "Microsoft.DBforPostgreSQL/servers",
"resources": [
{
"type": "firewallrules",
"apiVersion": "2017-12-01",
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', variables('serverName'))]"
],
"location": "[resourceGroup().location]",
"name": "[concat(variables('serverName'),'firewall')]",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255"
}
},
{
"name": "myDB1",
"type": "databases",
"apiVersion": "2017-12-01",
"properties": {
"charset": "utf8",
"collation": "English_United States.1252"
},
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', 'MyDBServer')]"
]
}
]
}
],
"outputs": {}
}
Negative test num. 3 - bicep file
param databaseSkuName int = 5
param databaseSkuTier int = 5
param databaseDTU int = 5
param databaseSkuSizeMB int = 5
var serverName = 'server'
resource MyDBServer 'Microsoft.DBforPostgreSQL/servers@2017-12-01' = {
kind: ''
location: resourceGroup().location
name: 'MyDBServer'
properties: {
version: '11'
administratorLogin: 'root'
administratorLoginPassword: '12345'
storageMB: '2048'
sslEnforcement: 'Enabled'
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'
defaultSecondaryLocation: resourceGroup().location
maxSizeInGB: '10'
isEncrypted: 'false'
isNetworkAccessible: 'true'
identity: ''
}
sku: {
name: databaseSkuName
tier: databaseSkuTier
capacity: databaseDTU
size: databaseSkuSizeMB
family: 'SkuFamily'
}
}
resource MyDBServer_serverName_firewall 'Microsoft.DBforPostgreSQL/servers/firewallrules@2017-12-01' = {
parent: MyDBServer
location: resourceGroup().location
name: '${serverName}firewall'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
dependsOn: [
'Microsoft.DBforPostgreSQL/servers/${serverName}'
]
}
resource MyDBServer_myDB1 'Microsoft.DBforPostgreSQL/servers/databases@2017-12-01' = {
parent: MyDBServer
name: 'myDB1'
properties: {
charset: 'utf8'
collation: 'English_United States.1252'
}
}
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": [
{
"apiVersion": "2017-12-01",
"kind": "",
"location": "[resourceGroup().location]",
"name": "MyDBServer",
"properties": {
"version": "11",
"administratorLogin": "root",
"administratorLoginPassword": "12345",
"storageMB": "2048",
"sslEnforcement": "Enabled",
"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",
"defaultSecondaryLocation": "[resourceGroup().location]",
"maxSizeInGB": "10",
"isEncrypted": "false",
"isNetworkAccessible": "true",
"identity": ""
},
"sku": {
"name": "[parameters('databaseSkuName')]",
"tier": "[parameters('databaseSkuTier')]",
"capacity": "[parameters('databaseDTU')]",
"size": "[parameters('databaseSkuSizeMB')]",
"family": "SkuFamily"
},
"type": "Microsoft.DBforPostgreSQL/servers",
"resources": [
{
"type": "firewallrules",
"apiVersion": "2017-12-01",
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', variables('serverName'))]"
],
"location": "[resourceGroup().location]",
"name": "[concat(variables('serverName'),'firewall')]",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255"
}
},
{
"name": "myDB1",
"type": "databases",
"apiVersion": "2017-12-01",
"properties": {
"charset": "utf8",
"collation": "English_United States.1252"
},
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/servers/', 'MyDBServer')]"
]
}
]
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}