Skip to content

Commit

Permalink
Add support for loading TLS system certificate store (#858)
Browse files Browse the repository at this point in the history
Previously a server CA had to be specified for TLS work, even if the
system store trusted the cert already.
  • Loading branch information
stanhu authored Dec 20, 2023
1 parent a9d587f commit 357e7ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions exporter/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func (e *Exporter) CreateClientTLSConfig() (*tls.Config, error) {
return nil, err
}
tlsConfig.RootCAs = certificates
} else {
// Load the system certificate pool
rootCAs, err := x509.SystemCertPool()
if err != nil {
return nil, err
}

tlsConfig.RootCAs = rootCAs
}

return &tlsConfig, nil
Expand Down
1 change: 1 addition & 0 deletions exporter/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestCreateClientTLSConfig(t *testing.T) {
ClientKeyFile: "../contrib/tls/redis.key"}, true},
{"load_ca_cert", Options{
CaCertFile: "../contrib/tls/ca.crt"}, true},
{"load_system_certs", Options{}, true},

// negative tests
{"nonexisting_client_files", Options{
Expand Down

0 comments on commit 357e7ac

Please sign in to comment.