Fallback to encrypted sleeve on a per-connection basis

If overlay encryption is required between peers, the fast datapath
forwarder returns an error rather than aborting the process, allowing
the overlay switch to fall back gracefully to an encrypted sleeve
overlay connection.
This commit is contained in:
Adam Harrison committed 2015-12-14 12:13:11 +00:00
1 parent d434b50dfc
commit 059cc65b55
6 files changed
+56 -11

No files matched your search

+1 -1
View File
@@ -96,7 +96,7 @@ func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, ro
RemoteConnection: *connRemote, // NB, we're taking a copy of connRemote here. RemoteConnection: *connRemote, // NB, we're taking a copy of connRemote here.
Router: router, Router: router,
TCPConn: tcpConn, TCPConn: tcpConn,
TrustRemote: false, TrustRemote: router.Trusts(connRemote),
uid: randUint64(), uid: randUint64(),
actionChan: actionChan, actionChan: actionChan,
errorChan: errorChan, errorChan: errorChan,
+15
View File
@@ -37,6 +37,7 @@ type Config struct {
Password []byte Password []byte
ConnLimit int ConnLimit int
PeerDiscovery bool PeerDiscovery bool
TrustedSubnets []*net.IPNet
} }
type Router struct { type Router struct {
@@ -181,3 +182,17 @@ func (router *Router) applyTopologyUpdate(update []byte) (PeerNameSet, PeerNameS
} }
return origUpdate, newUpdate, nil return origUpdate, newUpdate, nil
} }
func (router *Router) Trusts(remote *RemoteConnection) bool {
if tcpAddr, err := net.ResolveTCPAddr("tcp4", remote.remoteTCPAddr); err == nil {
for _, trustedSubnet := range router.TrustedSubnets {
if trustedSubnet.Contains(tcpAddr.IP) {
return true
}
}
} else {
// Should not happen as remoteTCPAddr was obtained from TCPConn
log.Errorf("Unable to parse remote TCP addr: %s", err)
}
return false
}
+26 -4
View File
@@ -69,6 +69,7 @@ func main() {
dnsEffectiveListenAddress string dnsEffectiveListenAddress string
iface *net.Interface iface *net.Interface
datapathName string datapathName string
trustedSubnetStr string
) )
mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit") mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit")
@@ -101,6 +102,8 @@ func main() {
mflag.StringVar(&dnsEffectiveListenAddress, []string{"-dns-effective-listen-address"}, "", "address DNS will actually be listening, after Docker port mapping") mflag.StringVar(&dnsEffectiveListenAddress, []string{"-dns-effective-listen-address"}, "", "address DNS will actually be listening, after Docker port mapping")
mflag.StringVar(&datapathName, []string{"-datapath"}, "", "ODP datapath name") mflag.StringVar(&datapathName, []string{"-datapath"}, "", "ODP datapath name")
mflag.StringVar(&trustedSubnetStr, []string{"-trusted-subnets"}, "", "Command separated list of trusted subnets in CIDR notation")
// crude way of detecting that we probably have been started in a // crude way of detecting that we probably have been started in a
// container, with `weave launch` --> suppress misleading paths in // container, with `weave launch` --> suppress misleading paths in
// mflags error messages. // mflags error messages.
@@ -193,10 +196,7 @@ func main() {
Log.Println("Communication between peers is unencrypted.") Log.Println("Communication between peers is unencrypted.")
} else { } else {
config.Password = []byte(password) config.Password = []byte(password)
Log.Println("Communication between peers is encrypted.") Log.Println("Communication between peers via untrusted networks is encrypted.")
// fastdp doesn't support encryption
fastDPOverlay = nil
} }
overlays := weave.NewOverlaySwitch() overlays := weave.NewOverlaySwitch()
@@ -237,6 +237,10 @@ func main() {
networkConfig.PacketLogging = nopPacketLogging{} networkConfig.PacketLogging = nopPacketLogging{}
} }
if config.TrustedSubnets, err = parseTrustedSubnets(trustedSubnetStr); err != nil {
Log.Fatal("Unable to parse trusted subnets: ", err)
}
router := weave.NewNetworkRouter(config, networkConfig, name, nickName, overlays) router := weave.NewNetworkRouter(config, networkConfig, name, nickName, overlays)
Log.Println("Our name is", router.Ourself) Log.Println("Our name is", router.Ourself)
@@ -405,6 +409,24 @@ func determineQuorum(initPeerCountFlag int, peers []string) uint {
return quorum return quorum
} }
func parseTrustedSubnets(trustedSubnetStr string) ([]*net.IPNet, error) {
trustedSubnets := []*net.IPNet{}
if trustedSubnetStr == "" {
return trustedSubnets, nil
}
for _, subnetStr := range strings.Split(trustedSubnetStr, ",") {
_, subnet, err := net.ParseCIDR(subnetStr)
if err != nil {
return nil, err
}
trustedSubnets = append(trustedSubnets, subnet)
}
return trustedSubnets, nil
}
func listenAndServeHTTP(httpAddr string, muxRouter *mux.Router) { func listenAndServeHTTP(httpAddr string, muxRouter *mux.Router) {
protocol := "tcp" protocol := "tcp"
if strings.HasPrefix(httpAddr, "/") { if strings.HasPrefix(httpAddr, "/") {
+2 -3
View File
@@ -515,9 +515,8 @@ type fastDatapathForwarder struct {
func (fastdp fastDatapathOverlay) PrepareConnection(params mesh.OverlayConnectionParams) (mesh.OverlayConnection, error) { func (fastdp fastDatapathOverlay) PrepareConnection(params mesh.OverlayConnectionParams) (mesh.OverlayConnection, error) {
if params.SessionKey != nil { if params.SessionKey != nil {
// No encryption suport in fastdp. The weaver main.go // No encryption support in fastdp
// is responsible for ensuring this doesn't happen. return nil, fmt.Errorf("encryption not supported")
log.Fatal("Attempt to use FastDatapath with encryption")
} }
vxlanVportID := fastdp.mainVxlanVportID vxlanVportID := fastdp.mainVxlanVportID
+10 -2
View File
@@ -204,8 +204,16 @@ func (osw *OverlaySwitch) PrepareConnection(params mesh.OverlayConnectionParams)
subConn, err := overlay.PrepareConnection(params) subConn, err := overlay.PrepareConnection(params)
if err != nil { if err != nil {
fwd.stopFrom(0) log.Infof("Unable to use %s for connection to %s(%s): %s",
return nil, err overlay.name,
params.RemotePeer.Name,
params.RemotePeer.NickName,
err)
// failed to start subforwarder - record overlay name and continue
fwd.forwarders[i] = subForwarder{
overlayName: overlay.name,
}
continue
} }
subFwd := subConn.(OverlayForwarder) subFwd := subConn.(OverlayForwarder)
+2 -1
View File
@@ -42,7 +42,8 @@ weave setup
weave version weave version
weave launch [--password <password>] [--nickname <nickname>] weave launch [--password <password>] [--nickname <nickname>]
[--ipalloc-range <cidr> [--ipalloc-default-subnet <cidr>]] [--ipalloc-range <cidr> [--ipalloc-default-subnet <cidr>]]
[--no-discovery] [--init-peer-count <count>] <peer> ... [--no-discovery] [--init-peer-count <count>]
[--trusted-subnets <cidr>,...] <peer> ...
weave launch-router [--password <password>] [--nickname <nickname>] weave launch-router [--password <password>] [--nickname <nickname>]
[--ipalloc-range <cidr> [--ipalloc-default-subnet <cidr>]] [--ipalloc-range <cidr> [--ipalloc-default-subnet <cidr>]]
[--no-discovery] [--init-peer-count <count>] <peer> ... [--no-discovery] [--init-peer-count <count>] <peer> ...