Skip to content

Commit 67d27ed

Browse files
authored
Merge pull request #245 from aknuds1/chore/hide-tls-params
server: Removing advanced TLS config parameters - BREAKING CHANGE
2 parents e3b70df + 2e9b589 commit 67d27ed

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

server/server.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ type SignalHandler interface {
5050
Stop()
5151
}
5252

53+
// TLSConfig contains TLS parameters for Config.
54+
type TLSConfig struct {
55+
TLSCertPath string `yaml:"cert_file"`
56+
TLSKeyPath string `yaml:"key_file"`
57+
ClientAuth string `yaml:"client_auth_type"`
58+
ClientCAs string `yaml:"client_ca_file"`
59+
}
60+
5361
// Config for a Server
5462
type Config struct {
5563
MetricsNamespace string `yaml:"-"`
@@ -62,8 +70,8 @@ type Config struct {
6270
GRPCListenPort int `yaml:"grpc_listen_port"`
6371
GRPCConnLimit int `yaml:"grpc_listen_conn_limit"`
6472

65-
HTTPTLSConfig web.TLSStruct `yaml:"http_tls_config"`
66-
GRPCTLSConfig web.TLSStruct `yaml:"grpc_tls_config"`
73+
HTTPTLSConfig TLSConfig `yaml:"http_tls_config"`
74+
GRPCTLSConfig TLSConfig `yaml:"grpc_tls_config"`
6775

6876
RegisterInstrumentation bool `yaml:"register_instrumentation"`
6977
ExcludeRequestInLog bool `yaml:"-"`
@@ -239,15 +247,25 @@ func New(cfg Config) (*Server, error) {
239247
var httpTLSConfig *tls.Config
240248
if len(cfg.HTTPTLSConfig.TLSCertPath) > 0 && len(cfg.HTTPTLSConfig.TLSKeyPath) > 0 {
241249
// Note: ConfigToTLSConfig from prometheus/exporter-toolkit is awaiting security review.
242-
httpTLSConfig, err = web.ConfigToTLSConfig(&cfg.HTTPTLSConfig)
250+
httpTLSConfig, err = web.ConfigToTLSConfig(&web.TLSStruct{
251+
TLSCertPath: cfg.HTTPTLSConfig.TLSCertPath,
252+
TLSKeyPath: cfg.HTTPTLSConfig.TLSKeyPath,
253+
ClientAuth: cfg.HTTPTLSConfig.ClientAuth,
254+
ClientCAs: cfg.HTTPTLSConfig.ClientCAs,
255+
})
243256
if err != nil {
244257
return nil, fmt.Errorf("error generating http tls config: %v", err)
245258
}
246259
}
247260
var grpcTLSConfig *tls.Config
248261
if len(cfg.GRPCTLSConfig.TLSCertPath) > 0 && len(cfg.GRPCTLSConfig.TLSKeyPath) > 0 {
249262
// Note: ConfigToTLSConfig from prometheus/exporter-toolkit is awaiting security review.
250-
grpcTLSConfig, err = web.ConfigToTLSConfig(&cfg.GRPCTLSConfig)
263+
grpcTLSConfig, err = web.ConfigToTLSConfig(&web.TLSStruct{
264+
TLSCertPath: cfg.GRPCTLSConfig.TLSCertPath,
265+
TLSKeyPath: cfg.GRPCTLSConfig.TLSKeyPath,
266+
ClientAuth: cfg.GRPCTLSConfig.ClientAuth,
267+
ClientCAs: cfg.GRPCTLSConfig.ClientCAs,
268+
})
251269
if err != nil {
252270
return nil, fmt.Errorf("error generating grpc tls config: %v", err)
253271
}

server/server_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
google_protobuf "github.com/golang/protobuf/ptypes/empty"
2323
"github.com/gorilla/mux"
2424
"github.com/prometheus/client_golang/prometheus"
25-
"github.com/prometheus/exporter-toolkit/web"
2625
"github.com/stretchr/testify/require"
2726
"github.com/weaveworks/common/httpgrpc"
2827
"github.com/weaveworks/common/logging"
@@ -522,13 +521,13 @@ func TestTLSServer(t *testing.T) {
522521
HTTPListenNetwork: DefaultNetwork,
523522
HTTPListenAddress: "localhost",
524523
HTTPListenPort: 9193,
525-
HTTPTLSConfig: web.TLSStruct{
524+
HTTPTLSConfig: TLSConfig{
526525
TLSCertPath: "certs/server.crt",
527526
TLSKeyPath: "certs/server.key",
528527
ClientAuth: "RequireAndVerifyClientCert",
529528
ClientCAs: "certs/root.crt",
530529
},
531-
GRPCTLSConfig: web.TLSStruct{
530+
GRPCTLSConfig: TLSConfig{
532531
TLSCertPath: "certs/server.crt",
533532
TLSKeyPath: "certs/server.key",
534533
ClientAuth: "VerifyClientCertIfGiven",

0 commit comments

Comments
 (0)