Azure Audit Postgresql Database Server Enable In Transit
Triage and Remediation
- Remediation
Remediation
Using Console
Sure, here are the step-by-step instructions to remediate the misconfiguration of enabling in-transit encryption for PostgreSQL Database Servers in AZURE:
- Go to the AZURE portal and login to your account.
- In the left-hand menu, click on the "Azure Database for PostgreSQL servers" option.
- Select the PostgreSQL server for which you want to enable in-transit encryption.
- In the left-hand menu, under the "Security" section, click on the "Connection security" option.
- Under the "Connection security" section, toggle the "Enforce SSL connection" option to "Enabled".
- Once you have enabled the "Enforce SSL connection" option, click on the "Save" button at the top of the page to save your changes.
That's it! You have now remediated the misconfiguration of enabling in-transit encryption for PostgreSQL Database Servers in AZURE. Now, all connections to your PostgreSQL server will be encrypted using SSL.
Using CLI
To remediate the misconfiguration of enabling In-Transit Encryption for PostgreSQL Database Servers in AZURE using AZURE CLI, you can follow these step-by-step instructions:
-
Open the Azure CLI in your preferred terminal.
-
Login to your Azure account using the command below:
az login -
Once you are logged in, set the subscription where your PostgreSQL server is located using the command below:
az account set --subscription <subscription_name> -
Next, set the resource group where your PostgreSQL server is located using the command below:
az group set --name <resource_group_name> -
Now, enable SSL enforcement for your PostgreSQL server using the command below:
az postgres server update --resource-group <resource_group_name> --name <postgresql_server_name> --ssl-enforcement EnabledThis command will enable SSL enforcement for your PostgreSQL server which will encrypt the data in transit.
-
Finally, verify that SSL enforcement is enabled for your PostgreSQL server by running the following command:
az postgres server show --resource-group <resource_group_name> --name <postgresql_server_name> --query sslEnforcementThis command will return the value "Enabled" which confirms that SSL enforcement is enabled for your PostgreSQL server.
By following these steps, you will be able to remediate the misconfiguration of enabling In-Transit Encryption for PostgreSQL Database Servers in AZURE using AZURE CLI.
Using Python
To remediate the misconfiguration "Enable In-Transit Encryption for PostgreSQL Database Servers" in Azure using Python, you can follow the below steps:
- Import the necessary libraries:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.postgresql import PostgreSQLManagementClient
from azure.mgmt.postgresql.models import ServerUpdateParameters
- Authenticate with Azure using Service Principal credentials:
TENANT_ID = 'your_tenant_id'
CLIENT_ID = 'your_client_id'
CLIENT_SECRET = 'your_client_secret'
SUBSCRIPTION_ID = 'your_subscription_id'
credentials = ServicePrincipalCredentials(
client_id=CLIENT_ID,
secret=CLIENT_SECRET,
tenant=TENANT_ID
)
- Instantiate the PostgreSQLManagementClient:
client = PostgreSQLManagementClient(credentials, SUBSCRIPTION_ID)
- Get the existing server details:
resource_group_name = 'your_resource_group_name'
server_name = 'your_server_name'
server = client.servers.get(resource_group_name, server_name)
- Update the server with the in-transit encryption enabled:
params = ServerUpdateParameters(
ssl_enforcement="Enabled"
)
client.servers.update(resource_group_name, server_name, params)
- Verify that the in-transit encryption is enabled:
server = client.servers.get(resource_group_name, server_name)
print(server.ssl_enforcement)
These steps will enable in-transit encryption for PostgreSQL Database Servers in Azure using Python.
Using Terraform
resource "azurerm_postgresql_server" "POSTGRESQL_SERVER_NAME" {
name = "POSTGRESQL_SERVER_NAME" # replace with your server name
location = azurerm_resource_group.RG.name # replace with your RG reference
resource_group_name = azurerm_resource_group.RG.name # replace with your RG
sku_name = "GP_Gen5_2" # replace with your SKU
version = "11" # replace with your PostgreSQL version
administrator_login = "ADMIN_USERNAME" # replace
administrator_login_password = "ADMIN_PASSWORD" # replace with secure secret reference
# Enable in-transit encryption (force SSL)
ssl_enforcement_enabled = true
ssl_minimal_tls_version_enforced = "TLS1_2"
storage_mb = 5120
backup_retention_days = 7
geo_redundant_backup_enabled = false
auto_grow_enabled = true
}
Changing ssl_enforcement_enabled and ssl_minimal_tls_version_enforced does not force replacement of the server; Terraform will perform an in-place update.
Verification: terraform plan should show the existing azurerm_postgresql_server with ssl_enforcement_enabled changing from false (or null) to true and ssl_minimal_tls_version_enforced changing to "TLS1_2".