fix: strip StatefulSet pod-identity labels from network peer selectors - #945
fix: strip StatefulSet pod-identity labels from network peer selectors#945ANAMASGARD wants to merge 1 commit into
Conversation
StatefulSet pods carry apps.kubernetes.io/pod-index and statefulset.kubernetes.io/pod-name labels that are per-replica, not workload-level. Carrying them into NetworkNeighbor podSelectors caused GeneratedNetworkPolicy to pin peers to replicas seen during learning, denying traffic when the StatefulSet scales up. Fixes kubescape#942 Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe label filter now ignores StatefulSet pod identity labels. Tests verify that generated peer selectors retain workload labels and exclude pod-index and pod-name labels across multiple replicas. ChangesStatefulSet label filtering
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: 🟡 Moderate · up to The change correctly broadens StatefulSet peer selection across replicas, but a peer with no remaining labels could generate a policy that matches all pods in a namespace. Confirm or guard the downstream conversion before merging. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
StatefulSet pods carry
apps.kubernetes.io/pod-indexandstatefulset.kubernetes.io/pod-namelabels that are per-replica, not workload-level. Carrying them intoNetworkNeighborpodSelectors causedGeneratedNetworkPolicyto pin peers to replicas seen during learning, denying traffic when the StatefulSet scales up.Fixes #942
Overview
Current behavior: When the peer is a StatefulSet, learned
NetworkNeighbor.PodSelectorincludes per-replica identity labels (apps.kubernetes.io/pod-index,statefulset.kubernetes.io/pod-name). That produces one NetworkPolicy peer rule per replica and breaks after scale-up.Future behavior: Those StatefulSet pod-identity labels are stripped in
filterLabels()/DefaultLabelsToIgnore, so peer selectors keep only workload labels (e.g.app.kubernetes.io/name).This PR fixes learning at the source (new
ContainerProfileneighbors). A companion change inkubescape/storagesanitizes legacy profiles that already carrypod-indexat GNP generation time.How to Test
Expected: all cases pass, including table-driven replicas
0/1/2with onlyapp.kubernetes.io/name=dbremaining inPodSelector.MatchLabels.Related issues/PRs
kubescape/storagePR — ignoreapps.kubernetes.io/pod-indexwhen generating network policies (link after opening)Checklist before requesting a review
go test ./...not re-run in this environment)Summary by CodeRabbit
Bug Fixes
Tests