-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Support MySQL VERIFY_CA SSL Mode #1742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ type Config struct { | |
| MaxAllowedPacket int // Max packet size allowed | ||
| ServerPubKey string // Server public key name | ||
| TLSConfig string // TLS configuration name | ||
| TLSVerify string // TLS verification level: "identity" (default) or "ca" | ||
| TLS *tls.Config // TLS configuration, its priority is higher than TLSConfig | ||
| Timeout time.Duration // Dial timeout | ||
| ReadTimeout time.Duration // I/O read timeout | ||
|
Comment on lines
+52
to
55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tighten The core wiring of
return fmt.Errorf("invalid tls-verify value: %s (must be 'identity' or 'ca')", value)while - mode := strings.ToLower(value)
- if mode != "identity" && mode != "ca" {
- return fmt.Errorf("invalid tls-verify value: %s (must be 'identity' or 'ca')", value)
- }
+ mode := strings.ToLower(value)
+ if mode != "identity" && mode != "ca" {
+ return fmt.Errorf("invalid value for tls-verify: %s (must be 'identity' or 'ca')", value)
+ }
if cfg.TLS == nil {
if cfg.TLSVerify == "" {
cfg.TLSVerify = "identity"
}
switch cfg.TLSConfig {
case "false", "":
// ...This means every DSN, even ones without You likely want to either:
Right now Also applies to: 198-233, 392-394, 684-691 |
||
|
|
@@ -195,21 +196,39 @@ func (cfg *Config) normalize() error { | |
| } | ||
|
|
||
| if cfg.TLS == nil { | ||
| // Default TLSVerify to identity if not specified | ||
| if cfg.TLSVerify == "" { | ||
| cfg.TLSVerify = "identity" | ||
| } | ||
|
|
||
| switch cfg.TLSConfig { | ||
| case "false", "": | ||
| // don't set anything | ||
| case "true": | ||
| // Reject tls=true with tls-verify=ca since it provides minimal security | ||
| if cfg.TLSVerify == "ca" { | ||
| return errors.New("tls-verify=ca requires a custom TLS config with specific CA certificates (use tls=<config-name>); tls=true is not supported with tls-verify=ca") | ||
| } | ||
| // System CA pool with full verification (identity check) | ||
| cfg.TLS = &tls.Config{} | ||
| case "skip-verify": | ||
| cfg.TLS = &tls.Config{InsecureSkipVerify: true} | ||
| case "preferred": | ||
| cfg.TLS = &tls.Config{InsecureSkipVerify: true} | ||
| cfg.AllowFallbackToPlaintext = true | ||
| default: | ||
| // Custom registered TLS config | ||
| cfg.TLS = getTLSConfigClone(cfg.TLSConfig) | ||
| if cfg.TLS == nil { | ||
| return errors.New("invalid value / unknown config name: " + cfg.TLSConfig) | ||
| } | ||
|
|
||
| // Apply tls-verify to custom config | ||
| if cfg.TLSVerify == "ca" { | ||
| // Preserve all settings from custom config, only modify verification behavior | ||
| rootCAs := cfg.TLS.RootCAs | ||
| cfg.TLS = createVerifyCAConfig(cfg.TLS, rootCAs) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -370,6 +389,10 @@ func (cfg *Config) FormatDSN() string { | |
| writeDSNParam(&buf, &hasParam, "tls", url.QueryEscape(cfg.TLSConfig)) | ||
| } | ||
|
|
||
| if cfg.TLSVerify != "" && cfg.TLSVerify != "identity" { | ||
| writeDSNParam(&buf, &hasParam, "tls-verify", cfg.TLSVerify) | ||
| } | ||
|
|
||
| if cfg.WriteTimeout > 0 { | ||
| writeDSNParam(&buf, &hasParam, "writeTimeout", cfg.WriteTimeout.String()) | ||
| } | ||
|
|
@@ -658,6 +681,14 @@ func parseDSNParams(cfg *Config, params string) (err error) { | |
| cfg.TLSConfig = name | ||
| } | ||
|
|
||
| // TLS verification level | ||
| case "tls-verify": | ||
| mode := strings.ToLower(value) | ||
| if mode != "identity" && mode != "ca" { | ||
| return fmt.Errorf("invalid tls-verify value: %s (must be 'identity' or 'ca')", value) | ||
| } | ||
| cfg.TLSVerify = mode | ||
|
|
||
| // I/O write Timeout | ||
| case "writeTimeout": | ||
| cfg.WriteTimeout, err = time.ParseDuration(value) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.