简体   繁体   English

K8S iptables 与 pod 内的容器之间的关系

[英]relationship between K8S iptables and the one of a container inside a pod

I have enabled the privileged mode in the container and add a rule to it,我在容器中启用了特权模式并为其添加了规则,

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

and kt exec into the container and use iptables --table filter -L , I can see the added rules.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

While when I logged into the node where the container lives, and run sudo iptalbes --table filter -L , I cannot see the same result.当我登录到容器所在的节点并运行sudo iptalbes --table filter -L ,我看不到相同的结果。

I was thinking by default the previleged is dropped because the container might leverage it to change something like the iptables in the node, however it looks not like that.我在想默认情况下previleged被删除,因为容器可能会利用它来改变节点中的 iptables 之类的东西,但它看起来不是那样。

So my question is "what is the relationship between K8S iptables and the one of a container inside a pod" and "why we stop user from modifying the container's iptables without the privileged field"?所以我的问题是“K8S iptables 与 pod 内的容器之间的关系是什么”和“为什么我们阻止用户在没有privileged字段的情况下修改容器的 iptables”?

if you want to manipulate node's iptables then you definitely need to put the pod on host's network ( hostNetwork: true within pod's spec ).如果您想操作节点的 iptables,那么您肯定需要将 pod 放在主机的网络上( hostNetwork: true在 pod 的spec )。 After that granting to the container NET_ADMIN and NET_RAW capabilities (in containers[i].securityContext.capabilities.add ) is sufficient.之后授予容器NET_ADMINNET_RAW功能(在containers[i].securityContext.capabilities.add )就足够了。 example json slice:示例 json 切片:

  "spec": {
    "hostNetwork": true,
    "containers": [{
      "name": "netadmin",
      "securityContext": {"capabilities": { "add": ["NET_ADMIN", "NET_RAW"] } }

I'm not sure if privileged mode has anything to do with manipulating host's iptables these days.我不确定现在特权模式是否与操纵主机的 iptables 有任何关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM