Description
Hello.
We use knex and mysql2 to connect to Google Cloud SQL from a local machine.
knex: v3.1.0
mysql2: 3.9.4
const knex = require('knex');
const fs = require('fs');
const params = {
client: 'mysql2',
connection: {
user: "db user",
password: "db password",
database: "db name",
timezone: 'Z',
host: "public IP address of db",
ssl: {
ca: fs.readFileSync(__dirname + '/server-ca.pem'),
cert: fs.readFileSync(__dirname + '/client-cert.pem'),
key: fs.readFileSync(__dirname + '/client-key.pem'),
}
},
};
const knexInstance = knex(params);
The issue is, when the host
is an IP address (provided by Google Cloud SQL), we get warning
[DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
It seems that the cause is the host
is passed as servername
in the call of tls.connect()
, and according to https://nodejs.org/api/tls.html#tlsconnectoptions-callback
servername: Server name for the SNI (Server Name Indication) TLS extension. It is the name of the host being connected to, and must be a host name, and not an IP address.
I am wondering what would be the correct approach to resolve this issue? Thank you.