-
Notifications
You must be signed in to change notification settings - Fork 27
feat(network): symmetric R0011/R0012 with NetworkPolicy-style internal allowlisting and port-aware alerting #923
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
Open
entlein
wants to merge
42
commits into
kubescape:main
Choose a base branch
from
k8sstormcenter:feat/network-v2
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.
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
14a3283
allow networkpolicy to be a cel selector for internal/external traffi…
entlein 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 283098d
feat(cel/network): serviceRef/serviceSelector/host neighbor resolution
entlein 6f30d65
feat(cel/network): real-Flux component test, RBAC + perf fixes for se…
entlein 7d294ca
test(component): scope the internal-egress rule to the serviceRef suite
entlein 8d5a019
test(chart): make network service resolution a value
entlein 369fbe6
fix(cel): invalidate cached results when a profile is re-resolved
entlein e240448
feat(rules): R0012 unexpected internal egress
entlein 9537cf0
feat(rules): R0011/R0012 symmetric egress/ingress, no IP-class gate
entlein b9328c0
Merge remote-tracking branch 'origin/upstream-pr/portalerts' into fea…
entlein 8a74230
Merge remote-tracking branch 'origin/upstream-pr/serviceref-network' …
entlein 9c272fa
Merge branch 'feat/rules-internal-egress' into feat/network-v2
entlein 9a5dca6
dedup selector engine after portalerts merge
entlein 60962b8
pin storage to k8sstormcenter/storage@3844202a (dnsNames + deflate fi…
entlein 70ebf6d
test(component): Test_50 asserts shipped R0011; Test_51 ingress R0012…
entlein 20791f1
chart(kubescape-rules): standalone chart shipping the R0011/R0012 rul…
entlein eb2f79e
Merge branch 'feat/rules-internal-egress' into feat/network-v2
entlein 5a17ba0
rules: consume the peer-selector engine in R0011/R0012
entlein 4280eae
review: address maintainer blockers on network-v2
entlein 91c6dec
fix(cel/network): label-only peer matching, empty selector fails closed
entlein daad334
test(networkpeer): characterize excludeNamespaces × selector resolution
entlein 3c45703
test(cel/network): eval-level selector truth tables, matchAddrPort gr…
entlein bc4abc6
test: pin default-posture R0011/R0012 behavior on learned profiles (T…
entlein 7e4b47e
fix(learn): record service ClusterIP so learned profiles don't false-…
entlein 96cb0b9
feat(network): silence node/host peers by default; expose loopback to…
entlein 9a08bc9
build: pin inspektor-gadget fork to kubescape (matches upstream #925)
entlein 14f912f
Revert the standalone kubescape-rules chart
entlein 36ae810
fix(network): address review — port-aware selector matching + CR nits
entlein 1001913
test(testutils): use a YAML document reader for multi-doc apply (Code…
entlein 7cdd5fb
perf(projection): don't mark every profile resolution-dependent for t…
entlein 7aa43ae
test(component): make Test_20/30/36 deterministic — kill the flakes
entlein a19e064
fix(projection): keep host-injected profiles resolution-dependent (ma…
entlein 54041a5
test(component): Test_54 — peer allowlisting is namespace-invariant (…
entlein ba27b23
Revert "test(component): Test_54 — peer allowlisting is namespace-inv…
entlein a370aba
feat(network): commit to namespace-agnostic peer matching, drop dead …
entlein 652e98f
test(network): name the namespace-disambiguation collision case expli…
entlein 6741015
feat(network): NetworkPolicy namespaceSelector semantics — omitted=sa…
entlein f4ea9a6
feat(network): unify serviceSelector namespace semantics with the pod…
entlein db256c4
pinning sotrage to kubescape
entlein 2707b4a
pinning sotrage to kubescape part 2
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
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
98 changes: 98 additions & 0 deletions
98
pkg/containerprofilemanager/v1/container_data_service_test.go
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,98 @@ | ||
| package containerprofilemanager | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/kubescape/k8s-interface/k8sinterface" | ||
| "github.com/kubescape/k8s-interface/workloadinterface" | ||
| "github.com/kubescape/node-agent/pkg/objectcache" | ||
| "github.com/kubescape/node-agent/pkg/utils" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "k8s.io/client-go/dynamic" | ||
| "k8s.io/client-go/kubernetes" | ||
| ) | ||
|
|
||
| type fakeServiceClient struct { | ||
| selector map[string]interface{} | ||
| labels map[string]interface{} | ||
| } | ||
|
|
||
| func (f *fakeServiceClient) GetWorkload(namespace, _, name string) (k8sinterface.IWorkload, error) { | ||
| meta := map[string]interface{}{"name": name, "namespace": namespace} | ||
| if f.labels != nil { | ||
| meta["labels"] = f.labels | ||
| } | ||
| spec := map[string]interface{}{} | ||
| if f.selector != nil { | ||
| spec["selector"] = f.selector | ||
| } | ||
| return workloadinterface.NewWorkloadObj(map[string]interface{}{ | ||
| "apiVersion": "v1", | ||
| "kind": "Service", | ||
| "metadata": meta, | ||
| "spec": spec, | ||
| }), nil | ||
| } | ||
|
|
||
| func (f *fakeServiceClient) CalculateWorkloadParentRecursive(w k8sinterface.IWorkload) (string, string, error) { | ||
| return w.GetKind(), w.GetName(), nil | ||
| } | ||
| func (f *fakeServiceClient) GetKubernetesClient() kubernetes.Interface { return nil } | ||
| func (f *fakeServiceClient) GetDynamicClient() dynamic.Interface { return nil } | ||
|
|
||
| // A service neighbor records its stable ClusterIP so detection matches the peer | ||
| // by address (the learned selector alone misses on CNIs that keep the pre-DNAT | ||
| // ClusterIP on the wire, since IG stamps the service's metadata labels while the | ||
| // learned selector holds the pod selector), and a selectorless service is kept. | ||
| func TestCreateNetworkNeighbor_ServiceRecordsClusterIP(t *testing.T) { | ||
| const clusterIP = "10.43.12.34" | ||
| cd := &containerData{watchedContainerData: &objectcache.WatchedContainerData{Namespace: "default"}} | ||
| ev := NetworkEvent{ | ||
| Port: 80, | ||
| Protocol: "tcp", | ||
| PktType: utils.OutgoingPktType, | ||
| Destination: Destination{ | ||
| Kind: EndpointKindService, | ||
| Namespace: "default", | ||
| Name: "nginx", | ||
| IPAddress: clusterIP, | ||
| }, | ||
| } | ||
|
|
||
| withSel := &fakeServiceClient{selector: map[string]interface{}{"app": "nginx"}} | ||
| n := cd.createNetworkNeighbor(ev, "default", withSel, nil) | ||
| require.NotNil(t, n) | ||
| assert.Equal(t, clusterIP, n.IPAddress, "a service neighbor must record its stable ClusterIP") | ||
| require.NotNil(t, n.PodSelector, "a service with a selector keeps its pod selector") | ||
| assert.Equal(t, "nginx", n.PodSelector.MatchLabels["app"]) | ||
|
|
||
| noSel := &fakeServiceClient{} | ||
| n2 := cd.createNetworkNeighbor(ev, "default", noSel, nil) | ||
| require.NotNil(t, n2, "a selectorless service must not be dropped — the ClusterIP identifies it") | ||
| assert.Equal(t, clusterIP, n2.IPAddress) | ||
| assert.Nil(t, n2.PodSelector, "no selector to learn when the service defines none") | ||
| } | ||
|
|
||
| // With the 127.0.0.1 learn-drop removed, loopback and its aliases are learned | ||
| // as address neighbors (subject to R0011/R0012) instead of being silently | ||
| // dropped — loopback is a real attack surface (localhost admin panels, sidecar | ||
| // pivots). Only the literal 127.0.0.1 changed behavior; the others were never | ||
| // dropped, and this pins that they all remain learnable. | ||
| func TestCreateNetworkNeighbor_LoopbackAliasesLearned(t *testing.T) { | ||
| cd := &containerData{watchedContainerData: &objectcache.WatchedContainerData{Namespace: "default"}} | ||
| for _, ip := range []string{"127.0.0.1", "127.0.0.53", "::1", "0.0.0.0"} { | ||
| ev := NetworkEvent{ | ||
| Port: 8080, | ||
| Protocol: "tcp", | ||
| PktType: utils.OutgoingPktType, | ||
| Destination: Destination{ | ||
| Kind: EndpointKindRaw, | ||
| IPAddress: ip, | ||
| }, | ||
| } | ||
| n := cd.createNetworkNeighbor(ev, "default", nil, nil) | ||
| require.NotNil(t, n, "loopback/localhost %s must be learned (guard removed), not dropped", ip) | ||
| assert.Equal(t, ip, n.IPAddress, "loopback %s recorded as an address neighbor", ip) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.