@@ -14,6 +14,8 @@ import (
1414type TLSConfig struct {
1515 // The CA cert to use for the targets.
1616 CAFile string `yaml:"ca_file"`
17+ // Trust RootCAs provided by the host
18+ TrustRootCA bool `yaml:"trust_root_ca"`
1719 // The client cert file for the targets.
1820 CertFile string `yaml:"cert_file"`
1921 // The client key file for the targets.
@@ -34,7 +36,7 @@ func NewTLSConfig(cfg *TLSConfig) (*tls.Config, error) {
3436 if err != nil {
3537 return nil , err
3638 }
37- if ! updateRootCA (tlsConfig , b ) {
39+ if ! updateRootCA (tlsConfig , b , cfg . TrustRootCA ) {
3840 return nil , fmt .Errorf ("unable to use specified CA cert %s" , cfg .CAFile )
3941 }
4042 }
@@ -68,8 +70,18 @@ func readCAFile(f string) ([]byte, error) {
6870}
6971
7072// updateRootCA parses the given byte slice as a series of PEM encoded certificates and updates tls.Config.RootCAs.
71- func updateRootCA (cfg * tls.Config , b []byte ) bool {
72- caCertPool := x509 .NewCertPool ()
73+ func updateRootCA (cfg * tls.Config , b []byte , trustRootCA bool ) bool {
74+ var caCertPool * x509.CertPool
75+ var err error
76+ if trustRootCA {
77+ caCertPool , err = x509 .SystemCertPool ()
78+ if err != nil {
79+ caCertPool = x509 .NewCertPool ()
80+ }
81+ } else {
82+ caCertPool = x509 .NewCertPool ()
83+ }
84+
7385 if ! caCertPool .AppendCertsFromPEM (b ) {
7486 return false
7587 }
0 commit comments