Default ssl_mode to SSL_PREFERRED_NOVERIFY for TCP connections - #307
Default ssl_mode to SSL_PREFERRED_NOVERIFY for TCP connections#307Yuhi-Sato wants to merge 2 commits into
ssl_mode to SSL_PREFERRED_NOVERIFY for TCP connections#307Conversation
When the Ruby binding's `ssl_mode` option is omitted, TCP connections previously stayed plaintext even when the server supports TLS. Match the MySQL client library's default instead: attempt TLS and fall back to plaintext when the server doesn't support it. The server certificate is not verified in this mode. An explicit `ssl_mode` is honored as before, including `SSL_DISABLED`. Unix socket connections still default to plaintext, matching libmysqlclient's PREFERRED behavior of not encrypting them. The new tests use SHOW SESSION STATUS rather than performance_schema.session_status because the fallback test runs on servers without TLS (CI's MariaDB 10.6/10.11 jobs), where performance_schema is OFF and its session_status table is empty. Fix: trilogy-libraries#306 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
composerinteralia
left a comment
There was a problem hiding this comment.
Changing the default seems OK to me, but might need to wait for a major release since it's a breaking change.
|
@composerinteralia |
Is it though? I may be missing something, but since it automatically fall backs to unencrypted (the current default), I wouldn't expect breakages. Unless somehow using unverified SSL instead of plain text cause some ripple effect. |
|
Ah yeah, good point. I guess it's not breaking then 👍🏻 |
|
@byroot My only concern is that it changes the default behavior, and while the SSL overhead is probably negligible, it's not entirely free. |
|
We can bump the major, but the annoying thing is that active record won't boot https://github.com/rails/rails/blob/0f36bbf72cc8b814bf1ad05c896c9c427b18217f/activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb#L5 |
Fixes #306
Summary
When the
ssl_modeoption is omitted, the Ruby binding now defaults TCP connections toTrilogy::SSL_PREFERRED_NOVERIFY: TLS is attempted, and the connection falls back to plaintext when the server doesn't support it. This matches the default behavior of MySQL client programs /libmysqlclient(SSL_MODE_PREFERRED) and avoids silently downgrading to plaintext when migrating frommysql2.SSL_VERIFY_CA/SSL_VERIFY_IDENTITYexplicitly when verification is needed, orSSL_REQUIRED_NOVERIFYto make TLS mandatory.ssl_modeis honored as before, includingSSL_DISABLED.libmysqlclient's PREFERRED behavior of not encrypting them.trilogy_ssl_mode_tenum, ortrilogy_sockopt_tzero-value semantics.Tests
Adds
DefaultSslModeTest, separate fromSslTestbecauseSslTest#setupskips everything on non-TLS servers while the fallback test here must run exactly then:ssl_modeconnects with TLS on a TLS-capable serverSSL_DISABLEDstays plaintext (guards the zero value against being clobbered by the default, sinceSSL_DISABLED == 0)ssl_modefalls back to plaintext on a server without TLS — this runs on the MariaDB 10.6/10.11 CI jobs, which don't enable TLSThe tests call
Trilogy.newdirectly because thenew_tcp_clienthelper passesssl_modeexplicitly, and checkSHOW SESSION STATUS LIKE 'Ssl_cipher'rather thanperformance_schema.session_statusbecause the fallback test runs on servers whereperformance_schemais OFF (the MariaDB < 11.4 default) and that table is empty.Docs
🤖 Generated with Claude Code