@@ -196,19 +196,19 @@ func (npc *NetworkPolicyController) interceptPodInboundTraffic(pod *podInfo, pod
196196 // this rule applies to the traffic getting routed (coming for other node pods)
197197 comment := "\" rule to jump traffic destined to POD name:" + pod .name + " namespace: " + pod .namespace +
198198 " to chain " + podFwChainName + "\" "
199- args := []string {"-I " , kubeForwardChainName , "1" , "-m" , "comment" , "--comment" , comment , "-d" , pod .ip , "-j" , podFwChainName + "\n " }
199+ args := []string {"-A " , kubeForwardChainName , "-m" , "comment" , "--comment" , comment , "-d" , pod .ip , "-j" , podFwChainName + "\n " }
200200 npc .filterTableRules .WriteString (strings .Join (args , " " ))
201201
202202 // ensure there is rule in filter table and OUTPUT chain to jump to pod specific firewall chain
203203 // this rule applies to the traffic from a pod getting routed back to another pod on same node by service proxy
204- args = []string {"-I " , kubeOutputChainName , "1" , "-m" , "comment" , "--comment" , comment , "-d" , pod .ip , "-j" , podFwChainName + "\n " }
204+ args = []string {"-A " , kubeOutputChainName , "-m" , "comment" , "--comment" , comment , "-d" , pod .ip , "-j" , podFwChainName + "\n " }
205205 npc .filterTableRules .WriteString (strings .Join (args , " " ))
206206
207207 // ensure there is rule in filter table and forward chain to jump to pod specific firewall chain
208208 // this rule applies to the traffic getting switched (coming for same node pods)
209209 comment = "\" rule to jump traffic destined to POD name:" + pod .name + " namespace: " + pod .namespace +
210210 " to chain " + podFwChainName + "\" "
211- args = []string {"-I " , kubeForwardChainName , "1" , "-m" , "physdev" , "--physdev-is-bridged" ,
211+ args = []string {"-A " , kubeForwardChainName , "-m" , "physdev" , "--physdev-is-bridged" ,
212212 "-m" , "comment" , "--comment" , comment ,
213213 "-d" , pod .ip ,
214214 "-j" , podFwChainName , "\n " }
@@ -218,22 +218,21 @@ func (npc *NetworkPolicyController) interceptPodInboundTraffic(pod *podInfo, pod
218218// setup iptable rules to intercept outbound traffic from pods and run it across the
219219// firewall chain corresponding to the pod so that egress network policies are enforced
220220func (npc * NetworkPolicyController ) interceptPodOutboundTraffic (pod * podInfo , podFwChainName string ) {
221- egressFilterChains := []string {kubeInputChainName , kubeForwardChainName , kubeOutputChainName }
222- for _ , chain := range egressFilterChains {
221+ for _ , chain := range defaultChains {
223222 // ensure there is rule in filter table and FORWARD chain to jump to pod specific firewall chain
224- // this rule applies to the traffic getting forwarded/routed (traffic from the pod destinted
223+ // this rule applies to the traffic getting forwarded/routed (traffic from the pod destined
225224 // to pod on a different node)
226225 comment := "\" rule to jump traffic from POD name:" + pod .name + " namespace: " + pod .namespace +
227226 " to chain " + podFwChainName + "\" "
228- args := []string {"-I " , chain , "1" , "-m" , "comment" , "--comment" , comment , "-s" , pod .ip , "-j" , podFwChainName , "\n " }
227+ args := []string {"-A " , chain , "-m" , "comment" , "--comment" , comment , "-s" , pod .ip , "-j" , podFwChainName , "\n " }
229228 npc .filterTableRules .WriteString (strings .Join (args , " " ))
230229 }
231230
232231 // ensure there is rule in filter table and forward chain to jump to pod specific firewall chain
233232 // this rule applies to the traffic getting switched (coming for same node pods)
234233 comment := "\" rule to jump traffic from POD name:" + pod .name + " namespace: " + pod .namespace +
235234 " to chain " + podFwChainName + "\" "
236- args := []string {"-I " , kubeForwardChainName , "1" , "-m" , "physdev" , "--physdev-is-bridged" ,
235+ args := []string {"-A " , kubeForwardChainName , "-m" , "physdev" , "--physdev-is-bridged" ,
237236 "-m" , "comment" , "--comment" , comment ,
238237 "-s" , pod .ip ,
239238 "-j" , podFwChainName , "\n " }
0 commit comments