Repository navigation
fix(mainhandler): list namespaces for a cluster-wide image scan request - #489
Conversation
getNamespaces put the namespace of the request's ID in the list, and for a
cluster-wide WildWlid (such as the SecurityException watcher's image rescan)
that is "". A list holding "" isn't empty, so the "list every namespace"
branch never ran and HandleImageScanningScopedRequest worked on "" instead:
- SkipNamespace("") is true whenever includeNamespaces is set, so a
cluster-wide image scan scanned nothing at all;
- ContainerProfiles were looked up in namespace "", which client-go refuses
for a named Get, so these scans never used relevancy.
Leave an empty namespace out, so every namespace is listed and each is
filtered and looked up on its own.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: itsvishalyadav <vishalyadav87695@gmail.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
matthyx
left a comment
There was a problem hiding this comment.
Approving 88614e2 (base main). No blockers found.
- Need: Confirmed on
main. For a cluster-wide WildWlid,getNamespacesreturns[""], which is non-empty, so the "list all namespaces" fallback never runs. WithincludeNamespacesset, nothing is scanned. Without it, ContainerProfiles are fetched in namespace"", so relevancy scans never start. Matches #488. - Fix: Skipping an empty namespace lets the existing fallback run. Requests with a namespace or with designators behave as before. This is the cause, not a symptom patch. Designator-based requests already used the fallback, so they are unaffected.
- Validation (run locally):
- Both new tests fail on the unfixed code (
expected ["default"] actual [""], andexpected 1 actual 0). - They pass with the fix, and
go test ./mainhandler/andgo vetare clean. - Not tested on a live cluster.
- Both new tests fail on the unfixed code (
- CI: build, CodeQL, DCO and GitGuardian are green. The Basic-Test result was not reported when I checked.
- History: I found no duplicate, superseded or previously rejected PRs. The search was by keyword, so it is not exhaustive. There are no prior reviews or inline threads.
Overview
This PR fixes #488
Signed Commits
getNamespacesput the namespace of the request's ID in the list, and for a cluster-wide WildWlid that is"". A list holding""isn't empty, so the "list every namespace" branch never ran andHandleImageScanningScopedRequestworked on"":SkipNamespace("")is true wheneverincludeNamespacesis set, so a cluster-wide image scan scanned nothing at all;"", which client-go refuses for a named Get, so these scans never used relevancy.An empty namespace is now left out, so every namespace is listed and each one is filtered and looked up on its own. A request with a namespace, or with designators, is handled as before.
How to Test
TestHandleImageScanningScopedRequest_ClusterWideLooksUpProfilesInPodNamespace: a cluster-wide request for a pod indefaultwith a ContainerProfile. On main the profile is looked up in""(expected: []string{"default"} actual: []string{""}); with the fix it's looked up indefaultand the profile scan is dispatched.TestHandleImageScanningScopedRequest_ClusterWideHonoursIncludedNamespaces: withincludeNamespaces: ["payments"], a cluster-wide request scans the pod inpaymentsand not the one inother. On main nothing is scanned (expected: 1 actual: 0).go test ./mainhandler/ -count=1passes, andgofmt,goimports,go vetandgolangci-lintreport nothing new. I haven't run it on a live cluster.Checklist before requesting a review
🤖 Generated with Claude Code
Summary by CodeRabbit