Remediation
Initialize the pgAudit flagβ
From Google Cloud Consoleβ
- Go to https://console.cloud.google.com/sql/instances.
- Select the instance to open its
Overview
page. - Click
Edit
. - Scroll down and expand
Flags
. - To set a flag that has not been set on the instance before, click
Add item
. - Enter
cloudsql.enable_pgaudit
for the flag name and set the flag toon
. - Click
Done
. - Click
Save
to update the configuration. - Confirm your changes under
Flags
on theOverview
page.
From Google Cloud CLIβ
Run the below command by providing <INSTANCE_NAME>
to enable cloudsql.enable_pgaudit
flag.
gcloud sql instances patch <INSTANCE_NAME> --database-flags cloudsql.enable_pgaudit=on
Note: RESTART
is required to get this configuration in effect.
Creating the extension
-
Connect to the the server running PostgreSQL or through a SQL client of your choice.
-
If SSHing to the server in the command line open the PostgreSQL shell by typing
psql
-
Run the following command as a superuser.
CREATE EXTENSION pgaudit;
Updating the previously created pgaudit.log flag for your Logging Needsβ
From Consoleβ
Note: there are multiple options here. This command will enable logging for all databases on a server. Please see the customizing database audit logging reference for more flag options.
- Go to https://console.cloud.google.com/sql/instances.
- Select the instance to open its
Overview
page. - Click
Edit
. - Scroll down and expand
Flags
. - To set a flag that has not been set on the instance before, click
Add item
. - Enter
pgaudit.log=all
for the flag name and set the flag to on. - Click
Done
. - Click
Save
to update the configuration. - Confirm your changes under
Flags
on theOverview
page.
From Command Lineβ
Run the command
gcloud sql instances patch <INSTANCE_NAME> --database-flags \ cloudsql.enable_pgaudit=on,pgaudit.log=all
Determine if logs are being sent to Logs Explorer
- From the Google Console home page, open the hamburger menu in the top left.
- In the menu that pops open, scroll down to Logs Explorer under Operations.
- In the query box, paste the following and search resource.type="cloudsql_database" logName="projects//logs/cloudaudit.googleapis.com%2Fdata_access" protoPayload.request.@type="type.googleapis.com/google.cloud.sql.audit.v1.PgAuditEntry" If it returns any log sources, they are correctly setup.