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 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/pkg/apis/projectcalico/v3/felixconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ type FelixConfigurationSpec struct {
// (ie it uses the iptables MASQUERADE target)
NATOutgoingAddress string `json:"natOutgoingAddress,omitempty"`

// 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"`

// This is the IPv4 source address to use on programmed device routes. By default the source address is left blank,
// leaving the kernel to choose the source address used.
DeviceRouteSourceAddress string `json:"deviceRouteSourceAddress,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions api/pkg/openapi/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calicoctl/calicoctl/commands/crds/crds.go

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions felix/config/config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,10 @@ type Config struct {
FailsafeInboundHostPorts []ProtoPort `config:"port-list;tcp:22,udp:68,tcp:179,tcp:2379,tcp:2380,tcp:5473,tcp:6443,tcp:6666,tcp:6667;die-on-fail"`
FailsafeOutboundHostPorts []ProtoPort `config:"port-list;udp:53,udp:67,tcp:179,tcp:2379,tcp:2380,tcp:5473,tcp:6443,tcp:6666,tcp:6667;die-on-fail"`

KubeNodePortRanges []numorstring.Port `config:"portrange-list;30000:32767"`
NATPortRange numorstring.Port `config:"portrange;"`
NATOutgoingAddress net.IP `config:"ipv4;"`
KubeNodePortRanges []numorstring.Port `config:"portrange-list;30000:32767"`
NATPortRange numorstring.Port `config:"portrange;"`
NATOutgoingAddress net.IP `config:"ipv4;"`
DisableHostSubnetNATExclusion bool `config:"bool;false"`

UsageReportingEnabled bool `config:"bool;true"`
UsageReportingInitialDelaySecs time.Duration `config:"seconds;300"`
Expand Down
1 change: 1 addition & 0 deletions felix/dataplane/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func StartDataplaneDriver(configParams *config.Config,
NATPortRange: configParams.NATPortRange,
IptablesNATOutgoingInterfaceFilter: configParams.IptablesNATOutgoingInterfaceFilter,
NATOutgoingAddress: configParams.NATOutgoingAddress,
DisableHostSubnetNATExclusion: configParams.DisableHostSubnetNATExclusion,
BPFEnabled: configParams.BPFEnabled,
BPFForceTrackPacketsFromIfaces: configParams.BPFForceTrackPacketsFromIfaces,
ServiceLoopPrevention: configParams.ServiceLoopPrevention,
Expand Down
6 changes: 4 additions & 2 deletions felix/dataplane/linux/masq_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ var _ = Describe("Masquerade manager", func() {
Action: iptables.MasqAction{},
Match: iptables.Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net"),
},
},
}}})
Expand Down Expand Up @@ -147,7 +148,8 @@ var _ = Describe("Masquerade manager", func() {
Action: iptables.MasqAction{},
Match: iptables.Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net"),
},
},
}}})
Expand Down
5 changes: 5 additions & 0 deletions felix/rules/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func (r *DefaultRuleRenderer) makeNATOutgoingRuleIPTables(ipVersion uint8, proto
SourceIPSet(masqIPsSetName).
NotDestIPSet(allIPsSetName)

if !r.Config.DisableHostSubnetNATExclusion {
allHostsIPsSetName := ipConf.NameForMainIPSet(IPSetIDAllHostNets)
match = match.NotDestIPSet(allHostsIPsSetName)
}

if protocol != "" {
match = match.Protocol(protocol)
}
Expand Down
49 changes: 33 additions & 16 deletions felix/rules/nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ var _ = Describe("NAT", func() {
Action: MasqAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net"),
},
},
}))
Expand All @@ -74,7 +75,8 @@ var _ = Describe("NAT", func() {
Action: SNATAction{ToAddr: snatAddress},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net"),
},
},
}))
Expand All @@ -92,31 +94,36 @@ var _ = Describe("NAT", func() {
Action: MasqAction{ToPorts: "99-100"},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("tcp"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("tcp"),
},
{
Action: ReturnAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("tcp"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("tcp"),
},
{
Action: MasqAction{ToPorts: "99-100"},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("udp"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("udp"),
},
{
Action: ReturnAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("udp"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("udp"),
},
{
Action: MasqAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net"),
},
},
}))
Expand All @@ -135,35 +142,40 @@ var _ = Describe("NAT", func() {
Action: MasqAction{ToPorts: "99-100"},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("tcp").
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("tcp").
OutInterface("cali-123"),
},
{
Action: ReturnAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("tcp").
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("tcp").
OutInterface("cali-123"),
},
{
Action: MasqAction{ToPorts: "99-100"},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("udp").
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("udp").
OutInterface("cali-123"),
},
{
Action: ReturnAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("udp").
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("udp").
OutInterface("cali-123"),
},
{
Action: MasqAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").
OutInterface("cali-123"),
},
},
Expand All @@ -186,31 +198,36 @@ var _ = Describe("NAT", func() {
Action: SNATAction{ToAddr: expectedAddress},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("tcp"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("tcp"),
},
{
Action: ReturnAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("tcp"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("tcp"),
},
{
Action: SNATAction{ToAddr: expectedAddress},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("udp"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("udp"),
},
{
Action: ReturnAction{},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools").Protocol("udp"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net").Protocol("udp"),
},
{
Action: SNATAction{ToAddr: snatAddress},
Match: Match().
SourceIPSet("cali40masq-ipam-pools").
NotDestIPSet("cali40all-ipam-pools"),
NotDestIPSet("cali40all-ipam-pools").
NotDestIPSet("cali40all-hosts-net"),
},
},
}))
Expand Down
1 change: 1 addition & 0 deletions felix/rules/rule_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ type Config struct {
IptablesNATOutgoingInterfaceFilter string

NATOutgoingAddress net.IP
DisableHostSubnetNATExclusion bool
BPFEnabled bool
BPFForceTrackPacketsFromIfaces []string
ServiceLoopPrevention string
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico-bpf.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico-policy-only.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico-typha.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico-vxlan.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/canal.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/crds.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/flannel-migration/calico.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/operator-crds.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/tigera-operator.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.