Exclude volatile ReplicaSet name from Trivy Operator service field - #16028
Open
tallesgois-shipay wants to merge 5 commits into
Open
tallesgois-shipay wants to merge 5 commits into
tallesgois-shipay wants to merge 5 commits into
Conversation
The Trivy Operator handlers (vulnerability, checks, secrets) built the `service` field as `namespace/kind/name`. For Pods owned by a ReplicaSet, `name` is the ReplicaSet's generated name, which changes on every deploy. Since close_old_findings matches on an exact service string, this made service change on every redeploy and permanently prevented old findings from ever being closed, causing unbounded finding accumulation across redeploys. Fixes DefectDojo#16026
tallesgois-shipay
requested review from
Maffooch and
blakeaowens
as code owners
September 21, 2026 17:37
This branch has not been deployed
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.
Fixes #16026
Problem
The Trivy Operator handlers (
vulnerability_handler.py,checks_handler.py,secrets_handler.py) buildFinding.serviceasnamespace/kind/name:For Pods owned by a ReplicaSet,
resource_name(from thetrivy-operator.resource.namelabel) is the ReplicaSet's generated name, which changes on every deploy (new hash suffix each rollout).close_old_findingsscopes its query by an exactservicematch:Since
servicechanges on every redeploy for these three scan types,close_old_findingscan never match findings from a previous deploy generation — old findings are never closed, only ever added to, regardless ofclose_old_findings=true. In our environment this let onedojo_findingtable grow from ~218k to 5.7M+ rows over ~3 months, degrading Postgres enough to cause dashboard timeouts and an availability incident (details in #16026).This is the same pattern discussed in #11500, where a maintainer confirmed the fix works "as long as you don't include a version number and the value stays the same across reimports" — but there the volatile value came from caller-supplied API input. Here it's built inside DefectDojo's own bundled parsers, so callers (e.g.
trivy-dojo-report-operator) have no way to work around it.Fix
Drop
resource_namefrom theservicestring in all three handlers, keepingnamespace/kind[/container]. This keepsservicestable across redeploys of the same workload while still distinguishing different containers/workloads within a namespace.checks_handler.pyandsecrets_handler.pyhad byte-identical logic tovulnerability_handler.pyand are fixed the same way for consistency, since they share the exact same volatility problem.Tests
Added
test_vulnerabilityreport_service_excludes_volatile_replicaset_nametounittests/tools/test_trivy_operator_parser.py, asserting the fixture's ReplicaSet-generatedresource.name("nginx-deployment-965685897") does not end up infinding.service. No existing test asserted onserviceformat, so nothing else needed updating.Deployment method