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

Commit

Permalink
Merge pull request #3811 from weaveworks/allow-dnat-127
Browse files Browse the repository at this point in the history
Only drop traffic to the Weave Net port on 127.0.0.1
  • Loading branch information
bboreham authored May 30, 2020
2 parents 95c020f + a46d18d commit bef50d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions net/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ type BridgeConfig struct {
MTU int
Mac string
Port int
ControlPort string
NoMasqLocal bool
}

Expand Down Expand Up @@ -469,10 +470,17 @@ func configureIPTables(config *BridgeConfig, ips ipset.Interface) error {
}
}

// Block non-local traffic to the Weave control port
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 {
return err
if config.ControlPort != "" {
if err = ipt.AppendUnique("filter", "INPUT", "-p", "tcp", "--dst", "127.0.0.1", "--dport", config.ControlPort,
"-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 {
// Steer traffic via the NPC.
Expand Down
5 changes: 5 additions & 0 deletions prog/weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ func main() {

bridgeConfig.Mac = name.String()
bridgeConfig.Port = config.Port
if httpAddr != "" {
if _, port, err := net.SplitHostPort(httpAddr); err == nil {
bridgeConfig.ControlPort = port
}
}
ips := ipset.New(common.LogLogger(), 0)
bridgeType, err := weavenet.EnsureBridge(procPath, &bridgeConfig, Log, ips)
checkFatal(err)
Expand Down
2 changes: 1 addition & 1 deletion weave
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ destroy_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 tcp --dport 53 -j ACCEPT >/dev/null 2>&1 || true

Expand Down

0 comments on commit bef50d3

Please sign in to comment.