Stop the SAST report inheriting the taint cache expiry

What does this MR do and why?

The gitlab-advanced-sast job declares its security report and its Advanced SAST taint cache in a single artifacts block, and that block set expire_in: 3 days. There is no per-path form of expire_in, so the security report took a retention value that was only ever chosen for the cache. Every sibling scanner job leaves expire_in unset and follows the instance setting.

The consequence lands on merge request comparisons. Three days after a target branch pipeline runs, its Advanced SAST report is deleted while the sibling reports from the same pipeline survive. A merge request whose merge base is that pipeline then finds no prior Advanced SAST findings, so every Advanced SAST finding in the merge request is reported as new.

Two details make it worse than it first looks. Three days spans a weekend, so a default branch scanned on Friday has no baseline by Monday. And incremental scanning, which the retention value exists for, is off by default, so projects that never turned it on were affected anyway.

This removes expire_in from the job in both templates, which is the first of the fixes the issue proposes and the only one that is a pure template change. Moving the taint cache to cache:, the way gitlab-advanced-sast-ext does, would also need an analyzer change, because this job locates its cache by searching earlier pipelines' artifacts. Per-path expire_in would need a CI/CD feature that does not exist today.

The cache path is left in place, so incremental scanning keeps working.

References

Differences

Before: in a single pipeline, gitlab-advanced-sast artifacts expired after 3 days while semgrep-sast artifacts followed the instance setting, 30 days on GitLab.com. Once the baseline pipeline was superseded and its artifacts unlocked, the Advanced SAST report was deleted first, and the merge request widget reported every Advanced SAST finding as new rather than only the ones the branch introduced.

After: both jobs keep the same retention, so the Advanced SAST report survives as long as its siblings and the comparison finds the baseline it expects. Only genuinely new findings are reported as new.

The documentation said the template stores the cache artifact with a default expiry of 3 days, which stops being true with this change, so it now says the artifact follows the instance or project setting. The override example is unchanged, with one sentence added noting that expire_in applies to the whole artifacts block and so also shortens how long the report is kept. That coupling is what caused this bug, and anyone reaching for the override should know about it.

How to set up and validate locally

The templates are data, so the change can be read directly:

grep -n "expire_in" lib/gitlab/ci/templates/Jobs/SAST.gitlab-ci.yml lib/gitlab/ci/templates/Jobs/SAST.latest.gitlab-ci.yml

No matches remain. Parsing either template and comparing the two jobs shows the point of the change: gitlab-advanced-sast and semgrep-sast now agree, with artifacts holding only access, paths and reports, and both report and cache paths still present.

Reproducing the original behaviour end to end needs Ultimate and an instance artifact expiry longer than 3 days; the issue records the full steps, including the precondition that the baseline pipeline must no longer be the most recent successful pipeline on the ref, since GitLab locks those artifacts.

Edited by Jeston Singh

Merge request reports

Loading
Loading