PostgreSQL connection logging is disabled

Use Cloud SQL for PostgreSQL connection logs to examine account access history.

Description

log_connections records connection attempts and successful authentication and authorization in PostgreSQL.

Potential impact

Without connection records, it is harder to trace unusual account activity or diagnose client connection problems.

Remediation

Set log_connections to the string on in settings.database_flags and keep other required flags. Open a new connection, find its entry and restrict who can read the log. Configure query auditing separately if you need statement history.

Examples

For the google.cloud 1.14.0 creation example, supply your PostgreSQL version and service account JSON file. Change flags on existing instances in Cloud SQL.

Before

yaml
- name: create instance
  google.cloud.gcp_sql_instance:
    name: gcp-instance
    settings:
      database_flags:
        - name: log_connections
          value: "off"
      tier: db-n1-standard-1
    region: us-central1
    project: "{{ gcp_project_id }}"
    database_version: "{{ postgres_version }}"
    auth_kind: serviceaccount
    service_account_file: "{{ gcp_credentials_file }}"
    state: present

After

yaml
- name: create a instance
  google.cloud.gcp_sql_instance:
    name: gcp-instance
    settings:
      database_flags:
        - name: log_connections
          value: "on"
      tier: db-n1-standard-1
    region: us-central1
    project: "{{ gcp_project_id }}"
    database_version: "{{ postgres_version }}"
    auth_kind: serviceaccount
    service_account_file: "{{ gcp_credentials_file }}"
    state: present

References