Skip to content

Commit 1347bf7

Browse files
author
chrisfarms
committed
Ensure ServerName is set in mysql TLS config in healthcheck app
The healthcheck app was updated to use a more recent Go version and the latest compatible depenencies. The newer Go standard library is stricter about ensuring that the ServerName field is correctly set for TLS. The current version of the mysql library does not set the required `ServerName` when using a connection string with 'tls=true'. A fix has been already been merged and will be released in the next version (v1.4) of the go-sql-driver/mysql lib. See go-sql-driver/mysql#564 To workaround the problem in the meantime, we register a "custom" TLS config which correctly sets the ServerName.
1 parent b67cc8b commit 1347bf7

File tree

1 file changed

+7
-2
lines changed
  • platform-tests/example-apps/healthcheck

1 file changed

+7
-2
lines changed

platform-tests/example-apps/healthcheck/db.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package main
22

33
import (
4+
"crypto/tls"
45
"database/sql"
56
"fmt"
67
"net/http"
78
"net/url"
89
"os"
910

10-
_ "github.com/go-sql-driver/mysql"
11+
mysql "github.com/go-sql-driver/mysql"
1112
_ "github.com/lib/pq"
1213
)
1314

@@ -104,7 +105,11 @@ func mysqlOpen(dbu string, ssl bool) (*sql.DB, error) {
104105
}
105106

106107
if ssl {
107-
u.RawQuery = "tls=true"
108+
u.RawQuery = "tls=custom"
109+
if err := mysql.RegisterTLSConfig("custom", &tls.Config{ServerName: u.Hostname()}); err != nil {
110+
return nil, err
111+
}
112+
108113
} else {
109114
u.RawQuery = "tls=false"
110115
}

0 commit comments

Comments
 (0)