【问题标题】:Docker ports visible on interface even if UFW has denied access即使 UFW 拒绝访问,Docker 端口也会在界面上可见
【发布时间】:2018-12-10 08:45:28
【问题描述】:

我有一个使用 docker-machine 和 ubuntu-18-04-x64 映像创建的数字海洋水滴。我使用 docker-compose 为它部署了三个容器,其中一个是 nginx,它的端口 80 和 8080 转发到 0.0.0.0,从而监听所有接口。

  nginx:
image: noumena/nrg-vpp/nginx:latest
ports:
- "80:80"
- "8080:8080"
depends_on:
- engine
- api

防火墙配置为阻止 eth0(DO 公共接口)上的所有流量,docker 的 2376 除外,并在 eth1(DO 专用接口)上打开端口 22、80、8080。

22/tcp on eth1             ALLOW       Anywhere
8080/tcp on eth1           ALLOW       Anywhere
80/tcp on eth1             ALLOW       Anywhere
2376/tcp on eth0           ALLOW       Anywhere
Anywhere on eth0           DENY        Anywhere
Anywhere on eth1           DENY        Anywhere
22/tcp (v6) on eth1        ALLOW       Anywhere (v6)
8080/tcp (v6) on eth1      ALLOW       Anywhere (v6)
80/tcp (v6) on eth1        ALLOW       Anywhere (v6)
2376/tcp (v6) on eth0      ALLOW       Anywhere (v6)
Anywhere (v6) on eth0      DENY        Anywhere (v6)
Anywhere (v6) on eth1      DENY        Anywhere (v6)

但是 docker 转发的端口(80,8080)在 eth0 上仍然可见,任何其他端口在 eth 0 上不可见(例如 22)

17:10 $ telnet public-ip 22 
Trying x.x.x.x... 
telnet: connect to address x.x.x.x: Operation timed out 
telnet: Unable to connect to remote host 

17:16 $ telnet public-ip 80 
Trying x.x.x.x... 
Connected to x.x.x.x. 
Escape character is '^]'. 
^] 
telnet> Connection closed. 

17:17 $ telnet public-ip 8080 
Trying x.x.x.x...  
Connected to x.x.x.x.
Escape character is '^]'. 
^] 
telnet> Connection closed.

为什么这些端口会开放?是否在涉及防火墙之前进行转发?

我通过将容器限制为仅侦听私有 IP 来解决严重问题,但这很烦人,因为它需要额外的逻辑来查询 droplet 的私有 IP 并且 docker-compose 文件成为模板.如果我可以依靠防火墙来关闭转发的端口,那就简单多了。

以前有人遇到过这种行为吗?我真的很想了解发生了什么。

【问题讨论】:

    标签: docker ubuntu docker-compose docker-machine ufw


    【解决方案1】:

    这是由于 Docker 处理网络的方式。简而言之,从容器中公开一个端口,您指示 Docker 在防火墙(至少对于 UFW)有机会应用自己的规则之前为特定端口设置 ACCEPT 规则。

    GitHub 上跟踪此行为的主要、最明智的问题似乎是 #22054。根据您的确切防火墙配置 (UFW?),其中一个 cmets(尤其是较新的一次,自 2017 年左右以来)可能会为您提供解决方案。

    另请参阅 this answer to similar question on ServerFault,它与 one of successful advices on #22054 issue 来自同一个人。

    【讨论】:

    猜你喜欢
    • 2021-07-30
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 2016-04-10
    • 1970-01-01
    相关资源
    最近更新 更多