--node-collector-namespace: Do not delete existing namespace #6558
Labels
kind/bug
Categorizes issue or PR as related to a bug.
priority/backlog
Higher priority than priority/awaiting-more-evidence.
target/kubernetes
Issues relating to kubernetes cluster scanning
Milestone
Discussed in #6538
Originally posted by codinux-gmbh April 22, 2024
Description
When using
trivy kubernetes --node-collector-namespace <namespace> ...
, then the namespace<namespace>
gets deleted after the operation even if it's an existing namespace that contains resources.That deleted almost our whole (for sake test) cluster.
(Scanning the whole cluster for misconfiguration ran into a timeout, so we decided to automatically scan namespace per namespace. But then jobs sometimes failed as the previous job in the
trivy-temp
namespace was still running, so we decided to run each job in the namespace to scan via--node-collector-namespace
flag.)The issue is in
pkg/jobs/collector.go
:Desired Behavior
First check if Trivy created that namespace before deleting it.
Actual Behavior
The namespace passed with
--node-collector-namespace
gets deleted regardless if Trivy created that namespace or if it's an existing namespace that contains resources.Reproduction Steps
Target
Kubernetes
Scanner
None
Output Format
None
Mode
None
Debug Output
The output doesn't matter, the clean up behavior is the issue.
Operating System
Arch Linux, but also the OS doesn't matter
Version
Checklist
trivy image --reset
The text was updated successfully, but these errors were encountered: