Database migration to correct vulnerabilities incorrectly transitioned by auto-resolve
Why are we doing this work
The new vulnerability management policy feature had a bug (#521907 (closed)) where vulnerabilities were incorrectly transitioned from dismissed to resolved. We need to create a background migration to correct these vulnerabilities back to their original state.
Customer reports
Active
- https://gitlab.slack.com/archives/CPJTR33AQ/p1744759442737069
- Vulnerability Management Policy Auto-resolve Pr... (#536314 - closed)
- GitLab Security Policy Bot updated vulnerabilit... (#535613 - closed)
- Dismissed entries in Vulnerability Report keep ... (#515785 - closed)
Mitigated (other issue, or migration is not needed)
Relevant links
Non-functional requirements
-
Documentation: -
Feature flag: -
Performance: -
Testing:
Implementation plan
- Create a batched background migration that accepts two arguments:
-
instance- boolean, migrate all vulnerabilities on the instance when set totrue -
namespace_id- integer, namespace to migrate
-
- Batch over in-scope vulnerabilities that are in the
resolvedordetectedstates. - Check the state transitions from newest to oldest.
- If we see a state transition where
created_atis older than 2024-11-18 (when !172161 (merged) was first deployed), exit early. - If we see a state transition where
authordoes not haveuser_type = 10(security policy bot), exit early. - If we see a state transition where
from_stateisdismissedandto_stateisresolved, push this vulnerability to the list of vulnerabilities to be reverted.
- If we see a state transition where
- Bulk-update all the vulnerabilities to be reverted
- Change vulnerability state to
dismissed - Insert a new state transition to record this state change
- Insert a system note explaining why the state has been changed
- Change vulnerability state to
- Create a rake task which can be used to enqueue the migration with the arguments
Why not a normal migration?
See https://gitlab.com/gitlab-com/gl-infra/production/-/issues/19860#why-do-this-via-a-change-request
Verification steps
Edited by Neil McCorrison