Skip to content

Commit d7b1bef

Browse files
embroedegaius-qi
authored andcommitted
feat: enable configuration of the tls parameter for the mysql connection. i.e. tls=preferred (#1300)
* Default to tls=preferred for mysql connection For communication from manager to mysql server, use `tls=preferred` parameter to enable TLS whenever possible. Signed-off-by: Edward Broeder <[email protected]> * Make mysql tls parameter configurable Allow the user to specify the tls setting for the mysql connection. An example would be setting tls to "preferred", or "true". This is separate to the tlsConfig config parameter, which is used to set up a custom tls config, where tls key/certs are specified. See the tls parameter section in the below link: https://pkg.go.dev/github.com/go-sql-driver/mysql#section-readme Signed-off-by: Edward Broeder <[email protected]>
1 parent 4f2f760 commit d7b1bef

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

manager/config/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ type MysqlConfig struct {
9191
// Enable migration
9292
Migrate bool `yaml:"migrate" mapstructure:"migrate"`
9393

94-
// TLS configuration
94+
// TLS mode (can be one of "true", "false", "skip-verify", or "preferred")
95+
TLSConfig string `yaml:"tlsConfig" mapstructure:"tlsConfig"`
96+
97+
// Custom TLS configuration (overrides "TLSConfig" setting above)
9598
TLS *TLSConfig `yaml:"tls" mapstructure:"tls"`
9699
}
97100

manager/config/config_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ func TestManagerConfig_Load(t *testing.T) {
4848
},
4949
Database: &DatabaseConfig{
5050
Mysql: &MysqlConfig{
51-
User: "foo",
52-
Password: "foo",
53-
Host: "foo",
54-
Port: 3306,
55-
DBName: "foo",
51+
User: "foo",
52+
Password: "foo",
53+
Host: "foo",
54+
Port: 3306,
55+
DBName: "foo",
56+
TLSConfig: "preferred",
5657
TLS: &TLSConfig{
5758
Cert: "foo",
5859
Key: "foo",

manager/config/testdata/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ database:
1717
host: foo
1818
port: 3306
1919
dbname: foo
20+
tlsConfig: preferred
2021
tls:
2122
cert: foo
2223
key: foo

manager/database/mysql.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func formatDSN(cfg *config.MysqlConfig) (string, error) {
9494
if err := mysql.RegisterTLSConfig("custom", tls); err != nil {
9595
return "", err
9696
}
97+
} else if cfg.TLSConfig != "" { // If no custom config is specified, use tlsConfig parameter if it is set
98+
mysqlCfg.TLSConfig = cfg.TLSConfig
9799
}
98100

99101
return mysqlCfg.FormatDSN(), nil

0 commit comments

Comments
 (0)