Skip to content

Commit

Permalink
etcdmain: check TLS on gateway SRV records
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Aug 3, 2016
1 parent c2ba917 commit 8edbce5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions etcdmain/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
"fmt"
"net"
"os"
"strings"
"time"

"github.com/coreos/etcd/client"
"github.com/coreos/etcd/pkg/transport"
"github.com/coreos/etcd/proxy/tcpproxy"
"github.com/spf13/cobra"
)
Expand All @@ -30,6 +32,7 @@ var (
gatewayEndpoints []string
gatewayDNSCluster string
getewayRetryDelay time.Duration
gatewayCA string
)

var (
Expand Down Expand Up @@ -64,6 +67,7 @@ func newGatewayStartCommand() *cobra.Command {

cmd.Flags().StringVar(&gatewayListenAddr, "listen-addr", "127.0.0.1:23790", "listen address")
cmd.Flags().StringVar(&gatewayDNSCluster, "discovery-srv", "", "DNS domain used to bootstrap initial cluster")
cmd.Flags().StringVar(&gatewayCA, "trusted-ca-file", "", "path to the client server TLS CA file.")

cmd.Flags().StringSliceVar(&gatewayEndpoints, "endpoints", []string{"127.0.0.1:2379"}, "comma separated etcd cluster endpoints")

Expand All @@ -81,6 +85,37 @@ func startGateway(cmd *cobra.Command, args []string) {
os.Exit(1)
}
plog.Infof("discovered the cluster %s from %s", eps, gatewayDNSCluster)

// confirm TLS connections are good
tlsInfo := transport.TLSInfo{
TrustedCAFile: gatewayCA,
ServerName: gatewayDNSCluster,
}
t, err := transport.NewTransport(tlsInfo, 5*time.Second)
if err != nil {
plog.Fatalf("could not create transport (%v)", err)
}
for _, ep := range eps {
if !strings.HasPrefix(ep, "https://") {
if gatewayCA != "" {
plog.Errorf("rejecting insecure SRV record %q", ep)
continue
}
endpoints = append(endpoints, ep)
continue
}
conn, cerr := t.Dial("tcp", ep[len("https://"):])
if cerr != nil {
plog.Errorf("rejecting SRV record %q on dial (%v)", ep, err)
continue
}
conn.Close()
endpoints = append(endpoints, ep)
}
}

if len(endpoints) == 0 {
plog.Fatalf("no endpoints found")
}

l, err := net.Listen("tcp", gatewayListenAddr)
Expand Down

0 comments on commit 8edbce5

Please sign in to comment.