Skip to content

feat(ressrf): expose the deny CIDR set for callers to mirror the gate - #36

Merged
gonzaloserrano merged 2 commits into
mainfrom
gsr/expose-denied-ip-prefixes
Jun 10, 2026
Merged

gonzaloserrano merged 2 commits into
mainfrom
gsr/expose-denied-ip-prefixes

Conversation

@gonzaloserrano

@gonzaloserrano gonzaloserrano commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

A consumer enforcing the same policy at the network layer (e.g. a Kubernetes NetworkPolicy egress except-list) must block the same IP ranges the application-layer dial gate enforces, but there was no way to read a policy's deny set, so it had to hand-maintain a parallel CIDR list that silently drifts from the gate.

Adds Policy.DeniedIPPrefixes() returning the network-layer deny ranges in native form (IPv4 as Is4 prefixes via the new CIDR.NativePrefix(), not the IPv4-mapped form the matcher stores internally), so a caller rendering a Kubernetes NetworkPolicy egress except-list can derive it from the policy. denied_prefixes_test.go pins the invariant that the exported set equals what IsNetworkAllowed enforces, so the network-layer block list and the dial gate can't drift apart.

The exported set is the raw deny set, de-duplicated; WithAllowedCIDRs is not subtracted (documented on the method). PresetExternalOnly returns the built-in deny set plus any cloud-provider and user-supplied denies; PresetNone and PresetInternalOnly return nil.

Add Policy.DeniedIPPrefixes() returning the network-layer deny ranges (PresetExternalOnly default set plus WithCloudProviderDenies and WithDeniedCIDRs entries; nil for PresetNone/InternalOnly), and CIDR.NativePrefix() to return IPv4 ranges in native 4-byte form rather than the IPv4-mapped form the matcher stores internally.

A consumer that must mirror the gate at another layer (e.g. a Kubernetes NetworkPolicy egress except-list) can derive it from the policy instead of hand-maintaining a parallel CIDR list that drifts. denied_prefixes_test.go pins the invariant that the exported set equals what IsNetworkAllowed enforces.
…nimal

A metadata IP that lives in both the built-in deny set and a cloud-provider
module (169.254.169.254/32, 169.254.170.2/32, fd00:ec2::254/128 under
PresetExternalOnly + WithCloudProviderDenies(CloudAWS)) was returned twice,
so a NetworkPolicy except-list derived from DeniedIPPrefixes() carried
duplicate entries that some API servers reject. De-duplicate in first-seen
order; add a no-duplicate assertion to TestDeniedIPPrefixes.
@gonzaloserrano
gonzaloserrano merged commit 71a45f9 into main Jun 10, 2026
22 of 23 checks passed
@gonzaloserrano
gonzaloserrano deleted the gsr/expose-denied-ip-prefixes branch June 10, 2026 13:37
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.

2 participants