-
Notifications
You must be signed in to change notification settings - Fork 883
[WIP] Add DOCKER-USER chain when iptables=true is set ENGCORE-1114 #2464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ const ( | |
| vethLen = 7 | ||
| defaultContainerVethPrefix = "eth" | ||
| maxAllocatePortAttempts = 10 | ||
| userChain = "DOCKER-USER" | ||
| ingressChain = "DOCKER-INGRESS" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -357,6 +359,16 @@ 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-INGRESS chain | ||
| arrangeIngressFilterRule() | ||
| // Add DOCKER-USER chain | ||
| arrangeUserFilterRule() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now arrangeUserFIlterRule is called on all systems, linux/windows/bsd etc, is this by intention?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose for any *nix, we expect to create bridge. I see somewhere there are _bsd specific imple. So I am guessing at some point before at least bsd is supported? |
||
| iptables.OnReloaded(func() { | ||
| logrus.Debugf("Recreating DOCKER-INGRESS and DOCKER-USER iptables chain on firewall reload") | ||
| arrangeIngressFilterRule() | ||
| arrangeUserFilterRule() | ||
| }) | ||
| } | ||
|
|
||
| if config.EnableIPForwarding { | ||
|
|
@@ -1504,3 +1516,42 @@ 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) | ||
| } | ||
| } | ||
|
|
||
| // In the filter table FORWARD chain the first rule should be to jump to | ||
| // DOCKER-USER so the user is able to filter packet first. | ||
| // The second rule should be jump to INGRESS-CHAIN. | ||
| // This chain has the rules to allow access to the published ports for swarm tasks | ||
| // from local bridge networks and docker_gwbridge (ie:taks on other swarm networks) | ||
| func arrangeIngressFilterRule() { | ||
| if iptables.ExistChain(ingressChain, iptables.Filter) { | ||
| if iptables.Exists(iptables.Filter, "FORWARD", "-j", ingressChain) { | ||
| if err := iptables.RawCombinedOutput("-D", "FORWARD", "-j", ingressChain); err != nil { | ||
| logrus.Warnf("failed to delete jump rule to ingressChain in filter table: %v", err) | ||
| } | ||
| } | ||
| if err := iptables.RawCombinedOutput("-I", "FORWARD", "-j", ingressChain); err != nil { | ||
| logrus.Warnf("failed to add jump rule to ingressChain in filter table: %v", err) | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have similar questions as Elango, why move to bridge.go, may be the real problem is that controller.hasIPTableEnabled() isn't the correct value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by moving arrangeUserFilterRule to bridge only network, it means unless a bridge network is created, there won't be DOCKER_USER chain. It will work as dockerd always creates docker9 bridge, but for me the original approach is cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK from https://github.com/moby/moby/blob/ad1b781e44fa1e44b9e654e5078929aec56aed66/daemon/config/config_unix.go#L50 and 9c6ab12
EnableIPTablesis specific tobridge