@@ -84,6 +84,10 @@ const (
8484 // kubeLoadBalancerChain is the kubernetes chain for loadbalancer type service
8585 kubeLoadBalancerChain utiliptables.Chain = "KUBE-LOAD-BALANCER"
8686
87+ // kubeIPVSFilterChain filters external access to main netns
88+ // https://github.com/kubernetes/kubernetes/issues/72236
89+ kubeIPVSFilterChain utiliptables.Chain = "KUBE-IPVS-FILTER"
90+
8791 // defaultScheduler is the default ipvs scheduler algorithm - round robin.
8892 defaultScheduler = "rr"
8993
@@ -112,6 +116,7 @@ var iptablesJumpChain = []struct {
112116 {utiliptables .TableFilter , utiliptables .ChainInput , kubeNodePortChain , "kubernetes health check rules" },
113117 {utiliptables .TableFilter , utiliptables .ChainInput , kubeProxyFirewallChain , "kube-proxy firewall rules" },
114118 {utiliptables .TableFilter , utiliptables .ChainForward , kubeProxyFirewallChain , "kube-proxy firewall rules" },
119+ {utiliptables .TableFilter , utiliptables .ChainInput , kubeIPVSFilterChain , "kubernetes ipvs access filter" },
115120}
116121
117122var iptablesChains = []struct {
@@ -127,6 +132,7 @@ var iptablesChains = []struct {
127132 {utiliptables .TableFilter , kubeNodePortChain },
128133 {utiliptables .TableFilter , kubeProxyFirewallChain },
129134 {utiliptables .TableFilter , kubeSourceRangesFirewallChain },
135+ {utiliptables .TableFilter , kubeIPVSFilterChain },
130136}
131137
132138var iptablesCleanupChains = []struct {
@@ -141,6 +147,7 @@ var iptablesCleanupChains = []struct {
141147 {utiliptables .TableFilter , kubeNodePortChain },
142148 {utiliptables .TableFilter , kubeProxyFirewallChain },
143149 {utiliptables .TableFilter , kubeSourceRangesFirewallChain },
150+ {utiliptables .TableFilter , kubeIPVSFilterChain },
144151}
145152
146153// ipsetInfo is all ipset we needed in ipvs proxier
@@ -165,6 +172,7 @@ var ipsetInfo = []struct {
165172 {kubeNodePortSetSCTP , utilipset .HashIPPort , kubeNodePortSetSCTPComment },
166173 {kubeNodePortLocalSetSCTP , utilipset .HashIPPort , kubeNodePortLocalSetSCTPComment },
167174 {kubeHealthCheckNodePortSet , utilipset .BitmapPort , kubeHealthCheckNodePortSetComment },
175+ {kubeIPVSSet , utilipset .HashIP , kubeIPVSSetComment },
168176}
169177
170178// ipsetWithIptablesChain is the ipsets list with iptables source chain and the chain jump to
@@ -1549,6 +1557,9 @@ func (proxier *Proxier) syncProxyRules() {
15491557 }
15501558 }
15511559
1560+ // Set the KUBE-IPVS-IPS set to the "activeBindAddrs"
1561+ proxier .ipsetList [kubeIPVSSet ].activeEntries = sets .StringKeySet (activeBindAddrs )
1562+
15521563 // sync ipset entries
15531564 for _ , set := range proxier .ipsetList {
15541565 set .syncIPSetEntries ()
@@ -1792,6 +1803,22 @@ func (proxier *Proxier) writeIptablesRules() {
17921803 "-j" , "ACCEPT" ,
17931804 )
17941805
1806+ // Add rules to the filter/KUBE-IPVS-FILTER chain to prevent access to ports on the host through VIP addresses.
1807+ // https://github.com/kubernetes/kubernetes/issues/72236
1808+ proxier .filterRules .Write (
1809+ "-A" , string (kubeIPVSFilterChain ),
1810+ "-m" , "set" , "--match-set" , proxier .ipsetList [kubeLoadBalancerSet ].Name , "dst,dst" , "-j" , "ACCEPT" )
1811+ proxier .filterRules .Write (
1812+ "-A" , string (kubeIPVSFilterChain ),
1813+ "-m" , "set" , "--match-set" , proxier .ipsetList [kubeClusterIPSet ].Name , "dst,dst" , "-j" , "ACCEPT" )
1814+ proxier .filterRules .Write (
1815+ "-A" , string (kubeIPVSFilterChain ),
1816+ "-m" , "set" , "--match-set" , proxier .ipsetList [kubeExternalIPSet ].Name , "dst,dst" , "-j" , "ACCEPT" )
1817+ proxier .filterRules .Write (
1818+ "-A" , string (kubeIPVSFilterChain ),
1819+ "-m" , "conntrack" , "--ctstate" , "NEW" ,
1820+ "-m" , "set" , "--match-set" , proxier .ipsetList [kubeIPVSSet ].Name , "dst" , "-j" , "REJECT" )
1821+
17951822 // Install the kubernetes-specific postrouting rules. We use a whole chain for
17961823 // this so that it is easier to flush and change, for example if the mark
17971824 // value should ever change.
0 commit comments