docker手册 ( http://docs.docker.com/installation/ubuntulinux/#docker-and-ufw ) 指出有必要将 UFWs DEFAULT_FORWARD_POLICY 设置为“ACCEPT”,以便 docker 容器可以相互访问。
在具有可公开访问的网络接口的服务器上这样做有什么安全意义?
应该怎么做才能保护这样的 docker 主机?
他们似乎已经解决了这部分问题,至少在最新的 1.4.1 版本中。我的 FORWARD 策略是丢弃数据包,并且容器间通信没有问题。
这些是 docker 创建的 FORWARD 链中的标准规则:
$ iptables -vnL FORWARD
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
6902 96M ACCEPT all -- * docker0 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
6151 482K ACCEPT all -- docker0 !docker0 0.0.0.0/0 0.0.0.0/0
3 180 ACCEPT all -- docker0 docker0 0.0.0.0/0 0.0.0.0/0
Run Code Online (Sandbox Code Playgroud)
自下而上:
这里没有问题。(除非你想要传出过滤器)
您可以愉快地将 FORWARD + INPUT 策略设置为 DROP/REJECT。
现在,您可能希望在 Internet 上提供服务。例如一个简单的网络服务器:
$ docker run -d -p 80:80 dockerfile/nginx
Run Code Online (Sandbox Code Playgroud)
好的,现在去 yourserver.com。您将看到默认的 nginx 页面。为什么?Docker 在 iptables 中为您添加了一些特殊规则。
$ iptables -vn -t nat -L # NAT table, truncated for clarity
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
189 11900 DOCKER all -- * * 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL
Chain DOCKER (2 references)
pkts bytes target prot opt in out source destination
0 0 DNAT tcp -- !docker0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:172.17.0.15:80
$ iptables -vnL FORWARD
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- !docker0 docker0 0.0.0.0/0 172.17.0.15 tcp dpt:80
6903 96M ACCEPT all -- * docker0 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
6159 483K ACCEPT all -- docker0 !docker0 0.0.0.0/0 0.0.0.0/0
3 180 ACCEPT all -- docker0 docker0 0.0.0.0/0 0.0.0.0/0
Run Code Online (Sandbox Code Playgroud)
如果有容器监听,这些规则会绕过所有 ufw 规则。ufw 在 nat 表中什么都不做,Docker 在 FORWARD 链中的第一个位置设置它的规则。因此,您不可能阻止 IP 地址或进行任何类型的速率限制。
可能的解决方案:
--iptables=false并手动完成所有操作。煞费苦心的解决方案,因为每次重新启动容器时,它都会获得一个新 IP(目前,他们计划更改它)。-p 127.0.0.1:30080:80并创建您自己的 iptables 规则以到达那里。service docker start. 虽然有点hacky它的工作原理......| 归档时间: |
|
| 查看次数: |
3810 次 |
| 最近记录: |