Description
ssl_mode controls what Cloud SQL accepts from direct clients, including clients on a private network. The Cloud SQL Auth Proxy and Connectors automatically encrypt their connections to the instance.
Potential impact
A client that connects without TLS can expose credentials, queries and results in transit.
Remediation
Prepare clients to use TLS and verify the server certificate. Choose ENCRYPTED_ONLY for SQL Server. For MySQL or PostgreSQL, choose that mode or TRUSTED_CLIENT_CERTIFICATE_REQUIRED when clients must present valid certificates. The change applies to new sessions. Schedule a restart if you need to close all existing plaintext sessions.
Examples
Both PostgreSQL examples use private networking. The first permits plaintext or TLS. The second requires TLS and a trusted client certificate. Supply the private network and prepare certificates before enforcing the setting.
Before
resource "google_sql_database_instance" "sql_instance" {
name = "private-instance"
region = "us-central1"
database_version = "POSTGRES_15"
settings {
tier = "db-f1-micro"
ip_configuration {
ipv4_enabled = false
private_network = google_compute_network.private_network.id
ssl_mode = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
}
}
}
After
resource "google_sql_database_instance" "sql_instance" {
name = "private-instance"
region = "us-central1"
database_version = "POSTGRES_15"
settings {
tier = "db-f1-micro"
ip_configuration {
ipv4_enabled = false
private_network = google_compute_network.private_network.id
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"
}
}
}