SSL configuration for backends

ProxySQL supports SSL connections to the backends since version v1.2.0e . Attempts to configure an older version will fails.

IMPORTANT NOTES:

  • SSL is supported only for backends in v1.x. Clients cannot use use SSL to connect to ProxySQL in version prior to v2.x
  • As of v1.4.5, because ProxySQL uses mariadb-connector-c-2.3.1 only SSL/TLSv1.0 is supported: https://mariadb.com/kb/en/library/mariadb-connector-c-300-release-notes/.
  • In ProxySQL v2.x the mariadb-connector-3.0.2 and supports SSL/TLSv1.0,TLSv1.1 and TLSv1.2. This applies to frontend and backend connections
    To enabled SSL connections you need to:

  • update mysql_servers.use_ssl for the server you want to use SSL;

  • update associated global variables (only required in ProxySQL v1.x releases, not required for ProxySQL v2.x)
    If you want to connect to the same server with both SSL and non-SSL you need to configure the same server in two different hostgroups, and define access rules.For example, to configure SSL on one server:
  1. mysql> SELECT * FROM mysql_servers;
  2. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  3. | hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms |
  4. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  5. | 1 | 127.0.0.1 | 21891 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 |
  6. | 2 | 127.0.0.1 | 21892 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 |
  7. | 2 | 127.0.0.1 | 21893 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 |
  8. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  9. 3 rows in set (0.00 sec)
  10.  
  11. mysql> UPDATE mysql_servers SET use_ssl=1 WHERE port=21891;
  12. Query OK, 1 row affected (0.00 sec)
  13.  
  14. mysql> SELECT * FROM mysql_servers;
  15. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  16. | hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms |
  17. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  18. | 1 | 127.0.0.1 | 21891 | ONLINE | 1 | 0 | 1000 | 0 | 1 | 0 |
  19. | 2 | 127.0.0.1 | 21892 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 |
  20. | 2 | 127.0.0.1 | 21893 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 |
  21. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  22. 3 rows in set (0.00 sec)
  23.  
  24. mysql> LOAD MYSQL SERVERS TO RUNTIME;
  25. Query OK, 0 rows affected (0.00 sec)
  26.  
  27. mysql> SELECT * FROM runtime_mysql_servers;
  28. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  29. | hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms |
  30. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  31. | 1 | 127.0.0.1 | 21891 | ONLINE | 1 | 0 | 1000 | 0 | 1 | 0 |
  32. | 2 | 127.0.0.1 | 21892 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 |
  33. | 2 | 127.0.0.1 | 21893 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 |
  34. +--------------+-----------+-------+--------+--------+-------------+-----------------+---------------------+---------+----------------+
  35. 3 rows in set (0.00 sec)

At this stage, in ProxySQL v1.x, trying to connect to host 127.0.0.1 and port 21891 will not use SSL because no key and no certificate are configured. Instead, normal non-SSL connections will be established. In ProxySQL v2.x, if use_ssl=1 then all new connections will use SSL (by means of MySQL's builtin key/certs).

The next step to use SSL connections in ProxySQL 1.x is to configure key and certificate (this can also be applied to ProxySQL v2.x in case you would like to use a specific key and certificate).

  1. mysql> SELECT * FROM global_variables WHERE variable_name LIKE 'mysql%ssl%';
  2. +--------------------+----------------+
  3. | variable_name | variable_value |
  4. +--------------------+----------------+
  5. | mysql-ssl_p2s_ca | (null) |
  6. | mysql-ssl_p2s_cert | (null) |
  7. | mysql-ssl_p2s_key | (null) |
  8. +--------------------+----------------+
  9. 3 rows in set (0.00 sec)
  10.  
  11. mysql> SET mysql-ssl_p2s_cert="/home/vagrant/newcerts/client-cert.pem";
  12. Query OK, 1 row affected (0.00 sec)
  13.  
  14. mysql> SET mysql-ssl_p2s_key="/home/vagrant/newcerts/client-key.pem";
  15. Query OK, 1 row affected (0.00 sec)
  16.  
  17. mysql> SELECT * FROM global_variables WHERE variable_name LIKE 'mysql%ssl%';
  18. +--------------------+----------------------------------------+
  19. | variable_name | variable_value |
  20. +--------------------+----------------------------------------+
  21. | mysql-ssl_p2s_ca | (null) |
  22. | mysql-ssl_p2s_cert | /home/vagrant/newcerts/client-cert.pem |
  23. | mysql-ssl_p2s_key | /home/vagrant/newcerts/client-key.pem |
  24. +--------------------+----------------------------------------+
  25. 3 rows in set (0.01 sec)
  26.  
  27. mysql> LOAD MYSQL VARIABLES TO RUNTIME;
  28. Query OK, 0 rows affected (0.00 sec)

At this point, all new connections to host 127.0.0.1 and port 21891 will use SSL.

If you are happy with the new changes, you can make them persistent saving the configuration on disk:

  1. mysql> SAVE MYSQL SERVERS TO DISK;
  2. Query OK, 0 rows affected (0.01 sec)
  3.  
  4. mysql> SAVE MYSQL VARIABLES TO DISK;
  5. Query OK, 58 rows affected (0.00 sec)

Happy SSLing!

SSL configuration for frontends

Available since 2.0, although disabled by default.To enable SSL for frontend connections, you need to enable mysql-have_ssl=true

Supported protocol:

  1. SSLv2
  2. SSLv3
  3. TLSv1
  4. TLSv1.1
  5. TLSv1.2

Supported ciphers:

  1. DHE-RSA-AES256-GCM-SHA384
  2. DHE-RSA-AES256-SHA256
  3. DHE-RSA-AES256-SHA
  4. DHE-RSA-CAMELLIA256-SHA
  5. AES256-GCM-SHA384
  6. AES256-SHA256
  7. AES256-SHA
  8. CAMELLIA256-SHA
  9. DHE-RSA-AES128-GCM-SHA256
  10. DHE-RSA-AES128-SHA256
  11. DHE-RSA-AES128-SHA
  12. DHE-RSA-SEED-SHA
  13. DHE-RSA-CAMELLIA128-SHA
  14. AES128-GCM-SHA256
  15. AES128-SHA256
  16. AES128-SHA
  17. SEED-SHA
  18. CAMELLIA128-SHA
  19. DES-CBC3-SHA

原文: https://github.com/sysown/proxysql/wiki/SSL-Support