Skip to content

Commit

Permalink
Fix serverName config bug for tls health checks
Browse files Browse the repository at this point in the history
The option was available but without effect.
  • Loading branch information
mcorbin committed Dec 24, 2022
1 parent 8517d98 commit fd225f2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion discovery/http/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type HTTPDiscovery struct {
// New creates a new HTTP Discovery
func New(logger *zap.Logger, config *Configuration, checkComponent *healthcheck.Component, counter *prom.CounterVec, histogram *prom.HistogramVec) (*HTTPDiscovery, error) {
protocol := "http"
tlsConfig, err := tls.GetTLSConfig(config.Key, config.Cert, config.Cacert, config.Insecure)
tlsConfig, err := tls.GetTLSConfig(config.Key, config.Cert, config.Cacert, "", config.Insecure)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *HTTPConfiguration) UnmarshalYAML(unmarshal func(interface{}) error) err
// NewHTTPExporter creates a new HTTP exporter
func NewHTTPExporter(logger *zap.Logger, config *HTTPConfiguration) (*HTTPExporter, error) {
protocol := "http"
tlsConfig, err := tls.GetTLSConfig(config.Key, config.Cert, config.Cacert, config.Insecure)
tlsConfig, err := tls.GetTLSConfig(config.Key, config.Cert, config.Cacert, "", config.Insecure)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/riemann.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/pkg/errors"
"github.com/riemann/riemann-go-client"
riemanngo "github.com/riemann/riemann-go-client"
"go.uber.org/zap"

"github.com/mcorbin/cabourotte/healthcheck"
Expand Down Expand Up @@ -64,7 +64,7 @@ func getClient(config *RiemannConfiguration) (riemanngo.Client, error) {
var client riemanngo.Client
url := net.JoinHostPort(config.Host, fmt.Sprintf("%d", config.Port))
if config.Key != "" || config.Cert != "" || config.Cacert != "" {
tlsConfig, err := tls.GetTLSConfig(config.Key, config.Cert, config.Cacert, config.Insecure)
tlsConfig, err := tls.GetTLSConfig(config.Key, config.Cert, config.Cacert, "", config.Insecure)
if err != nil {
return nil, errors.Wrapf(err, "Fail to build the Riemann exporter tls configuration")
}
Expand Down
2 changes: 1 addition & 1 deletion healthcheck/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (h *TLSHealthcheck) buildURL() {
// Initialize the healthcheck.
func (h *TLSHealthcheck) Initialize() error {
h.buildURL()
tlsConfig, err := tls.GetTLSConfig(h.Config.Key, h.Config.Cert, h.Config.Cacert, h.Config.Insecure)
tlsConfig, err := tls.GetTLSConfig(h.Config.Key, h.Config.Cert, h.Config.Cacert, h.Config.ServerName, h.Config.Insecure)
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// GetTLSConfig returns a tls configuration
func GetTLSConfig(keyPath string, certPath string, cacertPath string, insecure bool) (*tls.Config, error) {
func GetTLSConfig(keyPath string, certPath string, cacertPath string, serverName string, insecure bool) (*tls.Config, error) {
tlsConfig := &tls.Config{}
if keyPath != "" {
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
Expand All @@ -32,6 +32,9 @@ func GetTLSConfig(keyPath string, certPath string, cacertPath string, insecure b
tlsConfig.RootCAs = caCertPool

}
if serverName != "" {
tlsConfig.ServerName = serverName
}
tlsConfig.InsecureSkipVerify = insecure
return tlsConfig, nil
}

0 comments on commit fd225f2

Please sign in to comment.