Skip to content

Commit 79df0d1

Browse files
Adding --ssl-insecure flag
1 parent 5319157 commit 79df0d1

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

go/base/context.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,16 @@ type MigrationContext struct {
9494
AliyunRDS bool
9595
GoogleCloudPlatform bool
9696

97-
config ContextConfig
98-
configMutex *sync.Mutex
99-
ConfigFile string
100-
CliUser string
101-
CliPassword string
102-
UseTLS bool
103-
TLSCACertificate string
104-
CliMasterUser string
105-
CliMasterPassword string
97+
config ContextConfig
98+
configMutex *sync.Mutex
99+
ConfigFile string
100+
CliUser string
101+
CliPassword string
102+
UseTLS bool
103+
TLSInsecureSkipVerify bool
104+
TLSCACertificate string
105+
CliMasterUser string
106+
CliMasterPassword string
106107

107108
HeartbeatIntervalMilliseconds int64
108109
defaultNumRetries int64

go/cmd/gh-ost/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func main() {
5757

5858
flag.BoolVar(&migrationContext.UseTLS, "ssl", false, "Enable SSL encrypted connections to MySQL hosts")
5959
flag.StringVar(&migrationContext.TLSCACertificate, "ssl-ca", "", "CA certificate in PEM format for TLS connections to MySQL hosts. Requires --ssl")
60+
flag.StringVar(&migrationContext.TLSInsecureSkipVerify, "ssl-insecure", false, "Do not verify that the TLS connection is secure. Requires --ssl")
6061

6162
flag.StringVar(&migrationContext.DatabaseName, "database", "", "database name (mandatory)")
6263
flag.StringVar(&migrationContext.OriginalTableName, "table", "", "table name (mandatory)")
@@ -201,6 +202,9 @@ func main() {
201202
if migrationContext.TLSCACertificate != "" && !migrationContext.UseTLS {
202203
log.Fatalf("--ssl-ca requires --ssl")
203204
}
205+
if migrationContext.TLSInsecureSkipVerify && !migrationContext.UseTLS {
206+
log.Fatalf("--ssl-insecure requires --ssl")
207+
}
204208
if *replicationLagQuery != "" {
205209
log.Warningf("--replication-lag-query is deprecated")
206210
}

go/mysql/connection.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,30 @@ func (this *ConnectionConfig) Equals(other *ConnectionConfig) bool {
5858
}
5959

6060
func (this *ConnectionConfig) UseTLS(caCertificatePath string) error {
61-
skipVerify := caCertificatePath == ""
6261
var rootCertPool *x509.CertPool
63-
if !skipVerify {
64-
rootCertPool = x509.NewCertPool()
65-
pem, err := ioutil.ReadFile(caCertificatePath)
66-
if err != nil {
67-
return err
68-
}
69-
if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
70-
return errors.New("could not add ca certificate to cert pool")
62+
var err error
63+
64+
if !this.TLSInsecureSkipVerify {
65+
if caCertificatePath == "" {
66+
rootCertPool, err = x509.SystemCertPool()
67+
if err != nil {
68+
return err
69+
}
70+
} else {
71+
rootCertPool = x509.NewCertPool()
72+
pem, err := ioutil.ReadFile(caCertificatePath)
73+
if err != nil {
74+
return err
75+
}
76+
if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
77+
return errors.New("could not add ca certificate to cert pool")
78+
}
7179
}
7280
}
7381

7482
this.tlsConfig = &tls.Config{
7583
RootCAs: rootCertPool,
76-
InsecureSkipVerify: skipVerify,
84+
InsecureSkipVerify: this.TLSInsecureSkipVerify,
7785
}
7886

7987
return mysql.RegisterTLSConfig(this.Key.StringCode(), this.tlsConfig)

0 commit comments

Comments
 (0)