Skip to content

Commit

Permalink
config: tls verification can be disabled (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahrinh authored Aug 19, 2019
1 parent b071d4e commit 1f188a0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
10 changes: 8 additions & 2 deletions config.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
"timeout": 5,
"max-idle-conns": 1000,
"idle-conn-timeout": 30,
"disable-compression": true
"disable-compression": true,
"tls": {
"insecure-skip-verify": true
}
},
"to-sidecar": {
"timeout": 2,
"max-idle-conns": 1000,
"idle-conn-timeout": 30,
"disable-compression": true
"disable-compression": true,
"tls": {
"insecure-skip-verify": true
}
},
}
}
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ type HTTPClientConfig struct {
MaxIdleConns int `mapstructure:"max-idle-conns"`
IdleConnTimeout int `mapstructure:"idle-conn-timeout"`
DisableCompression bool `mapstructure:"disable-compression"`
TLS TLS `mapstructure:"tls"`
}

// TLS holds the configuration of TLS
type TLS struct {
InsecureSkipVerify bool `mapstructure:"insecure-skip-verify"`
}
8 changes: 5 additions & 3 deletions proxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package canaryrouter

import (
"crypto/tls"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -28,14 +29,14 @@ func BuildProxies(configClient config.HTTPClientConfig, mainTargetURL, canaryTar
if err != nil {
return nil, errors.Trace(err)
}
proxyMain.Transport = newTransport(configClient.MaxIdleConns, configClient.IdleConnTimeout, configClient.DisableCompression)
proxyMain.Transport = newTransport(configClient.MaxIdleConns, configClient.IdleConnTimeout, configClient.DisableCompression, configClient.TLS)
proxyMain.ErrorLog = log.New(os.Stderr, "[proxy-main] ", log.LstdFlags|log.Llongfile)

proxyCanary, err := newReverseProxy(canaryTargetURL)
if err != nil {
return nil, errors.Trace(err)
}
proxyCanary.Transport = newTransport(configClient.MaxIdleConns, configClient.IdleConnTimeout, configClient.DisableCompression)
proxyCanary.Transport = newTransport(configClient.MaxIdleConns, configClient.IdleConnTimeout, configClient.DisableCompression, configClient.TLS)
proxyCanary.ErrorLog = log.New(os.Stderr, "[proxy-canary] ", log.LstdFlags|log.Llongfile)

proxies := &Proxy{
Expand All @@ -46,11 +47,12 @@ func BuildProxies(configClient config.HTTPClientConfig, mainTargetURL, canaryTar
return proxies, nil
}

func newTransport(maxIdleConns, idleConnTimeout int, disableCompression bool) *http.Transport {
func newTransport(maxIdleConns, idleConnTimeout int, disableCompression bool, tlsConfig config.TLS) *http.Transport {
return &http.Transport{
MaxIdleConns: maxIdleConns,
IdleConnTimeout: time.Duration(idleConnTimeout) * time.Second,
DisableCompression: disableCompression,
TLSClientConfig: &tls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify},
}
}

Expand Down
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"bytes"
"context"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -53,6 +54,7 @@ func NewServer(config config.Config) (*Server, error) {
MaxIdleConns: config.Client.Sidecar.MaxIdleConns,
IdleConnTimeout: time.Duration(config.Client.Sidecar.IdleConnTimeout) * time.Second,
DisableCompression: config.Client.Sidecar.DisableCompression,
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.Client.Sidecar.TLS.InsecureSkipVerify},
}

sidecarURL, err := url.Parse(server.config.SidecarURL)
Expand Down

0 comments on commit 1f188a0

Please sign in to comment.