sidorares / node-mysql2

:zap: fast mysqljs/mysql compatible mysql driver for node.js
https://sidorares.github.io/node-mysql2/
MIT License
3.94k stars 593 forks source link

got warning when host is an IP address #2588

Open avispeng opened 1 month ago

avispeng commented 1 month ago

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.

sidorares commented 3 weeks ago

linking related #2560