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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions pkg/datapath/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,13 +1193,26 @@ func (m *IptablesManager) installMasqueradeRules(prog iptablesInterface, ifName,
return err
}

if err := prog.runProg([]string{
progArgs := []string{
"-t", "nat",
"-A", ciliumPostNatChain,
"-s", allocRange,
}

// If EgressMasqueradeInterfaces is set, we need to mirror base condition
// of the "cilium masquerade non-cluster" rule below, as the allocRange might
// not be valid in such setups (e.g. in ENI mode).
if option.Config.EgressMasqueradeInterfaces != "" {
progArgs = append(progArgs, "-o", option.Config.EgressMasqueradeInterfaces)
} else {
progArgs = append(progArgs, "-s", allocRange)
}

progArgs = append(progArgs,
"-m", "set", "--match-set", prog.getIpset(), "dst",
"-m", "comment", "--comment", "exclude traffic to cluster nodes from masquerade",
"-j", "ACCEPT"}); err != nil {
"-j", "ACCEPT",
)
if err := prog.runProg(progArgs); err != nil {
return err
}
}
Expand Down