Encrypting Cloud SQL database connections

Protect database connections with SSL/TLS and verify the server identity. Select settings that match the Cloud SQL engine and the actual connection path.

Description

Cloud SQL uses sslMode to control direct connections. When legacy requireSsl is also set, use a compatible value for the database engine.

Potential impact

Plaintext connections expose data in transit. Clients also need to verify the server’s identity.

Remediation

Prepare TLS and any required client certificates. For ENCRYPTED_ONLY, pair legacy requireSsl with false on MySQL or PostgreSQL and true on SQL Server. MySQL and PostgreSQL also support TRUSTED_CLIENT_CERTIFICATE_REQUIRED with true. Test an authorized TLS connection and confirm a new plaintext connection is refused. With the Auth Proxy, also protect the application-to-proxy connection.

Examples

The google.cloud 1.14.0 module exposes only require_ssl at creation. Change an existing instance’s mode in Cloud SQL. Supply the engine, a real project ID in place of test_project, and a service account JSON file. Replace the sample DNS resolver 8.8.8.8/32 with an approved database client range.

First configuration

yaml
- name: create a forth instance
  google.cloud.gcp_sql_instance:
    name: "{{ resource_name }}-2"
    settings:
      ip_configuration:
        require_ssl: no
        authorized_networks:
        - name: google dns server
          value: 8.8.8.8/32
      tier: db-n1-standard-1
    region: us-central1
    project: test_project
    auth_kind: serviceaccount
    service_account_file: "/tmp/auth.pem"
    state: present

require_ssl: no alone does not establish that plaintext is permitted. Check the effective sslMode.

Comparison configuration

yaml
- name: create a instance
  google.cloud.gcp_sql_instance:
    name: '{{ resource_name }}-2'
    settings:
      ip_configuration:
        require_ssl: yes
        authorized_networks:
        - name: google dns server
          value: 8.8.8.8/32
      tier: db-n1-standard-1
    region: us-central1
    project: test_project
    auth_kind: serviceaccount
    service_account_file: /tmp/auth.pem
    state: present

require_ssl: yes enables the legacy requirement. Check that clients meet the certificate requirements for your engine.

References