I'm trying to create a TLS connection to a Cloud SQL database but I'm getting the following error when trying to prepare a statement:
x509: cannot validate certificate for <cloud sql instance ip>
because it doesn't contain any IP SANs
Here is my setup code:
rootCertPool := x509.NewCertPool() pem, err := ioutil.ReadFile("/path/server-ca.pem") if err != nil { log.Fatal(err) } if ok := rootCertPool.AppendCertsFromPEM(pem); !ok { log.Fatal("Failed to append PEM.") } clientCert := make([]tls.Certificate, 0, 1) certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem") if err != nil { log.Fatal(err) } clientCert = append(clientCert, certs) mysql.RegisterTLSConfig("custom", &tls.Config{ RootCAs: rootCertPool, Certificates: clientCert, }) db, err := sql.Open("mysql", "<user>:<password>@tcp(<cloud sql ip>:3306)/<db_name>?tls=custom")