Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iptables: Fix wrong use of podCIDR in cluster node NAT exclusion #26397

Merged
merged 1 commit into from Jun 27, 2023

Conversation

gandro
Copy link
Member

@gandro gandro commented Jun 21, 2023

By default, in the iptables-based masquerading mode, Cilium will only masquerade traffic coming from the local pod CIDR (allocRange in installMasqueradeRules). However, many IPAM modes such as ENI or multi-pool IPAM do not have a single pod CIDR. Instead, those modes rely on the egress-masquerade-interfaces setting, which only masquerades traffic if it leaves one of the egress-masquerade-interfaces devices.

Therefore, the "exclude traffic to cluster nodes from masquerade" CILIUM_POST_nat rule should also respect the
egress-masquerade-interfaces setting and not masquerade traffic regardless of the value of allocRange (which will not be valid in settings such as ENI mode).

This likely has not manifested in ENI mode as an issue, because in ENI mode we derive the native routing CIDR (snatDstExclusionCIDR in installMasqueradeRules) from the EC2 VPC CIDR, which usually contains the node IPs too. However, we should not rely on that, since we are adding additional non-podCIDR based IPAM modes such as multi-pool where this will not be true.

Related: #22273

Open question: Should this be backported to v1.13? I'm not aware of any actual bugs this has caused so far in ENI mode (see above), but we should fix it nonetheless. I'd particularly would like to have this in v1.14, since it will fix iptables-based masquerading for the newly added Multi-Pool IPAM mode in v1.14.

By default, in the iptables-based masquerading mode, Cilium will only
masquerade traffic coming from the local pod CIDR (`allocRange` in
`installMasqueradeRules`). However, many IPAM modes such as ENI or
multi-pool IPAM do not have a single pod CIDR. Instead, those modes rely
on the `egress-masquerade-interfaces` setting, which masquerades all
traffic if it leaves one of the `egress-masquerade-interfaces` devices.

Therefore, the "exclude traffic to cluster nodes from masquerade"
`CILIUM_POST_nat` rule should also respect the
`egress-masquerade-interfaces` setting and not masquerade traffic
regardless of the value of `allocRange` (which will not be valid in
settings such as ENI mode).

This likely has not manifested in ENI mode as an issue, because in ENI
mode we derive the native routing CIDR (`snatDstExclusionCIDR` in
`installMasqueradeRules`) from the EC2 VPC CIDR, which usually contains
the node IPs too. However, we should not rely on that, since we are
adding additional non-podCIDR based IPAM modes such as multi-pool where
this will not be true.

Related: cilium#22273

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
@gandro gandro added the release-note/bug This PR fixes an issue in a previous release of Cilium. label Jun 21, 2023
@gandro gandro requested a review from a team as a code owner June 21, 2023 13:42
@gandro gandro requested a review from ldelossa June 21, 2023 13:42
@gandro
Copy link
Member Author

gandro commented Jun 21, 2023

/test

@christarazi christarazi added sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. area/eni Impacts ENI based IPAM. area/ipam Impacts IP address management functionality. labels Jun 21, 2023
@gandro
Copy link
Member Author

gandro commented Jun 22, 2023

@gandro
Copy link
Member Author

gandro commented Jun 27, 2023

Louis says he does not have time to review

@gandro gandro removed the request for review from ldelossa June 27, 2023 11:30
@jibi jibi self-requested a review June 27, 2023 12:15
@gandro
Copy link
Member Author

gandro commented Jun 27, 2023

Marking ready to merge. gateway-api-conformance-test are pending since the test was renamed since I ran CI, but the previous version of it has passed: https://github.com/cilium/cilium/actions/runs/5334861019/jobs/9667235765?pr=26397

@gandro gandro added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 27, 2023
@borkmann borkmann merged commit 1b14951 into cilium:main Jun 27, 2023
64 checks passed
gandro added a commit to gandro/cilium that referenced this pull request Jun 28, 2023
With cilium#26397 merged, iptables-based masquerading can now be used together
with Multi-Pool IPAM, as long as `egressMasqueradeInterfaces` is set
too.

This commit adjusts the documentation to reflect that and improves the
wording of that section a bit.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
borkmann pushed a commit that referenced this pull request Jul 3, 2023
With #26397 merged, iptables-based masquerading can now be used together
with Multi-Pool IPAM, as long as `egressMasqueradeInterfaces` is set
too.

This commit adjusts the documentation to reflect that and improves the
wording of that section a bit.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
joamaki pushed a commit to joamaki/cilium that referenced this pull request Jul 6, 2023
[ upstream commit 970f881 ]

With cilium#26397 merged, iptables-based masquerading can now be used together
with Multi-Pool IPAM, as long as `egressMasqueradeInterfaces` is set
too.

This commit adjusts the documentation to reflect that and improves the
wording of that section a bit.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Jussi Maki <jussi@isovalent.com>
jibi pushed a commit that referenced this pull request Jul 10, 2023
[ upstream commit 970f881 ]

With #26397 merged, iptables-based masquerading can now be used together
with Multi-Pool IPAM, as long as `egressMasqueradeInterfaces` is set
too.

This commit adjusts the documentation to reflect that and improves the
wording of that section a bit.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Jussi Maki <jussi@isovalent.com>
ldelossa pushed a commit to ldelossa/cilium that referenced this pull request Sep 27, 2023
[ upstream commit 970f881 ]

With cilium#26397 merged, iptables-based masquerading can now be used together
with Multi-Pool IPAM, as long as `egressMasqueradeInterfaces` is set
too.

This commit adjusts the documentation to reflect that and improves the
wording of that section a bit.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Jussi Maki <jussi@isovalent.com>
Signed-off-by: Gilberto Bertin <jibi@cilium.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/eni Impacts ENI based IPAM. area/ipam Impacts IP address management functionality. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/bug This PR fixes an issue in a previous release of Cilium. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants