Skip to main content

More Info:

Ensure that log_connections server parameter is enabled for all PostgreSQL database servers available in your Microsoft Azure cloud account. The log_connections parameter allows each attempted connection to the database server to be logged, including successful client authentication requests. Only Azure users with administrative privileges can change this parameter at session start, and it cannot be changed during an access session.

Risk Level

Medium

Address

Security

Compliance Standards

  • CIS AZURE
  • Cloudanix Best Practice
  • HITRUST CSF
  • NIST CSF
  • PCI
  • SOC2

Triage and Remediation

Remediation

Using Console

To enable the “LOG_CONNECTIONS” parameter for PostgreSQL servers in Azure, please follow the below steps:
  1. Login to Azure portal (https://portal.azure.com/)
  2. Navigate to the PostgreSQL server for which you want to enable the parameter.
  3. In the left-hand menu, click on “Settings”.
  4. Under the “Settings” tab, click on the “Configuration” option.
  5. Under the “Parameters” tab, search for the “logging_collector” parameter.
  6. Set the value of “logging_collector” parameter to “on”.
  7. Search for the “log_connections” parameter.
  8. Set the value of “log_connections” parameter to “on”.
  9. Click on the “Save” button to save the changes.
Once you have followed these steps, the “LOG_CONNECTIONS” parameter will be enabled for your PostgreSQL server in Azure.

To enable the “LOG_CONNECTIONS” parameter for PostgreSQL servers in Azure using Azure CLI, follow these steps:
  1. Open the Azure CLI in your terminal or command prompt.
  2. Log in to your Azure account using the command:
  3. Once logged in, select the Azure subscription where your PostgreSQL server is located using the command:
  4. Next, retrieve the resource ID of your PostgreSQL server using the command:
    Replace <resource-group-name> with the name of the resource group where your PostgreSQL server is located, and <server-name> with the name of your PostgreSQL server.
  5. Once you have the resource ID, use the following command to enable the “LOG_CONNECTIONS” parameter:
    Replace <resource-group-name> with the name of the resource group where your PostgreSQL server is located, and <server-name> with the name of your PostgreSQL server.
  6. After executing the command, the “LOG_CONNECTIONS” parameter will be enabled for your PostgreSQL server. You can verify this by checking the server configuration using the command:
    Replace <resource-group-name> with the name of the resource group where your PostgreSQL server is located, and <server-name> with the name of your PostgreSQL server.
To remediate the misconfiguration “Enable ‘LOG_CONNECTIONS’ Parameter for PostgreSQL Servers” in Azure using Python, you can follow these steps:
  1. First, you need to authenticate and create a PostgreSQL server object using the Azure Python SDK. You can use the following code snippet to achieve this:
  1. Once you have the server object, you can update the server parameters to enable the “log_connections” parameter. You can use the following code snippet to achieve this:
  1. Finally, you can verify that the parameter has been updated by checking the server parameters. You can use the following code snippet to achieve this:
This code will print “on” if the “log_connections” parameter has been successfully enabled.
This change does not force replacement of the PostgreSQL server; it updates the log_connections configuration in place on the existing server.For verification, terraform plan should show creation (or update) of azurerm_postgresql_configuration.log_connections with name = "log_connections" and value = "on" and no destroy/replace of azurerm_postgresql_server.this.