-
Notifications
You must be signed in to change notification settings - Fork 1
feat: per-service ingress port filtering #11
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
726e6cf
proxy: add EnsurePortFilter/DeletePortFilter/CleanupPortFilters inter…
mattia-eleuteri 23bc269
controllers: add wholeIPPassthrough helper and wire port-filter calls
mattia-eleuteri e1f16bb
proxy/nft: implement per-service port filtering with port_filter chain
mattia-eleuteri 3e4cb04
proxy/nft: accept ct state established,related in port_filter chain
mattia-eleuteri ced171e
proxy/nft: filter on pod IP at filter priority, fixes egress in PortL…
mattia-eleuteri 66b8699
proxy/nft: split early_snat into egress_snat (raw) and ingress_dnat (…
mattia-eleuteri 7242c97
docs: document wholeIP annotation values and port-filter mode
mattia-eleuteri 0b1a052
controllers: wire port-filter calls into endpoint event handlers
mattia-eleuteri 460c757
proxy/nft: batch netlink ops in EnsurePortFilter and CleanupPortFilters
mattia-eleuteri 5006843
proxy/nft: short-circuit EnsurePortFilter when ports list is empty
mattia-eleuteri 29ea0d7
proxy: refresh stale early_snat references in comments
mattia-eleuteri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package controllers | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| v1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func svcWith(annot map[string]string) *v1.Service { | ||
| return &v1.Service{ObjectMeta: metav1.ObjectMeta{Annotations: annot}} | ||
| } | ||
|
|
||
| func TestHasWholeIPAnnotation(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| svc *v1.Service | ||
| expect bool | ||
| }{ | ||
| {"true value", svcWith(map[string]string{"networking.cozystack.io/wholeIP": "true"}), true}, | ||
| {"false value", svcWith(map[string]string{"networking.cozystack.io/wholeIP": "false"}), true}, | ||
| {"absent annotation", svcWith(map[string]string{}), false}, | ||
| {"nil annotations", &v1.Service{}, false}, | ||
| {"unrelated annotation", svcWith(map[string]string{"foo": "bar"}), false}, | ||
| } | ||
| for _, c := range cases { | ||
| t.Run(c.name, func(t *testing.T) { | ||
| if got := hasWholeIPAnnotation(c.svc); got != c.expect { | ||
| t.Errorf("hasWholeIPAnnotation = %v, want %v", got, c.expect) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestWholeIPPassthrough(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| svc *v1.Service | ||
| expect bool | ||
| }{ | ||
| {"true value", svcWith(map[string]string{"networking.cozystack.io/wholeIP": "true"}), true}, | ||
| {"false value", svcWith(map[string]string{"networking.cozystack.io/wholeIP": "false"}), false}, | ||
| {"absent annotation defaults to passthrough", svcWith(map[string]string{}), true}, | ||
| {"nil annotations defaults to passthrough", &v1.Service{}, true}, | ||
| } | ||
| for _, c := range cases { | ||
| t.Run(c.name, func(t *testing.T) { | ||
| if got := wholeIPPassthrough(c.svc); got != c.expect { | ||
| t.Errorf("wholeIPPassthrough = %v, want %v", got, c.expect) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The port filtering logic introduced in this PR is currently only applied during Service events. However, changes to Endpoints also affect the NAT and filtering state. The
addEndpointFunc,deleteEndpointFunc, andupdateEndpointFunchandlers (which are not modified in this diff but are part of the controller) should be updated to manage port filters similarly to how they manage NAT rules. Without these updates, the firewall state may become inconsistent when pods are added or removed until a Service update event is triggered.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — fixed in 0b1a052. Mirrored the EnsureRules / DeleteRules calls in addEndpointFunc, updateEndpointFunc, and deleteEndpointFunc with EnsurePortFilter / DeletePortFilter so the firewall tracks endpoint changes in real time, not only on Service events.