Use a more targeted iptables rule to block access to control port
Only block the specific port Weave Net is listening on. Add a comment so users know what the rule is for. Remove the rule added in v2.6.3 because it was too coarse.
This commit is contained in:
1 parent
95c020fbe0
commit
a46d18da0c
3 files changed
+17
-4
No files matched your search
+11
-3
@@ -221,6 +221,7 @@ type BridgeConfig struct {
|
|||||||
MTU int
|
MTU int
|
||||||
Mac string
|
Mac string
|
||||||
Port int
|
Port int
|
||||||
|
ControlPort string
|
||||||
NoMasqLocal bool
|
NoMasqLocal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,10 +470,17 @@ func configureIPTables(config *BridgeConfig, ips ipset.Interface) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block non-local traffic to the Weave control port
|
if config.ControlPort != "" {
|
||||||
if err = ipt.AppendUnique("filter", "INPUT", "-p", "tcp", "--dst", "127.0.0.1", "-m", "addrtype", "!", "--src-type", "LOCAL", "-m", "conntrack", "!", "--ctstate", "RELATED,ESTABLISHED", "-j", "DROP"); err != nil {
|
if err = ipt.AppendUnique("filter", "INPUT", "-p", "tcp", "--dst", "127.0.0.1", "--dport", config.ControlPort,
|
||||||
return err
|
"-m", "addrtype", "!", "--src-type", "LOCAL",
|
||||||
|
"-m", "conntrack", "!", "--ctstate", "RELATED,ESTABLISHED",
|
||||||
|
"-m", "comment", "--comment", "Block non-local access to Weave Net control port",
|
||||||
|
"-j", "DROP"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Remove the rule from Weave Net 2.6.3 which dropped too much.
|
||||||
|
_ = ipt.Delete("filter", "INPUT", "-p", "tcp", "--dst", "127.0.0.1", "-m", "addrtype", "!", "--src-type", "LOCAL", "-m", "conntrack", "!", "--ctstate", "RELATED,ESTABLISHED", "-j", "DROP")
|
||||||
|
|
||||||
if config.NPC {
|
if config.NPC {
|
||||||
// Steer traffic via the NPC.
|
// Steer traffic via the NPC.
|
||||||
|
|||||||
@@ -307,6 +307,11 @@ func main() {
|
|||||||
|
|
||||||
bridgeConfig.Mac = name.String()
|
bridgeConfig.Mac = name.String()
|
||||||
bridgeConfig.Port = config.Port
|
bridgeConfig.Port = config.Port
|
||||||
|
if httpAddr != "" {
|
||||||
|
if _, port, err := net.SplitHostPort(httpAddr); err == nil {
|
||||||
|
bridgeConfig.ControlPort = port
|
||||||
|
}
|
||||||
|
}
|
||||||
ips := ipset.New(common.LogLogger(), 0)
|
ips := ipset.New(common.LogLogger(), 0)
|
||||||
bridgeType, err := weavenet.EnsureBridge(procPath, &bridgeConfig, Log, ips)
|
bridgeType, err := weavenet.EnsureBridge(procPath, &bridgeConfig, Log, ips)
|
||||||
checkFatal(err)
|
checkFatal(err)
|
||||||
|
|||||||
@@ -483,7 +483,7 @@ destroy_bridge() {
|
|||||||
|
|
||||||
[ -n "$DOCKER_BRIDGE_IP" ] || DOCKER_BRIDGE_IP=$(util_op bridge-ip $DOCKER_BRIDGE)
|
[ -n "$DOCKER_BRIDGE_IP" ] || DOCKER_BRIDGE_IP=$(util_op bridge-ip $DOCKER_BRIDGE)
|
||||||
|
|
||||||
run_iptables -t filter -D INPUT -d 127.0.0.1/32 -p tcp -m addrtype ! --src-type LOCAL -m conntrack ! --ctstate RELATED,ESTABLISHED -j DROP >/dev/null 2>&1 || true
|
run_iptables -t filter -D INPUT -d 127.0.0.1/32 -p tcp --dport 6784 -m addrtype ! --src-type LOCAL -m conntrack ! --ctstate RELATED,ESTABLISHED -m comment --comment "Block non-local access to Weave Net control port" -j DROP >/dev/null 2>&1 || true
|
||||||
run_iptables -t filter -D INPUT -i $DOCKER_BRIDGE -p udp --dport 53 -j ACCEPT >/dev/null 2>&1 || true
|
run_iptables -t filter -D INPUT -i $DOCKER_BRIDGE -p udp --dport 53 -j ACCEPT >/dev/null 2>&1 || true
|
||||||
run_iptables -t filter -D INPUT -i $DOCKER_BRIDGE -p tcp --dport 53 -j ACCEPT >/dev/null 2>&1 || true
|
run_iptables -t filter -D INPUT -i $DOCKER_BRIDGE -p tcp --dport 53 -j ACCEPT >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user