gpt4 book ai didi

docker - 使用 docker 和 ansible iptables 拒绝传入流量

转载 作者:行者123 更新时间:2023-12-02 18:13:14 25 4
gpt4 key购买 nike

在独立服务器中,我有一个运行 jenkins 的 docker 容器。我想编写一个剧本,允许我(一些公共(public) ip,假设它是 107.33.11.111)通过 22 和 8080 连接到我的独立服务器上的 jenkins 服务器,但没有其他人。公共(public)流量来自我的独立服务器上的 eth0。我正在使用 this guide尝试使这项工作。

这是我如何运行 jenkins 的示例:

# privileged is needed to allow browser based testing via chrome
- name: Run jenkins container
command: docker run --privileged -d -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk11

然后我设置了这个防火墙规则:
- name: Firewall rule - allow port 22/SSH traffic only for me
iptables:
chain: INPUT
in_interface: eth0
destination_port: 22
jump: ACCEPT
protocol: tcp
source: 107.33.11.111

- name: Firewall rule - allow port 8080 traffic only for me
iptables:
chain: INPUT
in_interface: eth0
destination_port: 8080
jump: ACCEPT
protocol: tcp
source: 107.33.11.111

- name: Firewall rule - drop any traffic without rule
iptables:
chain: INPUT
jump: DROP
in_interface: eth0

当我执行上述剧本并运行 iptables -L ,我的输出只修剪为:
Chain INPUT (policy ACCEPT)
target prot opt source destination

当我删除最后一条规则以丢弃所有流量时,我可以观察到整个输出,并且 ip 表显示我的 ip 被允许用于端口 22 和 8080。但是,进入 eth0 的所有其他流量也能够到达这些端口。

我需要做什么才能在我的 ansible playbook 中仅允许特定公共(public)地址使用 22 和 8080?

最佳答案

对于您的特定用例,您不需要跳转到另一个链,但您可以将默认策略设置为 DROP在允许 8080 和 22 之后。

将剧本中的最后一节替换为

- name: Firewall rule - drop any traffic without rule
iptables:
chain: INPUT
policy: DROP

关于docker - 使用 docker 和 ansible iptables 拒绝传入流量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61484170/

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