Cherry-picking https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2205
@DouweM Please review, thanks! /cc @kushalpandya