Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
  • Loading branch information
Connor1996 committed Dec 11, 2023
1 parent c534e02 commit ebadbfa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions pkg/dashboard/adapter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func GenDashboardConfig(srv *server.Server) (*config.Config, error) {
if dashboardCfg.ClusterTLSConfig, err = cfg.Security.ToTLSConfig(); err != nil {
return nil, err
}
if dashboardCfg.ClusterTLSInfo, err = cfg.Security.ToTLSInfo(); err != nil {
return nil, err
}
if dashboardCfg.TiDBTLSConfig, err = cfg.Dashboard.ToTiDBTLSConfig(); err != nil {
return nil, err
}
Expand Down
32 changes: 20 additions & 12 deletions pkg/utils/grpcutil/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ type TLSConfig struct {
SSLKEYBytes []byte
}

// TOTLSInfo converts TLSConfig to transport.TLSInfo.
func (s TLSConfig) ToTLSInfo() (*transport.TLSInfo, error) {
if len(s.CertPath) == 0 && len(s.KeyPath) == 0 {
return nil, nil
}
allowedCN, err := s.GetOneAllowedCN()
if err != nil {
return nil, err
}

return &transport.TLSInfo{
CertFile: s.CertPath,
KeyFile: s.KeyPath,
TrustedCAFile: s.CAPath,
AllowedCN: allowedCN,
}, nil
}

// ToTLSConfig generates tls config.
func (s TLSConfig) ToTLSConfig() (*tls.Config, error) {
if len(s.SSLCABytes) != 0 || len(s.SSLCertBytes) != 0 || len(s.SSLKEYBytes) != 0 {
Expand All @@ -77,19 +95,9 @@ func (s TLSConfig) ToTLSConfig() (*tls.Config, error) {
}, nil
}

if len(s.CertPath) == 0 && len(s.KeyPath) == 0 {
return nil, nil
}
allowedCN, err := s.GetOneAllowedCN()
tlsInfo, err := s.ToTLSInfo()
if err != nil {
return nil, err
}

tlsInfo := transport.TLSInfo{
CertFile: s.CertPath,
KeyFile: s.KeyPath,
TrustedCAFile: s.CAPath,
AllowedCN: allowedCN,
return nil, errs.ErrEtcdTLSConfig.Wrap(err).GenWithStackByCause()
}

tlsConfig, err := tlsInfo.ClientConfig()
Expand Down

0 comments on commit ebadbfa

Please sign in to comment.