Skip to content

host-local: validate explicit gateway address family and subnet membership - #1303

Merged
squeed merged 1 commit into
containernetworking:mainfrom
bodapatisaikrishna:fix/host-local-gateway-validation
Oct 14, 2026
Merged

squeed merged 1 commit into
containernetworking:mainfrom
bodapatisaikrishna:fix/host-local-gateway-validation

Conversation

@bodapatisaikrishna

Copy link
Copy Markdown
Contributor

Summary

In Range.Canonicalize (plugins/ipam/host-local/backend/allocator/range.go), when an explicit Gateway is provided, it is canonicalized via canonicalizeIP(&r.Gateway) but its address family and subnet containment are never checked against r.Subnet.

This allowed configurations specifying an out-of-subnet gateway (e.g. subnet 10.0.0.0/24 with gateway 192.168.1.1) or a mismatched address family (e.g. IPv6 gateway with IPv4 subnet) to pass validation silently, causing downstream container routing or configuration failures.

Solution

In Range.Canonicalize, validate that an explicit gateway matches the subnet address family (len(r.Gateway) == len(r.Subnet.IP)) and belongs to the subnet ((*net.IPNet)(&r.Subnet).Contains(r.Gateway)).

Fixes #1294

Testing

  • Added unit test specs in plugins/ipam/host-local/backend/allocator/range_test.go covering out-of-subnet gateway, mismatched address family, and valid inside-subnet gateway.
  • Verified test suite passes cleanly: go test -v ./plugins/ipam/host-local/....

@squeed squeed left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix

@squeed
squeed merged commit 41f5c79 into containernetworking:main Oct 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

host-local: Canonicalize does not validate an explicit gateway's address family or subnet membership

2 participants