Ports https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/28489 to EE.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/61960.