Skip to content

Commit

Permalink
Add DOCKER-USER chain when iptables=true is set
Browse files Browse the repository at this point in the history
This PR fixes the regression introduced by
moby#2339 to
correctly insert the DOCKER-USER chain if iptables=true
is set in the Daemon config

Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
  • Loading branch information
Arko Dasgupta committed Oct 9, 2019
1 parent 3e10ae9 commit 38ceb4e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 79 deletions.
2 changes: 0 additions & 2 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,6 @@ addToStore:
c.Unlock()
}

c.arrangeUserFilterRule()

return network, nil
}

Expand Down
29 changes: 29 additions & 0 deletions drivers/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
vethLen = 7
defaultContainerVethPrefix = "eth"
maxAllocatePortAttempts = 10
userChain = "DOCKER-USER"
)

const (
Expand Down Expand Up @@ -357,6 +358,13 @@ func (d *driver) configure(option map[string]interface{}) error {
}
// Make sure on firewall reload, first thing being re-played is chains creation
iptables.OnReloaded(func() { logrus.Debugf("Recreating iptables chains on firewall reload"); setupIPChains(config) })

// Add DOCKER-USER chain
arrangeUserFilterRule()
iptables.OnReloaded(func() {
logrus.Debugf("Recreating DOCKER-USER iptables chain on firewall reload")
arrangeUserFilterRule()
})
}

if config.EnableIPForwarding {
Expand Down Expand Up @@ -1504,3 +1512,24 @@ func electMacAddress(epConfig *endpointConfiguration, ip net.IP) net.HardwareAdd
}
return netutils.GenerateMACFromIP(ip)
}

// This chain allow users to configure firewall policies in a way that persists
// docker operations/restarts. Docker will not delete or modify any pre-existing
// rules from the DOCKER-USER filter chain.
func arrangeUserFilterRule() {
_, err := iptables.NewChain(userChain, iptables.Filter, false)
if err != nil {
logrus.Warnf("Failed to create %s chain: %v", userChain, err)
return
}

if err = iptables.AddReturnRule(userChain); err != nil {
logrus.Warnf("Failed to add the RETURN rule for %s: %v", userChain, err)
return
}

err = iptables.EnsureJumpRule("FORWARD", userChain)
if err != nil {
logrus.Warnf("Failed to ensure the jump rule for %s: %v", userChain, err)
}
}
70 changes: 0 additions & 70 deletions firewall_linux.go

This file was deleted.

6 changes: 0 additions & 6 deletions firewall_others.go

This file was deleted.

1 change: 0 additions & 1 deletion service_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ func programIngress(gwIP net.IP, ingressPorts []*PortConfig, isDelete bool) erro
if err := iptables.RawCombinedOutput("-I", "FORWARD", "-j", ingressChain); err != nil {
return fmt.Errorf("failed to add jump rule to %s in filter table forward chain: %v", ingressChain, err)
}
arrangeUserFilterRule()
}

oifName, err := findOIFName(gwIP)
Expand Down

0 comments on commit 38ceb4e

Please sign in to comment.