etcdmain: create self-signed certs when listening on https for httpproxy

Fixes failures from TestCtlV3PutClientAutoTLS in proxy coverage tests.
release-3.3
Anthony Romano 2017-07-24 15:37:05 -07:00
parent e9a7f3551b
commit 51d7786050
1 changed files with 20 additions and 1 deletions

View File

@ -314,9 +314,28 @@ func startProxy(cfg *config) error {
if cfg.isReadonlyProxy() {
ph = httpproxy.NewReadonlyHandler(ph)
}
// setup self signed certs when serving https
cHosts, cTLS := []string{}, false
for _, u := range cfg.LCUrls {
cHosts = append(cHosts, u.Host)
cTLS = cTLS || u.Scheme == "https"
}
for _, u := range cfg.ACUrls {
cHosts = append(cHosts, u.Host)
cTLS = cTLS || u.Scheme == "https"
}
listenerTLS := cfg.ClientTLSInfo
if cfg.ClientAutoTLS && cTLS {
listenerTLS, err = transport.SelfCert(filepath.Join(cfg.Dir, "clientCerts"), cHosts)
if err != nil {
plog.Fatalf("proxy: could not initialize self-signed client certs (%v)", err)
}
}
// Start a proxy server goroutine for each listen address
for _, u := range cfg.LCUrls {
l, err := transport.NewListener(u.Host, u.Scheme, &cfg.ClientTLSInfo)
l, err := transport.NewListener(u.Host, u.Scheme, &listenerTLS)
if err != nil {
return err
}