【发布时间】:2020-02-15 19:08:00
【问题描述】:
我已经在容器中启用了特权模式,并为其添加了规则,
iptables -N udp2rawDwrW_191630ce_C0
iptables -F udp2rawDwrW_191630ce_C0
iptables -I udp2rawDwrW_191630ce_C0 -j DROP
iptables -I INPUT -p tcp -m tcp --dport 4096 -j udp2rawDwrW_191630ce_C0
和kt exec进入容器并使用iptables --table filter -L,我可以看到添加的规则。
/ # iptables --table filter -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
udp2rawDwrW_191630ce_C0 tcp -- anywhere anywhere tcp dpt:4096
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain udp2rawDwrW_191630ce_C0 (1 references)
target prot opt source destination
DROP all -- anywhere anywhere
当我登录到容器所在的节点并运行sudo iptalbes --table filter -L 时,我看不到相同的结果。
我认为默认情况下会删除 previleged,因为容器可能会利用它来更改节点中的 iptables 之类的东西,但它看起来不像那样。
所以我的问题是“K8S iptables 与 pod 内的容器之间的关系是什么”以及“为什么我们阻止用户在没有 privileged 字段的情况下修改容器的 iptables”?
【问题讨论】:
-
嗨,我认为这是因为对节点
iptables所做的修改在其动态修改中丢失了。看看kubernetes documentation中的这部分。 -
请解释“在容器中启用特权模式”:您使用了什么命令/yaml?也是普通的 docker 容器还是 k8s pod?
-
@morgwai,这里记录了特权模式:kubernetes.io/docs/concepts/policy/pod-security-policy。它是 k8s pod 中的容器。
-
@PiotrMales,我认为 Node 的 iptables 实际上并没有被容器修改。查了节点的iptables规则,感觉有很多规则和流量相关,但没有体现在容器中。
标签: docker kubernetes iptables