Skip to content

Add an option to exclude networks from egress - #386

Open
p-strusiewiczsurmacki-mobica wants to merge 5 commits into
cybozu-go:mainfrom
p-strusiewiczsurmacki-mobica:feat/excluded-cidrs-v3
Open

p-strusiewiczsurmacki-mobica wants to merge 5 commits into
cybozu-go:mainfrom
p-strusiewiczsurmacki-mobica:feat/excluded-cidrs-v3

Conversation

@p-strusiewiczsurmacki-mobica

Copy link
Copy Markdown
Contributor

What was changed

This PR introduces new flag --cluster-networks for coild. When specified this flag will override the default non-egress addresses (IPv4 - RFC1918 - 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 and IPv6 - ULA&LLA - fc00::/7) with specified networks.

Override will happen on per IP family basis - for example, if at least one IPv4 will be provided for --cluster-networks , addresses for IPv4 will be overridden, but IPv6 will stay intact.

Because of how coil use rule priorities, max 100 CIDRs can be added per IP family. The CIDRs should be separated with a comma.

Example

--cluster-networks 10.0.0.0/8,172.18.0.0/1,fd00::/8

Justification for the change

Today Egress NAT orders the ip rules like this: "fwmark, more specific destinations, RFC1918 (IPv4)/ULA&LLA (IPv6), less specific destinations". Less specific destinations are e.g. 0.0.0.0/0 or ::/0.

We use IPv6 addresses outside of ULA&LLA across our pods, services etc, and we would like to be able to change that parameter, as we don't want to route our internal cluster traffic then through the egress NAT, even if someone specifies for example ::/0 as an egress NAT destination for a pod.

Additional info

E2E tests added with this PR.

@tkna
tkna requested a review from terassyi September 28, 2026 05:05
@terassyi

terassyi commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Hi, @p-strusiewiczsurmacki-mobica!
Thank you for submitting this.
I'll review the change, so please wait a moment.

@chez-shanpu
chez-shanpu self-requested a review October 2, 2026 05:33
Comment thread v2/e2e/suite_test.go Outdated
Comment thread docs/cmd-coild.md Outdated

@chez-shanpu chez-shanpu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your fix!
I left some quick comments on the core logic.

Comment thread v2/pkg/nat/netfilter/client.go Outdated
Comment thread v2/pkg/nat/netfilter/client.go Outdated
Comment thread v2/pkg/nat/netfilter/client.go Outdated
Comment thread v2/pkg/nat/netfilter/client.go
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk.strusiewiczsurmacki@cognizant.com>
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
@p-strusiewiczsurmacki-mobica
p-strusiewiczsurmacki-mobica force-pushed the feat/excluded-cidrs-v3 branch 2 times, most recently from 3b030bb to e691d9f Compare October 23, 2026 13:36
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk.strusiewiczsurmacki@cognizant.com>
@p-strusiewiczsurmacki-mobica

p-strusiewiczsurmacki-mobica commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@chez-shanpu Sorry you had to wait, but all the issues above should be fixed now, I think :)

Comment thread docs/cmd-coild.md Outdated
Comment thread v2/cmd/coild/sub/run.go Outdated
Comment thread v2/pkg/nat/netfilter/client_test.go Outdated
Comment thread v2/pkg/nat/netfilter/client.go Outdated
Comment thread v2/pkg/nat/netfilter/cluster_networks_test.go Outdated
Comment thread v2/e2e/coil_test.go Outdated
Comment thread v2/e2e/coil_test.go Outdated
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
Co-authored-by: Tomoki Sugiura <tomoki.sugiura@mail.shanpu.info>

@chez-shanpu chez-shanpu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM :)

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.

4 participants