Description
Issue description
On a large set of machines where:
- Most database servers support TLS and have a TLS certificate that is valid (CA, hostname, etc)
- Some database servers are running without TLS support
- Some database servers are running with require_secure_transport
And a go program that needs to connect to all of the servers (e.g. a monitoring application)
The program has a list with hostname, username and password for each server.
If it connects with tls=true
or tls=skip-verify
then this works for all servers except for those who don't support TLS.
If it connects without setting tls
or by setting tls=false
then it works for all servers except for those who run with require_secure_transport
.
Example code
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
// port 8011 runs with require_secure_transport
// port 5724 runs with skip-ssl
dsns := []string{
"msandbox:msandbox@tcp([::1]:8011)/test",
"msandbox:msandbox@tcp([::1]:8011)/test?tls=skip-verify",
"msandbox:msandbox@tcp([::1]:5724)/test",
"msandbox:msandbox@tcp([::1]:5724)/test?tls=skip-verify",
}
for _, dsn := range dsns {
fmt.Printf("Trying %s\n", dsn)
db, err := sql.Open("mysql", dsn)
if err != nil {
panic(err.Error())
}
defer db.Close()
err = db.Ping()
if err != nil {
fmt.Printf("Result: %s\n", err.Error())
} else {
print("Result: ok\n")
}
}
}
Output:
Trying msandbox:msandbox@tcp([::1]:8011)/test
Result: Error 3159: Connections using insecure transport are prohibited while --require_secure_transport=ON.
Trying msandbox:msandbox@tcp([::1]:8011)/test?tls=skip-verify
Result: ok
Trying msandbox:msandbox@tcp([::1]:5724)/test
Result: ok
Trying msandbox:msandbox@tcp([::1]:5724)/test?tls=skip-verify
skip-verifyResult: TLS requested but server does not support TLS
Configuration
Driver version (or git SHA):
6be42e0
Go version: run go version
in your console
go version go1.11.2 linux/amd64
Server version: E.g. MySQL 5.6, MariaDB 10.0.20
MySQL 8.0.11, MySQL 5.7.24
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
Fedora 29 (but target is CentOS 7)
Possible solutions
- Add a
tls=optional
option which results in TLS when the server has the SSL flag set and in clear-text when the server doesn't have this flag set. - Catch Error 3159 and re-connect with
tls=true
ortls=skip-verify
in the driver or application. - Catch the
ErrNoTLS
error in the application and re-connect withtls=false
in the application.
iirc option 2 is what https://github.com/github/orchestrator does at the moment.
Note that option 2 causes most connections to be clear-text and option 3 causes most connections to use TLS.