Skip to content
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

Wider-world-to-container doesn't apply to traffic coming from within a container #277

Open
pitkley opened this issue Jun 13, 2020 · 5 comments · Fixed by #278
Open

Wider-world-to-container doesn't apply to traffic coming from within a container #277

pitkley opened this issue Jun 13, 2020 · 5 comments · Fixed by #278

Comments

@pitkley
Copy link
Owner

pitkley commented Jun 13, 2020

Scenario:

  1. Create a container providing some service under a non-published port, e.g. with the following docker-compose.yml:

    version: '2'
    
    services:
        whoami:
            image: containous/whoami:latest
            command: "--port 8081"

    Start the service using docker-compose --project-name whoami up -d.

  2. Add the following to your WWTC-configuration:

    [[wider_world_to_container.rules]]
    network = "whoami_default"
    dst_container = "whoami_whoami_1"
    expose_port = "8081/tcp"
  3. Signal DFW to reapply the rules (e.g. by restarting it).

  4. Try to cURL the above container from within another container on the same host:

    # docker container run --rm curlimages/curl -v http://<your host or IP>:8081
    Status: Downloaded newer image for curlimages/curl:latest
    *   Trying <IP>:8081...
    * connect to <IP> port 8081 failed: Connection refused
    * Failed to connect to <your host or IP> port 8081: Connection refused
    * Closing connection 0
    curl: (7) Failed to connect to <your host or IP> port 8081: Connection refused

Since the container is exposed to the wider-world, I'd expect the container to also be reachable from other containers.

(Thanks to @cybermcm for reporting this.)

@pitkley pitkley added the bug label Jun 13, 2020
@pitkley pitkley added this to the 1.2.0 milestone Jun 13, 2020
@pitkley pitkley self-assigned this Jun 13, 2020
bors bot added a commit that referenced this issue Jun 14, 2020
278: Change behaviour of `external_network_interfaces` r=pitkley a=pitkley

Previously if you defined the `global_defaults.external_network_interfaces` configuration key, the first interface provided would internally be used to restrict which interfaces traffic can ingress into your containers from, even if `wider_world_to_container.rules[].external_network_interfaces` was not defined.

This version changes the behaviour such that `global_defaults.external_network_interfaces` is no longer used to determine if traffic can ingress or not. If you want to restrict traffic
from reaching your containers to specific interfaces, use the `wider_world_to_container.rules[].external_network_interfaces` configuration key instead.

Closes #277.


Co-authored-by: Pit Kleyersburg <[email protected]>
bors bot added a commit that referenced this issue Jun 14, 2020
278: Change behaviour of `external_network_interfaces` r=pitkley a=pitkley

Previously if you defined the `global_defaults.external_network_interfaces` configuration key, the first interface provided would internally be used to restrict which interfaces traffic can ingress into your containers from, even if `wider_world_to_container.rules[].external_network_interfaces` was not defined.

This version changes the behaviour such that `global_defaults.external_network_interfaces` is no longer used to determine if traffic can ingress or not. If you want to restrict traffic
from reaching your containers to specific interfaces, use the `wider_world_to_container.rules[].external_network_interfaces` configuration key instead.

Closes #277.


Co-authored-by: Pit Kleyersburg <[email protected]>
@bors bors bot closed this as completed in 6002a6c Jun 14, 2020
@pitkley
Copy link
Owner Author

pitkley commented Jun 14, 2020

@cybermcm I just released 1.2.0-rc.5 (which you'll be able to retrieve via Docker Hub under pitkley/dfw:1.2.0-rc.5 once it is done building). Maybe you can retest your use-case? 🙂

If your issue isn't fixed, please feel free to reopen this ticket!

@cybermcm
Copy link

@pitkley Thanks for this version but it breaks Docker internal DNS (at least for me)
Tested 1.2.0-rc.4 -> within container nslookup google.com -> working
1.2.0-rc.5 -> within container nslookup google.com -> no result (refused)
I'm currently reverting back to rc.4

@pitkley
Copy link
Owner Author

pitkley commented Jun 14, 2020

@cybermcm hm, while I can't directly confirm the DNS-issue, I can see that outgoing traffic overall seems to be a bit wonky. Sorry that I didn't catch that.

I'll reopen this issue and look at it again. 👍 Thanks so much for all your testing efforts!

@pitkley pitkley reopened this Jun 14, 2020
@pitkley pitkley modified the milestones: 1.2.0, 1.3.0 Jun 15, 2020
@pitkley
Copy link
Owner Author

pitkley commented Jun 15, 2020

@cybermcm just for your information: I have reverted the change and created rc.6 (which is effectively identical to rc.4). For the time being the required workaround is to publish the port.

(I'm planning to release v1.2.0 proper some time this week, potentially today.)

I have postponed this issue into v1.3.0 and I'm looking into how this could be handled.


Some background, both for myself and in case anyone is interested: DFW decides how/when to route traffic based on the port requested and on the interface the traffic is arriving from. If the interface is not specified (which is what rc.5 did), this also affected traffic that would have eventually leave the box, because the prerouting stage (which is what DFW needs to use) does not yet know if the packet it is looking at is inbound or outbound relative to the machine.

This circumstance makes it tough to decide if a packet for a specific port is targeting "us" or the outside world. My current idea is to allow the user to specify (or auto-determine) the IP-addresses traffic can ingress on and filtering on that, but I'm still exploring if there is maybe some metadata on a packet that can filtered on.

@pitkley
Copy link
Owner Author

pitkley commented Jun 18, 2020

Note: iptables can match -m addrtype --dst-type local where local identifies "destinations [...] assigned to this host". nftables seems to have fib (with kernel >=4.10), which supposedly does the same thing.

This could be the type of match we need.

@pitkley pitkley mentioned this issue Feb 6, 2022
3 tasks
@pitkley pitkley removed this from the 1.3.0 milestone Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants