Backport of gitlab-org/gitlab-ee!5743
gitlab-org/gitlab-ee!5743
https://gitlab.com/gitlab-org/gitlab-ee/issues/5784