More Info:
Ensures that logging and log alerts exist for SQL configuration changes. Project Ownership is the highest level of privilege on a project, any changes in SQL configurations should be heavily monitored to prevent unauthorized changes.Risk Level
HighAddress
SecurityCompliance Standards
HIPAATriage and Remediation
- Remediation
Remediation
Using Console
Using Console
To remediate “SQL configuration logging” for GCP Cloud SQL via the GCP Console, you want to ensure that Cloud Audit Logs are enabled for Cloud SQL so that configuration and metadata changes (creates, updates, deletes, etc.) are captured.Follow these steps:
-
Open Audit Logs settings
- In the Google Cloud Console, go to:
IAM & Admin→Audit Logs.
- In the Google Cloud Console, go to:
-
Select the correct project
- At the top project selector, make sure you’re on the project where your Cloud SQL instances reside.
-
Choose the Cloud SQL service
- On the left side, under “Audit Logs Configuration,” find and select:
Cloud SQL Admin API (sqladmin.googleapis.com).
- On the left side, under “Audit Logs Configuration,” find and select:
-
Enable the log types
- On the right pane, you’ll see checkboxes for:
- Admin Read
- Data Read
- Data Write
- At minimum for configuration logging, ensure Admin Read is enabled.
- If your policy requires full tracking (often recommended), also enable Data Read and Data Write.
- On the right pane, you’ll see checkboxes for:
-
Apply the settings
- Click Save at the bottom of the page.
-
Verify logs are being produced
- Go to
Logging→Logs Explorer. - Set:
- Resource type:
Cloud SQL Database - Or filter by:
- Resource type:
- Perform a configuration change on a test Cloud SQL instance (e.g., edit flags or settings) and confirm you see corresponding audit log entries.
- Go to
Using CLI
Using CLI
Below is how to enable/adjust SQL configuration logging on Cloud SQL for GCP using gcloud. I’ll cover MySQL and PostgreSQL, which are the usual targets for this control.
Check the
Notes:
Again, include any other existing flags you need to preserve.
Confirm each flag is set as intended.
You should see logs like
If you tell me whether your instance is MySQL or PostgreSQL (and its version), I can give you an exact
1. Identify your instance
databaseVersion in the output to know whether it’s MySQL or PostgreSQL.2. MySQL: Enable connection / general / slow / error logging
Typical CIS-style hardening wants:log_output = FILEgeneral_log = ONlog_connections = ON(vialog_warningsor default)slow_query_log = ON- Reasonable
long_query_time
2.1 See current flags
2.2 Patch flags
Replace or extend--database-flags as needed:- If you already have flags set, you must re-specify them all; this command replaces the full flag list.
- Adjust
long_query_time(in seconds) to your policy.
3. PostgreSQL: Enable connection / error / statement / slow logging
Typical settings:log_connections = onlog_disconnections = onlog_statement = all(or at leastmod)log_min_duration_statement = 1000(1s; adjust per policy)
3.1 See current flags
3.2 Patch flags
4. Verify after change
5. Ensure logs reach Cloud Logging
Cloud SQL writes logs to Cloud Logging by default when logging flags are on. Verify:cloudsql.googleapis.com/mysql.err, cloudsql.googleapis.com/postgres.log, etc.If you tell me whether your instance is MySQL or PostgreSQL (and its version), I can give you an exact
gcloud sql instances patch command you can paste and run.Using Python
Using Python
Below is how to remediate “SQL Configuration Logging” for Cloud SQL in GCP using Python, by enabling audit logging for Cloud SQL at the project level (so configuration changes on Cloud SQL instances are logged).In GCP, Cloud SQL configuration changes are captured by Cloud Audit Logs.
You need to ensure Data Access audit logs are enabled for the
And authenticate (e.g. via Application Default Credentials):
If you tell me your Cloud SQL engine (PostgreSQL / MySQL / SQL Server) and what “configuration logging” control you’re mapping to (e.g., CIS benchmark section), I can give a more tailored Python example (including instance-level flags if needed).
You need to ensure Data Access audit logs are enabled for the
cloudsql.googleapis.com service on your project.1. Prerequisites
-
Enable APIs
- Cloud Resource Manager API
- Cloud SQL Admin API
- Cloud Logging API
-
Service account / identity
The identity running the script must have:
roles/resourcemanager.projectIamAdmin(or a custom role that cangetandsetIamPolicyon the project)
- Install dependencies
2. What we’re enabling
You will:- Edit the project IAM policy to add an
auditConfigsentry forcloudsql.googleapis.comthat enables:DATA_READDATA_WRITE- (Admin Activity logs are on by default and can’t be disabled, so you don’t need to set that.)
3. Python code: enable Cloud SQL audit logging
ReplaceYOUR_PROJECT_ID with your GCP project ID.4. Verify logging
- Go to Cloud Logging → Logs Explorer.
- Use a query like:
- Make a configuration change to a Cloud SQL instance (e.g., modify settings) and confirm that a new audit log entry appears.
If you tell me your Cloud SQL engine (PostgreSQL / MySQL / SQL Server) and what “configuration logging” control you’re mapping to (e.g., CIS benchmark section), I can give a more tailored Python example (including instance-level flags if needed).
Using Terraform
Using Terraform
terraform plan should show one google_project_iam_audit_config.cloud_sql_audit_logging to be created (or updated) with service = "sqladmin.googleapis.com" and audit_log_config blocks for DATA_READ and DATA_WRITE.
