Triage and Remediation
Remediation
Using Console
Using Console
To remediate the PostgreSQL Enable PGAudit Database Flag Should Be On misconfiguration for GCP using GCP console, follow the below steps:
- Open the Google Cloud Console and select the project in which your PostgreSQL instance is running.
- Navigate to the Cloud SQL Instances page and click on the name of the PostgreSQL instance you want to remediate.
- In the instance details page, select the Configuration tab.
- In the Configuration tab, click on Edit Configuration.
- In the Edit Configuration page, scroll down to the Flags section.
- In the Flags section, click on Add item.
-
In the Add item dialog box, enter the flag name as
pgaudit.enabled
and set the value toon
. - Click on Save to save the configuration changes.
- Once the configuration changes are saved, restart the PostgreSQL instance for the changes to take effect.
Using CLI
Using CLI
To remediate the PostgreSQL Enable PGAudit Database Flag Should Be On misconfiguration in GCP using GCP CLI, follow these steps:Replace INSTANCE_NAME with the name of your PostgreSQL instance and USER_NAME with the username for the database.Replace DATABASE_NAME with the name of the database for which you want to enable the PGAudit flag.This should return “all” indicating that all audit events are being logged.By following these steps, you can remediate the PostgreSQL Enable PGAudit Database Flag Should Be On misconfiguration in GCP using GCP CLI.
- Open the Cloud Shell in the GCP console.
- Connect to your PostgreSQL instance using the following command:
- Once connected to the PostgreSQL instance, run the following command to enable the PGAudit flag:
- Verify that the PGAudit flag is enabled by running the following command:
- Exit the PostgreSQL instance by running the following command:
Using Python
Using Python
To remediate the PostgreSQL Enable PGAudit Database Flag Should Be On misconfiguration on GCP using Python, you can follow these steps:By following these steps, you should be able to remediate the PostgreSQL Enable PGAudit Database Flag Should Be On misconfiguration on GCP using Python.
- First, ensure that you have the necessary permissions to make changes to the PostgreSQL instance.
-
Next, use the
google-cloud-sql
library to connect to the PostgreSQL instance. You can install this library using pip:
- Once you have connected to the instance, you can use the
patch
method of theDatabaseInstance
object to update thesettings.settingsVersion
field with the latest version. This will ensure that you are making changes to the latest version of the settings.
- Next, you can use the
patch
method again to update thesettings.databaseFlags
field with thepgaudit.log
flag set toon
. This will enable PGAudit database flag.
- Finally, you can verify that the changes have been made by querying the
settings
field of theDatabaseInstance
object: