Skip to content

Conversation

@sanimej
Copy link

@sanimej sanimej commented Oct 28, 2016

Related to docker #14041

If docker daemon enables ip_forwarding on a host set the policy in the FORWARD chain to DROP. This blocks the vulnerability explained in the above mentioned issue. Setting the policy is done from the bridge driver to keep it consistent with the current handling for ip_forward flag.

Signed-off-by: Santhosh Manohar santhosh@docker.com

return fmt.Errorf("Setup IP forwarding failed: %v", err)
}
if err := iptables.SetDefaultPolicy(iptables.Filter, "FORWARD", iptables.Drop); err != nil {
return fmt.Errorf("setting default policy failed: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetDefaultPolicy already returns a comprehensive error string. This one is not adding anything new to that.
I would just return err here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. I was also thinking about just returning the error here. will change it.

return fmt.Errorf("Setup IP forwarding failed: %v", err)
}
if err := iptables.SetDefaultPolicy(iptables.Filter, "FORWARD", iptables.Drop); err != nil {
return fmt.Errorf("setting default policy failed: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of failure to set the policy to drop, we must reset ip_forwarding to 0

@aboch
Copy link
Contributor

aboch commented Oct 28, 2016

We will now touch the iptables (changing the default policy) even if daemon was started with --iptables=false.
I guess it is fine, given we are addressing a vulnerability.
We'll need to document this behavior.

@sanimej
Copy link
Author

sanimej commented Nov 1, 2016

We will now touch the iptables (changing the default policy) even if daemon was started with --iptables=false. - On second thought I think its probably better to honor the iptabels=false config. Whoever sets it wants full control of the iptables and its their responsibility to also set the default policies correctly.

@sanimej
Copy link
Author

sanimej commented Nov 1, 2016

@aboch Addressed the comments. PTAL

return &ErrInvalidDriverConfig{}
}

if config.EnableIPForwarding {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the new logic is to change the FORWARD chain default policy only if config.EnableIPTables==true, I am thinking we do not need to move this code, neither make any change in SetupForwarding().
We only need to add in SetupIPChain(configuration)

if config.EnableIPForwarding {
    if err := iptables.SetDefaultPolicy(iptables.Filter, "FORWARD", iptables.Drop); err != nil {
        return fmt.Errorf("%v. IP forwarding was set to 1", err)
    }
}

Also this will guarantee the action will take place when the firewall is reloaded:
iptables.OnReloaded(..., setupIPChains)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.EnableIPForwarding is set based on the daemon flag and not by checking the sysctl ip_forward. By doing the way you are suggesting we will call SetDefaultPolicy even if ip_forward is already enabled; ie: ip_forward might be enabled and the default policy set be ACCEPT. Docker changing that to DROP is incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's right. Thanks.

@aboch
Copy link
Contributor

aboch commented Nov 2, 2016

After some more thinking of this and talk offline, I see the FORWARD chain policy will be set to DROP only if the ip forwarding is being enabled during this running instance.

If the daemon was already running and we upgrade it to the version containing this fix, or if the user has it enabled via other means, the policy will not be set to DROP.

I believe this is for assuring we do not disrupt current behavior on the host.

I would be more on the conservative side and always set the policy to DROP in SetupIPChain() if the ip_forward flag read from OS is 1. Reason is that given we cannot know for sure existing forward flag set to 1 is intentional, I think it is better to always change the policy.

But I understand this is opinable.

Signed-off-by: Santhosh Manohar <santhosh@docker.com>
@sanimej
Copy link
Author

sanimej commented Nov 4, 2016

@aboch When firewalld is enabled, if firewalld is restarted the default policy has to be set again. Added a function to OnReloaded to handle this.

@mavenugo
Copy link
Contributor

@sanimej after much discussion, I think this is a reasonable approach considering the backward compatibility. Lets document this clearly in docker/docker.

LGTM

@mavenugo mavenugo merged commit 1861587 into moby:master Nov 10, 2016
thaJeztah added a commit to thaJeztah/docker that referenced this pull request Sep 20, 2019
full diff: moby/libnetwork@92d1fbe...96bcc0d

changes included:

- moby/libnetwork#2429 Updating IPAM config with results from HNS create network call
  - addresses moby#38358
- moby/libnetwork#2450 Always configure iptables forward policy
  - related to moby#14041 and moby/libnetwork#1526

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Sep 23, 2019
full diff: moby/libnetwork@92d1fbe...96bcc0d

changes included:

- moby/libnetwork#2429 Updating IPAM config with results from HNS create network call
  - addresses moby/moby#38358
- moby/libnetwork#2450 Always configure iptables forward policy
  - related to moby/moby#14041 and moby/libnetwork#1526

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 75477f0b3c77f2108a6b5586dbc246c52b479941
Component: engine
thaJeztah added a commit to thaJeztah/docker that referenced this pull request Sep 24, 2019
full diff: moby/libnetwork@92d1fbe...96bcc0d

changes included:

- moby/libnetwork#2429 Updating IPAM config with results from HNS create network call
  - addresses moby#38358
- moby/libnetwork#2450 Always configure iptables forward policy
  - related to moby#14041 and moby/libnetwork#1526

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 75477f0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Sep 25, 2019
full diff: moby/libnetwork@92d1fbe...96bcc0d

changes included:

- moby/libnetwork#2429 Updating IPAM config with results from HNS create network call
  - addresses moby/moby#38358
- moby/libnetwork#2450 Always configure iptables forward policy
  - related to moby/moby#14041 and moby/libnetwork#1526

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 75477f0b3c77f2108a6b5586dbc246c52b479941)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 559be42fc26048f4069de64f84202803a113413a
Component: engine
burnMyDread pushed a commit to burnMyDread/moby that referenced this pull request Oct 21, 2019
full diff: moby/libnetwork@92d1fbe...96bcc0d

changes included:

- moby/libnetwork#2429 Updating IPAM config with results from HNS create network call
  - addresses moby#38358
- moby/libnetwork#2450 Always configure iptables forward policy
  - related to moby#14041 and moby/libnetwork#1526

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: zach <Zachary.Joyner@linux.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants