gpt4 book ai didi

即使 UFW 拒绝访问,Docker 端口也会在界面上可见

转载 作者:行者123 更新时间:2023-12-02 19:28:45 27 4
gpt4 key购买 nike

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

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

防火墙配置为阻止 eth0(DO 公共(public)接口(interface))上的所有流量,docker 的 2376 除外,并在 eth1(DO 私有(private)接口(interface))上打开端口 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.

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

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

有没有人遇到过这种行为?我真的很想了解正在发生的事情。

最佳答案

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

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

另见 this answer to similar question on ServerFault ,来自与 one of successful advices on #22054 issue 相同的人.

关于即使 UFW 拒绝访问,Docker 端口也会在界面上可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53702109/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com