-
Notifications
You must be signed in to change notification settings - Fork 26
Allow alert from unexpected Ports, allow Port=0 as intentional wildcard #905
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
Draft
entlein
wants to merge
3
commits into
kubescape:main
Choose a base branch
from
k8sstormcenter:upstream-pr/portalerts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
e6b7fab
Allow alert from unexpected Ports, allow Port=0 as intentional wildcard
entlein 456d267
Allow alert from unexpected Ports, allow Port=0 as intentional wildcard
entlein ffb22be
remove explicit wildcard, declare port as non-mandatory, keep the ale…
entlein 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package objectcache | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" | ||
| "github.com/stretchr/testify/assert" | ||
| "k8s.io/utils/ptr" | ||
| ) | ||
|
|
||
| func np(proto string, p int32) v1beta1.NetworkPort { | ||
| return v1beta1.NetworkPort{Protocol: v1beta1.Protocol(proto), Port: ptr.To(p)} | ||
| } | ||
|
|
||
| func TestExtractAddrPorts_ZeroPortIsALiteralNotAWildcard(t *testing.T) { | ||
| groups := ExtractAddrPorts([]v1beta1.NetworkNeighbor{ | ||
| {IPAddresses: []string{"10.0.5.9"}, Ports: []v1beta1.NetworkPort{np("TCP", 0), np("UDP", 53)}}, | ||
| }) | ||
| assert.Len(t, groups, 1) | ||
| assert.NotNil(t, groups[0].Ports, "a zero-port entry must not collapse the entry to fully open") | ||
| assert.Contains(t, groups[0].Ports, PortKey("TCP", 0)) | ||
| assert.Contains(t, groups[0].Ports, PortKey("UDP", 53)) | ||
| assert.Len(t, groups[0].Ports, 2) | ||
| } | ||
|
|
||
| func TestExtractAddrPorts_AbsentStanzaIsTheOnlyWildcard(t *testing.T) { | ||
| groups := ExtractAddrPorts([]v1beta1.NetworkNeighbor{ | ||
| {IPAddresses: []string{"93.184.216.34"}}, | ||
| }) | ||
| assert.Len(t, groups, 1) | ||
| assert.Nil(t, groups[0].Ports) | ||
| } | ||
|
|
||
| func TestExtractAddrPorts_NilPortEntryContributesNothing(t *testing.T) { | ||
| groups := ExtractAddrPorts([]v1beta1.NetworkNeighbor{ | ||
| {IPAddresses: []string{"10.1.2.3"}, Ports: []v1beta1.NetworkPort{{Protocol: "TCP", Port: nil}, np("UDP", 53)}}, | ||
| }) | ||
| assert.Len(t, groups, 1) | ||
| assert.NotNil(t, groups[0].Ports) | ||
| assert.NotContains(t, groups[0].Ports, PortKey("TCP", 0)) | ||
| assert.Contains(t, groups[0].Ports, PortKey("UDP", 53)) | ||
| assert.Len(t, groups[0].Ports, 1) | ||
| } |
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
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
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
Oops, something went wrong.
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.
wildcardis computed once per neighbor entry, not per protocol/port. If a singleNetworkNeighbormixes aPort: 0entry for one protocol with specific ports for another (e.g.{TCP, 0}+{UDP, 53}), theif wildcard { ports = nil }below drops all of that entry's ports — so the address becomes open on both TCP and UDP, any port, even though UDP was explicitly restricted to 53. Worth either scoping the wildcard to its own protocol (e.g.map[string]struct{}keyed loosely, or drop only matching-protocol port entries) or documenting that mixing aPort: 0entry with other protocols' specific ports in the same neighbor isn't supported and will fully open that address.Uh oh!
There was an error while loading. Please reload this page.
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.
Very true,
The easiest solution to this might be to backtrack and treat the
nullas the wildcard (i.e. if the port is not specified, it is treated asANY) . Thats however not consistent with the narrative of the profiles.Guess, its a good point in time, to review all our settings for what they mean is
absent, null, wrong, or wildcarded.So, the base premise is:
if it aint explicitely listed, it aint allowed, so it'll alertOh dear oh dear 🤣😅,That ll break things, so maybe, this mantra needs the extension
unless its a non-mandatory field, in which case the absence of the entry meansANYTHING goes.(I think, I just found another bug (beyond this one), darn)... THANKS FOR THE REVIEW!
EDIT: bug=logic bug, not code