trilogy-libraries / trilogy

Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.
MIT License
697 stars 68 forks source link

Implement support for cleartext authentication plugin #171

Closed wildmaples closed 5 months ago

wildmaples commented 5 months ago

Resolves: https://github.com/trilogy-libraries/trilogy/issues/157 Redo of: https://github.com/trilogy-libraries/trilogy/pull/168

The server doesn't request for cleartext plugin in the first handshake as it is not a default plugin. The client should only provide cleartext password when the server requests an auth switch to it, and the client has enable_cleartext_plugin option enabled. If the client does not have cleartext auth plugin enabled, we will raise a Trilogy::AuthPluginError.

This is the authentication flow for a server that uses the cleartext client side plugin (https://github.com/trilogy-libraries/trilogy/pull/168#discussion_r1548811735):

Server sends handshake, with auth plugin caching_sha2_password Client sends handshake response, still with auth plugin caching_sha2_password Server sends auth switch request, now with auth plugin mysql_clear_password Client sends auth switch response with just the cleartext password and nothing else Server sends OK and we are connected

This PR introduces these changes:

cc: @ngan @composerinteralia

ngan commented 5 months ago

I created an issue on the MySQL docker repo to see if they'd be open to building and tagging a mysql-community-test variant that we can use. If they do, we can switch to that and get the test auth plugin for free. If they don't, we can keep what we have (checked-in plugins for various mysql version), or build our own MySQL image.

https://github.com/docker-library/mysql/issues/1040

composerinteralia commented 5 months ago

Would you mind squashing your commits?

I do like a clean git history, but we haven't historically been as opinionated about this as (for example) Rails.

composerinteralia commented 5 months ago

Thank you!