Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit bef50d3

Browse files
authored
Merge pull request #3811 from weaveworks/allow-dnat-127
Only drop traffic to the Weave Net port on 127.0.0.1
2 parents 95c020f + a46d18d commit bef50d3

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

net/bridge.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ type BridgeConfig struct {
221221
MTU int
222222
Mac string
223223
Port int
224+
ControlPort string
224225
NoMasqLocal bool
225226
}
226227

@@ -469,10 +470,17 @@ func configureIPTables(config *BridgeConfig, ips ipset.Interface) error {
469470
}
470471
}
471472

472-
// Block non-local traffic to the Weave control port
473-
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 {
474-
return err
473+
if config.ControlPort != "" {
474+
if err = ipt.AppendUnique("filter", "INPUT", "-p", "tcp", "--dst", "127.0.0.1", "--dport", config.ControlPort,
475+
"-m", "addrtype", "!", "--src-type", "LOCAL",
476+
"-m", "conntrack", "!", "--ctstate", "RELATED,ESTABLISHED",
477+
"-m", "comment", "--comment", "Block non-local access to Weave Net control port",
478+
"-j", "DROP"); err != nil {
479+
return err
480+
}
475481
}
482+
// Remove the rule from Weave Net 2.6.3 which dropped too much.
483+
_ = ipt.Delete("filter", "INPUT", "-p", "tcp", "--dst", "127.0.0.1", "-m", "addrtype", "!", "--src-type", "LOCAL", "-m", "conntrack", "!", "--ctstate", "RELATED,ESTABLISHED", "-j", "DROP")
476484

477485
if config.NPC {
478486
// Steer traffic via the NPC.

prog/weaver/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ func main() {
307307

308308
bridgeConfig.Mac = name.String()
309309
bridgeConfig.Port = config.Port
310+
if httpAddr != "" {
311+
if _, port, err := net.SplitHostPort(httpAddr); err == nil {
312+
bridgeConfig.ControlPort = port
313+
}
314+
}
310315
ips := ipset.New(common.LogLogger(), 0)
311316
bridgeType, err := weavenet.EnsureBridge(procPath, &bridgeConfig, Log, ips)
312317
checkFatal(err)

weave

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ destroy_bridge() {
483483

484484
[ -n "$DOCKER_BRIDGE_IP" ] || DOCKER_BRIDGE_IP=$(util_op bridge-ip $DOCKER_BRIDGE)
485485

486-
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
486+
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
487487
run_iptables -t filter -D INPUT -i $DOCKER_BRIDGE -p udp --dport 53 -j ACCEPT >/dev/null 2>&1 || true
488488
run_iptables -t filter -D INPUT -i $DOCKER_BRIDGE -p tcp --dport 53 -j ACCEPT >/dev/null 2>&1 || true
489489

0 commit comments

Comments
 (0)