|
@@ -1,4 +1,4 @@
|
|
-// Copyright 2015 flannel authors
|
|
|
|
|
|
+// Copyright 2017 flannel authors
|
|
//
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// you may not use this file except in compliance with the License.
|
|
@@ -11,23 +11,39 @@
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
// limitations under the License.
|
|
|
|
+// +build !windows
|
|
|
|
|
|
package ipsec
|
|
package ipsec
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "sync"
|
|
|
|
+
|
|
log "github.com/golang/glog"
|
|
log "github.com/golang/glog"
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/context"
|
|
- "sync"
|
|
|
|
|
|
|
|
"github.com/coreos/flannel/backend"
|
|
"github.com/coreos/flannel/backend"
|
|
"github.com/coreos/flannel/pkg/ip"
|
|
"github.com/coreos/flannel/pkg/ip"
|
|
"github.com/coreos/flannel/subnet"
|
|
"github.com/coreos/flannel/subnet"
|
|
)
|
|
)
|
|
|
|
|
|
-var CharonExecutablePath string
|
|
|
|
-var CharonViciUri string
|
|
|
|
|
|
+/*
|
|
|
|
+ Flannel's approach to IPSec uses Strongswan to handle the key exchange (using IKEv2) and the kernel to handle the
|
|
|
|
+ actual encryption.
|
|
|
|
+
|
|
|
|
+ Strongswan's "charon" is bundled in the flannel container. Flannel runs it as a child process when the ipsec backend
|
|
|
|
+ is selected and communicates with it using the "VICI" interface. Strongswan ships a utility "swanctl" which also
|
|
|
|
+ uses the VICI interface. This utility is bundled in the flannel container and can help with debugging.
|
|
|
|
+
|
|
|
|
+ The file "handle_charon.go" contains the logic for working with the charon. It supports creating a "CharonIKEDaemon"
|
|
|
|
+ which supports loading the PSK into the charon and adding and removing connections.
|
|
|
|
+
|
|
|
|
+ The file "handle_xfrm.go" contains functions for adding and removing the ipsec polcies.
|
|
|
|
+
|
|
|
|
+ ipsec_network.go ties it all together, loading the PSK for current host on startu and as new hosts are added and
|
|
|
|
+ removed it, adds/removes the PSK and connection details to strongswan and adds/remove the policy to the kernel.
|
|
|
|
+*/
|
|
|
|
|
|
const (
|
|
const (
|
|
defaultESPProposal = "aes128gcm16-sha256-prfsha256-ecp256"
|
|
defaultESPProposal = "aes128gcm16-sha256-prfsha256-ecp256"
|
|
@@ -66,7 +82,6 @@ func (be *IPSECBackend) RegisterNetwork(
|
|
}
|
|
}
|
|
|
|
|
|
if len(config.Backend) > 0 {
|
|
if len(config.Backend) > 0 {
|
|
- log.Info("i.config.backend length > 0")
|
|
|
|
if err := json.Unmarshal(config.Backend, &cfg); err != nil {
|
|
if err := json.Unmarshal(config.Backend, &cfg); err != nil {
|
|
return nil, fmt.Errorf("error decoding IPSEC backend config: %v", err)
|
|
return nil, fmt.Errorf("error decoding IPSEC backend config: %v", err)
|
|
}
|
|
}
|
|
@@ -74,10 +89,12 @@ func (be *IPSECBackend) RegisterNetwork(
|
|
|
|
|
|
if len(cfg.PSK) < minPasswordLength {
|
|
if len(cfg.PSK) < minPasswordLength {
|
|
return nil, fmt.Errorf(
|
|
return nil, fmt.Errorf(
|
|
- "config error, password should be at least %s characters long",
|
|
|
|
|
|
+ "config error, password should be at least %d characters long",
|
|
minPasswordLength)
|
|
minPasswordLength)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ log.Infof("IPSec config: UDPEncap=%v ESPProposal=%s", cfg.UDPEncap, cfg.ESPProposal)
|
|
|
|
+
|
|
attrs := subnet.LeaseAttrs{
|
|
attrs := subnet.LeaseAttrs{
|
|
PublicIP: ip.FromIP(be.extIface.ExtAddr),
|
|
PublicIP: ip.FromIP(be.extIface.ExtAddr),
|
|
BackendType: "ipsec",
|
|
BackendType: "ipsec",
|
|
@@ -95,17 +112,10 @@ func (be *IPSECBackend) RegisterNetwork(
|
|
return nil, fmt.Errorf("failed to acquire lease: %v", err)
|
|
return nil, fmt.Errorf("failed to acquire lease: %v", err)
|
|
}
|
|
}
|
|
|
|
|
|
- ikeDaemon, err := NewCharonIKEDaemon(ctx, wg, CharonExecutablePath, CharonViciUri,
|
|
|
|
- cfg.ESPProposal)
|
|
|
|
|
|
+ ikeDaemon, err := NewCharonIKEDaemon(ctx, wg, cfg.ESPProposal)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating CharonIKEDaemon struct: %v", err)
|
|
return nil, fmt.Errorf("error creating CharonIKEDaemon struct: %v", err)
|
|
}
|
|
}
|
|
|
|
|
|
- log.Info("UDPEncap: ", cfg.UDPEncap)
|
|
|
|
-
|
|
|
|
return newNetwork(be.sm, be.extIface, cfg.UDPEncap, cfg.PSK, ikeDaemon, l)
|
|
return newNetwork(be.sm, be.extIface, cfg.UDPEncap, cfg.PSK, ikeDaemon, l)
|
|
}
|
|
}
|
|
-
|
|
|
|
-func (be *IPSECBackend) Run(ctx context.Context) {
|
|
|
|
- <-ctx.Done()
|
|
|
|
-}
|
|
|