Skip to content

Commit

Permalink
add SSL MinVersion
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Jul 29, 2024
1 parent 5d77447 commit 59fffd2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions client/pd_service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,17 @@ func TestServiceClientScheme(t *testing.T) {
re.Equal("http://127.0.0.1:2379", cli.GetURL())
cli = newPDServiceClient(modifyURLScheme("http://127.0.0.1:2379", nil), modifyURLScheme("127.0.0.1:2379", nil), nil, false)
re.Equal("http://127.0.0.1:2379", cli.GetURL())
cli = newPDServiceClient(modifyURLScheme("127.0.0.1:2379", &tls.Config{}), modifyURLScheme("127.0.0.1:2379", &tls.Config{}), nil, false)
cli = newPDServiceClient(modifyURLScheme("127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), modifyURLScheme("127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), nil, false)
re.Equal("https://127.0.0.1:2379", cli.GetURL())
cli = newPDServiceClient(modifyURLScheme("https://127.0.0.1:2379", &tls.Config{}), modifyURLScheme("127.0.0.1:2379", &tls.Config{}), nil, false)
cli = newPDServiceClient(modifyURLScheme("https://127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), modifyURLScheme("127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), nil, false)
re.Equal("https://127.0.0.1:2379", cli.GetURL())
cli = newPDServiceClient(modifyURLScheme("http://127.0.0.1:2379", &tls.Config{}), modifyURLScheme("127.0.0.1:2379", &tls.Config{}), nil, false)
cli = newPDServiceClient(modifyURLScheme("http://127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), modifyURLScheme("127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), nil, false)
re.Equal("https://127.0.0.1:2379", cli.GetURL())
}

func TestSchemeFunction(t *testing.T) {
re := require.New(t)
tlsCfg := &tls.Config{}
tlsCfg := &tls.Config{MinVersion: tls.VersionTLS12}

endpoints1 := []string{
"http://tc-pd:2379",
Expand Down
3 changes: 2 additions & 1 deletion client/tlsutil/tlsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (info TLSInfo) ClientConfig() (*tls.Config, error) {
return nil, err
}
} else {
cfg = &tls.Config{ServerName: info.ServerName}
cfg = &tls.Config{ServerName: info.ServerName, MinVersion: tls.VersionTLS12}

Check warning on line 82 in client/tlsutil/tlsconfig.go

View check run for this annotation

Codecov / codecov/patch

client/tlsutil/tlsconfig.go#L82

Added line #L82 was not covered by tests
}
cfg.InsecureSkipVerify = info.InsecureSkipVerify

Expand Down Expand Up @@ -188,6 +188,7 @@ func (s TLSConfig) ToTLSConfig() (*tls.Config, error) {
Certificates: certificates,
RootCAs: certPool,
NextProtos: []string{"h2", "http/1.1"}, // specify `h2` to let Go use HTTP/2.
MinVersion: tls.VersionTLS12,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/utils/grpcutil/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (s TLSConfig) ToTLSConfig() (*tls.Config, error) {
Certificates: certificates,
RootCAs: certPool,
NextProtos: []string{"h2", "http/1.1"}, // specify `h2` to let Go use HTTP/2.
MinVersion: tls.VersionTLS12,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/netutil/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestIsEnableHttps(t *testing.T) {
httpClient = &http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{},
TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12},
},
}
re.False(IsEnableHTTPS(httpClient))
Expand Down

0 comments on commit 59fffd2

Please sign in to comment.