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

Pod in nat-outgoing should not be SNATed when it accesses local cluster #8961

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wayne-cheng
Copy link
Contributor

@wayne-cheng wayne-cheng commented Jun 29, 2024

Description

When natOutgoing is enabled in a IPPool, packets sent from Calico networked containers in this IP pool to destinations will be SNATed(msaqueraded).

However, we would prefer that the traffic accessing local cluster hosts should not be msaqueraded.

Provide a enum setting natOutgoingExclusions(default: IPPoolsOnly) in felix config.

Configure which type of destinations is excluded from being masqueraded.

  • IPPoolsOnly: destinations outside of this IP pool will be masqueraded.
  • IPPoolsAndHostIPs: destinations outside of this IP pool and all hosts will be masqueraded.

To maintain compatibility, this setting is not unconditionally enabled. We can consider switching its default value to IPPoolsAndHostIPs in the future version.

Related issues/PRs

fixes linux part of #8960

Todos

  • Tests
  • Documentation
  • Release note

Release Note

New Felix config param natOutgoingExclusions allows for configuring which type of destinations is excluded from being masqueraded.

Reminder for the reviewer

Make sure that this PR has the correct labels and milestone set.

Every PR needs one docs-* label.

  • docs-pr-required: This change requires a change to the documentation that has not been completed yet.
  • docs-completed: This change has all necessary documentation completed.
  • docs-not-required: This change has no user-facing impact and requires no docs.

Every PR needs one release-note-* label.

  • release-note-required: This PR has user-facing changes. Most PRs should have this label.
  • release-note-not-required: This PR has no user-facing changes.

Other optional labels:

  • cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.
  • needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.

@wayne-cheng wayne-cheng requested a review from a team as a code owner June 29, 2024 10:44
@marvin-tigera marvin-tigera added this to the Calico v3.29.0 milestone Jun 29, 2024
@marvin-tigera marvin-tigera added release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels Jun 29, 2024
@coutinhop
Copy link
Member

/sem-approve

@caseydavenport
Copy link
Member

I think this is achievable already today by creating a disabled IP pool containing your host IP range which tells Calico these IPs aren't external to the cluster.

This is obviously not ideal for clusters where the host IPs might not fall cleanly into a small set of IP pools.

I do think a setting like this makes a bit more sense on FelixConfiguration than on IP pools - setting this for a single IP pool (at least based on this implementation) is going to enforce the setting on every IP pool with NATOutgoing set, so the config model is a little bit misleading.

@fasaxc WDYT?

@wayne-cheng wayne-cheng force-pushed the fix-iptables-nat-host branch from 009fd68 to e782906 Compare July 9, 2024 01:36
@caseydavenport caseydavenport self-assigned this Jul 18, 2024
@wayne-cheng wayne-cheng force-pushed the fix-iptables-nat-host branch from e782906 to f4603d9 Compare August 23, 2024 00:54
@wayne-cheng wayne-cheng force-pushed the fix-iptables-nat-host branch from cde432b to bae1508 Compare October 8, 2024 01:48
@tomastigera
Copy link
Contributor

This is likely going to work for eBPF mode as well, however, it would be better to propagate the setting to somewhere here

Comment on lines 439 to 491
// When set to true and ip pool setting `natOutgoing` is true, packets sent from Calico networked containers in this pool
// to cluster host subnet will not be excluded from being masqueraded. [Default: false]
DisableHostSubnetNATExclusion bool `json:"disableHostSubnetNATExclusion,omitempty"`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many negatives for me to make much sense out of this. Could you make it a bit easier to read? Perhaps rename it to just HostSubnetSNATExclusion. And expand in the PR description on the two behaviours?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the adjustments. PTAL!

@wayne-cheng wayne-cheng force-pushed the fix-iptables-nat-host branch from bae1508 to c4e462b Compare October 9, 2024 02:52
@wayne-cheng
Copy link
Contributor Author

This is likely going to work for eBPF mode as well, however, it would be better to propagate the setting to somewhere here

In the related issue, I mentioned that Calico for Windows also needs such a setting. I think we can continue to improve it through additional PRs.

@fasaxc
Copy link
Member

fasaxc commented Oct 9, 2024

Could we make this an enum; say:

NATOutgoingExclusions: IPPoolsOnly | IPPoolsAndHostSubnet 

then we can improve over time with new, better options. For example, we could match on the all-hosts IP set to offer IPPoolsAndHostIPs.

@@ -58,6 +58,11 @@ func (r *DefaultRuleRenderer) makeNATOutgoingRuleIPTables(ipVersion uint8, proto
SourceIPSet(masqIPsSetName).
NotDestIPSet(allIPsSetName)

if r.Config.HostSubnetNATExclusion {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using the all-host IP set so the config param name is misleading since it's not using the subnet at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, IPPoolsAndHostIPs can convey the meaning of all-host IPs.
So, should I start changing this config to an enum?
@tomastigera WDYT?

@wayne-cheng wayne-cheng force-pushed the fix-iptables-nat-host branch from c4e462b to 1d8e1d3 Compare October 17, 2024 12:05
@wayne-cheng
Copy link
Contributor Author

Hi, I updated the code and description. PTAL, thanks! @fasaxc

@wayne-cheng wayne-cheng force-pushed the fix-iptables-nat-host branch from 1d8e1d3 to 53e2f39 Compare October 23, 2024 11:07
@caseydavenport caseydavenport removed their assignment Oct 28, 2024
@wayne-cheng wayne-cheng force-pushed the fix-iptables-nat-host branch from ce93465 to a5158e3 Compare November 6, 2024 12:04
@wayne-cheng wayne-cheng force-pushed the fix-iptables-nat-host branch from a5158e3 to d705776 Compare December 23, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-pr-required Change is not yet documented release-note-required Change has user-facing impact (no matter how small)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants