fix(NPC,LBC): harden network policy and load balancer controllers#2042
Open
Aprazor wants to merge 2 commits intocloudnativelabs:masterfrom
Open
fix(NPC,LBC): harden network policy and load balancer controllers#2042Aprazor wants to merge 2 commits intocloudnativelabs:masterfrom
Aprazor wants to merge 2 commits intocloudnativelabs:masterfrom
Conversation
Two defensive fixes:
1. LBC allocateService(): prevent nil pointer panic when no allocation needed
- When a service already has all requested IPs, both err4 and err6 are
nil, but err.Error() was called unconditionally. Add early return when
no allocation was needed and collect per-family error messages safely.
2. NPC pod.go: sanitize pod and policy names before embedding in iptables comments
- Pod names, namespace names, and policy names are concatenated directly
into iptables-restore comment strings. Add sanitizeForComment() that
strips control characters as a defense-in-depth measure.
This was referenced Mar 23, 2026
Table-driven tests covering: clean strings, newline injection, tabs, carriage returns, null bytes, normal K8s names, and empty strings.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What type of PR is this?
bug
What this PR does / why we need it:
Two defensive fixes (per @aauren's consolidation request on #2020):
err.Error()was called on a nil error. Added early return and safe per-family error collection.sanitizeForComment()as defense-in-depth.Supersedes: #2022, #2039
Was AI used during the creation of this PR?
What, if any, amount of integration testing was done with this change in a Kubernetes environment?
Unit tests pass for both lballoc and netpol packages. No integration testing.
Does this PR introduce a breaking change?
Anything else the reviewer should know that wasn't already covered?
The LBC fix changes error message format from
"unable to allocate address: no IPs left"to"unable to allocate address: IPv4: no IPs left"— log/error string change only, no API change.