Review Azure PostgreSQL connection encryption

Require TLS for database connections and retain client validation of the server certificate.

Description

Azure PostgreSQL Flexible Server defaults require_secure_transport to on. Check the effective value when reviewing a template that omits the setting.

Potential impact

If the server accepts plaintext, credentials and data can be exposed even on a private network.

Remediation

Keep require_secure_transport on. Check the minimum TLS version and network access, then test the application with server certificate verification enabled. Plan migration from retired Single Server and verify the migrated data before switching clients.

Examples

The first example disables TLS enforcement on Single Server and contains an illustrative password. Use a managed secret. The second sets the transport flag on a separately provisioned Flexible Server.

Before

hcl
resource "azurerm_postgresql_server" "example" {
  name                = "example-psqlserver"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  administrator_login          = "psqladminun"
  administrator_login_password = "H@Sh1CoR3!"

  sku_name   = "GP_Gen5_4"
  version    = "9.6"
  storage_mb = 640000

  backup_retention_days        = 7
  geo_redundant_backup_enabled = true
  auto_grow_enabled            = true

  public_network_access_enabled    = false
  ssl_enforcement_enabled          = false
  ssl_minimal_tls_version_enforced = "TLS1_2"
}

After

hcl
resource "azurerm_postgresql_flexible_server_configuration" "example" {
  name      = "require_secure_transport"
  server_id = azurerm_postgresql_flexible_server.example.id
  value     = "on"
}

References