|
4 | 4 | "context" |
5 | 5 | "crypto/tls" |
6 | 6 | "fmt" |
| 7 | + "net/url" |
7 | 8 | "os" |
8 | 9 | "strings" |
9 | 10 | "time" |
@@ -83,12 +84,27 @@ func (f FlagsRemoteStore) setupGrpcConnection(parent context.Context, metrics *g |
83 | 84 | if f.Insecure { |
84 | 85 | opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) |
85 | 86 | } else { |
86 | | - opts = append(opts, |
87 | | - grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ |
88 | | - // Support only TLS1.3+ with valid CA certificates |
89 | | - MinVersion: tls.VersionTLS13, |
90 | | - InsecureSkipVerify: f.InsecureSkipVerify, |
91 | | - }))) |
| 87 | + tlsConfig := tls.Config{ |
| 88 | + // Support only TLS1.3+ with valid CA certificates |
| 89 | + MinVersion: tls.VersionTLS13, |
| 90 | + InsecureSkipVerify: f.InsecureSkipVerify, |
| 91 | + } |
| 92 | + |
| 93 | + if f.ClientKey != "" && f.ClientCert != "" { |
| 94 | + cert, err := tls.LoadX509KeyPair(f.ClientCert, f.ClientKey) |
| 95 | + if err != nil { |
| 96 | + return nil, fmt.Errorf("failed to load client certificates: %w", err) |
| 97 | + } |
| 98 | + tlsConfig.Certificates = []tls.Certificate{cert} |
| 99 | + |
| 100 | + url, err := url.Parse(f.Address) |
| 101 | + if err != nil { |
| 102 | + return nil, fmt.Errorf("couldn't parse address (%s): %w", f.Address, err) |
| 103 | + } |
| 104 | + tlsConfig.ServerName = url.Hostname() |
| 105 | + } |
| 106 | + |
| 107 | + opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(&tlsConfig))) |
92 | 108 | } |
93 | 109 |
|
94 | 110 | // Auth |
|
0 commit comments