Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/60908
EE counterpart: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/14650