Open richard-delorenzi opened 6 years ago
Is there any rational reason why swarm prevents you from picking the IP address on the node that you'd like to bind to? What if you want to deploy multiple applications on a single node, each with it's own IP address? It seems like a completely reasonable use case.
If you want to pick the node ip, you must use host mode routing which is an option in the port binding.
@cpuguy83 I just read about host mode https://docs.docker.com/network/host/ it does not seem to have anything that would help with @bradmunz79 's case. Even if the software in the container, can choose to bind to only one address (not mentioned in this intro), then it relies no the containerised software to do the correct thing. However this is the containers job. We should be able to tell a container to map an internal port to an external host port e.g. 127.0.1.1
Are we at least warning the user, if we try to do this? “Secure by default”, tells us that we should error, and refuse to start.
No, it does not rely on the application to do the right thing, it's a config in the swarm service spec.
Why would a swarm service bind to localhost? Why not just run a normal container at that point?
The default is "no ports are published", which I don't think violates "secure by default". For services that are not meant to be accessible from outside the host, you can "not" publish ports, and connect them to an internal network for other services or containers to connect to them.
Being able to connect to a specific interface is still an open feature-request (https://github.com/moby/moby/issues/24317), but non-trivial (and related: ip-addresses for services https://github.com/moby/moby/issues/24170).
(MacVlan networking may be an option for some use-cases https://docs.docker.com/network/macvlan/, http://killcity.io/2017/08/12/setup-docker-swarm-with-macvlan-plus-consul-and-autoscaling.html)
As to
Errors should be issued if IP-Address specified, and docs updated. Error should be issued if mode not specified (no default), and docs updated.
A warning was added when deploying through a stack (https://github.com/docker/cli/pull/1017), and an error will be produced when attempting to bind to an IP-address;
docker service create --publish 127.0.0.1:8080:80 nginx:alpine
invalid argument "127.0.0.1:8080:80" for "-p, --publish" flag: hostip is not supported
Both ports mode = ingress, and binding to 0.0.0.0, and not giving an error when an IP address is specified but ignored, are in violation of “secure by default”.
There are 3 related issues:
Using ingress mode by default, is causing all nodes to listen when only one may be expected. Is an inconvenience, and violates security by default.
Ignoring bind address, and not issuing an error, then binding to 0.0.0.0. Is Is an inconvenience, and violates security by default.
Not supporting bind addresses, is an inconvenience.
The inconveniences, are making it impossible for me to use swarms. The security problems lead me to expose my data, but I now know how to avoid. However I should not need to think about this, and it could affect other people. (security should be by default).
Usecases
/etc/hosts
, so that each domain-name is sent to a different container. This works withdocker run
, but not with compose.So in summary
Allow bind to local address is useful for constrained nodes. Allow bind to particular address, would work for constrained node, or routed through the swarm to one of the addresses on one of the nodes (may be ingress mode only). This routing is done already
Steps to reproduce the issue:
Describe the results you received: The exposed port was on all nodes (public and private), and on all interfaces (public and private). Data was exposed.
Describe the results you expected: Port published on one node, on IP 127.0.0.3
Additional information you deem important (e.g. issue happens only occasionally):
Output of
docker version
:Output of
docker info
:Additional environment details (AWS, VirtualBox, physical, etc.):
Physical
Debian Gnu/Linux 8.10
Linux xxxxxxxxx 3.16.0-5-amd64 #1 SMP Debian 3.16.51-3+deb8u1 (2018-01-08) x86_64 GNU/Linux