chore(be) : Address bugs causing flappy fix timestamp #18789
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.
Description
There are two scenarios that can cause flappy FixAvailableTimestamps in a CVE:
If the same (CVE + package + datasource combination) is present multiple times in an image with different fix timestamps, then the one processed last will take precedence because the
ImageCVEInfolookup table can only have one (CVE + package + datasource) combination. So the last processed vuln will overwrite earlier info. Instead, we should preserve the earliest timestamp across multiple occurrences.The implementation did not preserve the datasource from the scanner when writing CVEs to the database. This can also cause CVE FixAvailableTimestamp to change. The image enricher does not rescan the image each time. Sometimes it just fetches the stored image from the database and populates the scan. If datasources are not stored in db, the scan populated from an existing image will not have any datasources. When such an image gets rewritten to the db, the logic used to find
FixAvailableTimestampfrom theImageCVEInfoslookup table will not be able to find it without the right datasource. Preserving the datasource in the database would fix this problem.This PR addresses both the above issues.
User-facing documentation
Testing and quality
Automated testing
How I validated my change
Unit tests
Manual tests