Bug: Scan execution policies error when Pipeline execution policies are concurrently enabled

Summary

When enforcing scan execution policies and pipeline execution policies against the same set of projects concurrently, the downstream project pipeline fails.

Steps to reproduce

  1. Create a scan execution policy enforcing a security scan such as SAST.
  2. Create a pipeline execution policy creating any job, such as basic job with an echo script.
  3. Enforce on projects with the same compliance framework label.
  4. Observe pipeline failure in given projects.

Example Project

What is the current bug behavior?

What is the expected correct behavior?

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes