Disable "log_min_duration_statement" Flag for PostgreSQL Database Instances

Trend Micro Cloud One™ – Conformity is a continuous assurance tool that provides peace of mind for your cloud infrastructure, delivering over 750 automated best practice checks.

Risk level: Medium (should be achieved)

Ensure that "log_min_duration_statement" database flag is set to -1 (i.e. disabled) for all your Google Cloud PostgreSQL database instances.

Security

The "log_min_duration_statement" configuration flag causes the duration of each completed SQL statement to be logged if the statement executes for at least the specified number of milliseconds. Setting this flag to 0 logs all statement durations, whereas setting it to -1 disables logging statement durations. Logging SQL statements may include sensitive information that should not be recorded in log files, therefore the "log_min_duration_statement" database flag should be disabled.

Note: Some database flag settings can affect instance availability and/or stability, and eventually remove the PostgreSQL instance from the Google Cloud SQL Service Level Agreement (SLA).


Audit

To determine if "log_min_duration_statement" flag is disabled for your Google Cloud PostgreSQL database instances, perform the following actions:

Using GCP Console

01 Sign in to Google Cloud Management Console.

02 Select the Google Cloud Platform (GCP) project that you want to access from the console top navigation bar.

03 Navigate to Cloud SQL Instances dashboard at https://console.cloud.google.com/sql/instances.

04 Click inside the Filter tree box, select Type and PostgreSQL then press Enter, to list only the PostgreSQL database instances provisioned for the selected GCP project.

05 Click on the name (ID) of the database instance that you want to examine.

06 In the navigation panel, select Overview to access the configuration details available for the selected instance.

07 In the Configuration section, under Database flags, check the configuration value set for the log_min_duration_statement database flag. If log_min_duration_statement is not available in the Database flags list, or the flag is set to 0, the "log_min_duration_statement" database flag is enabled for the selected Google Cloud PostgreSQL database instance, therefore the instance configuration is not compliant.

08 Repeat step no. 5 – 7 to check the "log_min_duration_statement" flag configuration for other PostgreSQL database instances available within the selected project.

09 Repeat steps no. 2 – 8 for each project deployed in your Google Cloud account.

Using GCP CLI

01 Run projects list command (Windows/macOS/Linux) using custom query filters to list the IDs of all the Google Cloud Platform (GCP) projects available in your Google Cloud account:

gcloud projects list
	--format="table(projectId)"

02 The command output should return the requested GCP project identifiers:

PROJECT_ID
cc-web-project-112233
cc-mobile-project-123123

03 Run sql instances list command (Windows/macOS/Linux) using custom filtering to describe the name of each PostgreSQL database instance provisioned for the selected Google Cloud project:

gcloud sql instances list
	--project cc-web-project-112233
	--filter='DATABASE_VERSION:POSTGRES*'
	--format="(NAME)"

04 The command output should return the requested database instance name(s):

NAME
cc-app-postgres-instance
cc-web-postgres-instance

05 Run sql instances describe command (Windows/macOS/Linux) using the name of the PostgreSQL database instance that you want to examine as identifier parameter and custom query filters to describe the "log_min_duration_statement" flag configuration value set for the selected database instance:

gcloud sql instances describe cc-app-postgres-instance
	--format=json | jq '.settings.databaseFlags[] | select(.name=="log_min_duration_statement")|.value'

06 The command output should return the requested flag configuration value:

"0"

If the sql instances describe command output returns null or "0", as shown in the example above, the "log_min_duration_statement" database flag is enabled for the selected Google Cloud PostgreSQL database instance, therefore the database configuration is not compliant.

07 Repeat step no. 5 and 6 to verify the "log_min_duration_statement" flag configuration value for other PostgreSQL database instances created for the selected project.

08 Repeat steps no. 3 – 7 for each project available within your Google Cloud account.

Remediation / Resolution

To turn off the "log_min_duration_statement" database flag for your Google Cloud Platform (GCP) PostgreSQL database instances, perform the following actions:

Using GCP Console

01 Sign in to Google Cloud Management Console.

02 Select the Google Cloud Platform (GCP) project that you want to access from the console top navigation bar.

03 Navigate to Cloud SQL Instances dashboard at https://console.cloud.google.com/sql/instances.

04 Click inside the Filter tree box, select Type and PostgreSQL then press Enter, to display only the PostgreSQL database instances available for the selected project.

05 Click on the name/ID of the database instance that you want to reconfigure.

06 In the navigation panel, select Overview to access the configuration details of the selected instance.

07 Click on the Edit button from the dashboard top menu to enter the instance edit mode.

08 In the Configuration options section, click on Flags to expand the panel with the database flags configured for the selected PostgreSQL instance.

09 Find the log_min_duration_statement flag and turn it off by typing -1 in the flag configuration box. If the flag has not been set on the selected instance before, click Add itemAdd item, choose the log_min_duration_statement flag from the Choose one dropdown menu, and set its value to -1. Click Close to close the panel.
IMPORTANT: Configuring the "log_min_duration_statement" flag restarts automatically the selected database instance.

10 Click Save to apply the configuration changes.

11 Repeat step no. 5 – 10 to configure the required flag for other PostgreSQL database instances available within the selected project.

12 Repeat steps no. 2 – 11 for each project deployed in your Google Cloud account.

Using GCP CLI

01 Run sql instances patch command (Windows/macOS/Linux) using the name of the PostgreSQL database instance that you want to reconfigure as identifier parameters (see Audit section part II to identify the right resource), to disable the "log_min_duration_statement" database flag for the selected instance, by setting the flag value to -1:

gcloud sql instances patch cc-app-postgres-instance
	--database-flags log_min_duration_statement=-1

IMPORTANT: Configuring the "log_min_duration_statement" flag restarts automatically the selected database instance.

02 Type Y to confirm the database configuration change:

The following message will be used for the patch API method.
{"name": "cc-app-postgres-instance", "project": "cc-web-project-112233", "settings": {"databaseFlags": [{"name": "log_min_duration_statement", "value": "-1"}]}}
WARNING: This patch modifies database flag values, which may require your instance to be restarted. Check the list of supported flags - https://cloud.google.com/sql/docs/postgres/flags - to see if your instance will be restarted when this patch is submitted.
Do you want to continue (Y/n)? Y

03 The output should return the sql instances patch command request status:

Patching Cloud SQL instance...done.
Updated [https://sqladmin.googleapis.com/sql/v1beta4/projects/cc-web-project-112233/instances/cc-app-postgres-instance].

04 Repeat step no. 1 – 3 to configure the required flag for other PostgreSQL database instances provisioned for the selected project.

05 Repeat steps no. 1 – 4 for each project created within your Google Cloud account.

References

Publication date Apr 12, 2021

Unlock the Remediation Steps


Gain free unlimited access
to our full Knowledge Base


Over 750 rules & best practices
for AWS and Azure

You are auditing:

Disable "log_min_duration_statement" Flag for PostgreSQL Database Instances

Risk level: Medium