You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for MySQL VERIFY_CA SSL mode via tls-verify parameter
Implements VERIFY_CA SSL mode to verify certificate authority without
hostname verification, matching MySQL client's --ssl-mode=VERIFY_CA.
This addresses a long-standing limitation where users needed TLS with
CA verification but couldn't use hostname verification due to:
- Connecting via IP addresses instead of hostnames
- Dynamic IPs or load-balanced MySQL instances
- Certificates with SANs that don't match connection strings
- Multiple hostnames for the same MySQL instance
Adds new DSN parameter with two values:
- identity: Full verification (CA + hostname) - default
- ca: CA verification only (no hostname check)
Works with both system CA pool and custom registered TLS configs:
- ?tls=true&tls-verify=ca (system CA)
- ?tls=custom&tls-verify=ca (custom CA)
This is particularly important for users migrating to MySQL 8.0's
caching_sha2_password authentication, which requires encrypted
connections by default, making TLS support more critical.
Implementation follows Go team's recommended pattern from golang/go
issues #21971, #31791, #31792, #35467: using InsecureSkipVerify
with custom VerifyPeerCertificate callback that performs CA validation
via x509.Certificate.Verify() without hostname checking.
Related: #899
See also: golang/go#31792, golang/go#24151, golang/go#21971,
golang/go#28754, golang/go#31791, golang/go#35467
`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side) or use `preferred` to use TLS only when advertised by the server. This is similar to `skip-verify`, but additionally allows a fallback to a connection which is not encrypted. Neither `skip-verify` nor `preferred` add any reliable security. You can use a custom TLS config after registering it with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
437
+
`tls=true` enables TLS / SSL encrypted connection to the server with full certificate verification (including hostname). Use `skip-verify` if you want to use a self-signed or invalid certificate (server-side) or use `preferred` to use TLS only when advertised by the server. This is similar to `skip-verify`, but additionally allows a fallback to a connection which is not encrypted. Neither `skip-verify` nor `preferred` add any reliable security. You can use a custom TLS config after registering it with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
438
+
439
+
**TLS Verification Modes:**
440
+
441
+
The `tls` parameter selects which CA certificates to use:
442
+
-`tls=true`: Use system CA pool
443
+
-`tls=<name>`: Use custom registered TLS config
444
+
-`tls=skip-verify`: Accept any certificate (insecure)
445
+
-`tls=preferred`: Attempt TLS, fall back to plaintext (insecure)
446
+
447
+
The `tls-verify` parameter controls how certificates are verified (works with both `tls=true` and custom configs):
448
+
-`tls-verify=identity` (default): Verifies CA and hostname - Most secure, equivalent to MySQL's VERIFY_IDENTITY
449
+
-`tls-verify=ca`: Verifies CA only, skips hostname check - Equivalent to MySQL's VERIFY_CA mode
450
+
451
+
**Examples:**
452
+
```text
453
+
?tls=true - System CA with full verification (default behavior)
454
+
?tls=true&tls-verify=ca - System CA with CA-only verification
455
+
?tls=custom - Custom CA with full verification (default behavior)
456
+
?tls=custom&tls-verify=ca - Custom CA with CA-only verification
457
+
```
458
+
459
+
##### `tls-verify`
460
+
461
+
```text
462
+
Type: string
463
+
Valid Values: identity, ca
464
+
Default: identity
465
+
```
466
+
467
+
Controls the TLS certificate verification level. This parameter works with the `tls` parameter:
468
+
-`identity`: Full verification including hostname (default, most secure)
469
+
-`ca`: CA verification only, without hostname checking (MySQL VERIFY_CA equivalent)
470
+
471
+
This parameter only applies when `tls=true` or `tls=<custom-config>`. It has no effect with `tls=skip-verify` or `tls=preferred`.
0 commit comments