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

v1.14 Backports 2023-09-08 #28021

Merged
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions daemon/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,16 @@ func newDaemon(ctx context.Context, cleaner *daemonCleanup, params *daemonParams
return nil, nil, err
}

// allocateIPs got us the routerIP so now we can create ipsec endpoint
// we must do this before publishing the router IP otherwise remote
// nodes could pick up the IP and send us outer headers we do not yet
// have xfrm rules for.
if option.Config.EnableIPSec {
if err := ipsec.Init(); err != nil {
log.WithError(err).Error("IPSec init failed")
}
}

// Must occur after d.allocateIPs(), see GH-14245 and its fix.
d.nodeDiscovery.StartDiscovery()

Expand Down
17 changes: 17 additions & 0 deletions pkg/datapath/linux/ipsec/ipsec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,3 +1115,20 @@ func StartStaleKeysReclaimer(ctx context.Context) {
}
}()
}

// We need to install xfrm state for the local router (cilium_host) early
// in daemon init path. This is to ensure that we have the xfrm state in
// place before we advertise the routerIP where other nodes may potentially
// pick it up and start sending traffic to us. This was previously racing
// and creating XfrmInNoState errors because other nodes picked up node
// update before Xfrm config logic was in place. So special case init the
// rule we need early in init flow.
func Init() error {
outerLocalIP := node.GetInternalIPv4Router()
wildcardIP := net.ParseIP("0.0.0.0")
localCIDR := node.GetIPv4AllocRange().IPNet
localWildcardIP := &net.IPNet{IP: wildcardIP, Mask: net.IPv4Mask(0, 0, 0, 0)}

_, err := UpsertIPsecEndpoint(localCIDR, localWildcardIP, outerLocalIP, wildcardIP, 0, IPSecDirIn, false)
return err
}