Skip to content

Accept environment variables from the `pre-receive` script

Timothy Andrew requested to merge 25301-git-2.11-force-push-bug into master

Summary

  1. Starting version 2.11, git changed the way the pre-receive flow works.
  • Previously, the new potential objects would be added to the main repo. If the pre-receive passes, the new objects stay in the repo but are linked up. If the pre-receive fails, the new objects stay orphaned in the repo, and are cleaned up during the next git gc.
  • In 2.11, the new potential objects are added to a temporary "alternate object directory", that git creates for this purpose. If the pre-receive passes, the objects from the alternate object directory are migrated to the main repo. If the pre-receive fails the alternate object directory is simply deleted.
  1. In our workflow, the pre-recieve script (in gitlab-shell) calls the /allowed endpoint, which calls out directly to git to perform various checks. These direct calls to git do not have the necessary environment variables set which allow access to the "alternate object directory" (explained above). Therefore these calls to git are not able to access any of the new potential objects to be added during this push.

  2. We fix this by accepting the relevant environment variables (GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_OBJECT_DIRECTORY, and GIT_QUARANTINE_PATH) on the /allowed endpoint, and then include these environment variables while calling out to git.

  3. This commit includes these environment variables while making the "force push" check.

Issue Numbers

Tasks

  • [#25301 (closed)/!7967 (merged)/!112 (merged)] Git version 2.11.0 - Can't push to protected branch as master or developer
    • Investigate
    • Implementation
      • force_push.rb should use the relevant environment variables
      • Any other instances of /allowed calling out to git directly?
      • Verify that the fix works over SSH as well
      • Can we trim the number of env variables? Do we need all 3?
      • Whitelist variables. Server shouldn't pass through any env variable passed in
      • Any security implications?
      • Check for force push return code
      • Shouldn't be able to opt-out from the force push check by passing an env variable
    • Tests
      • CE
        • Added
        • Passing
      • Shell
        • Added
        • Passing
    • Meta
      • CHANGELOG entry created
      • Branch has no merge conflicts with master
      • Squashed related commits together
      • EE merge request
    • Review
      • Endboss
    • Follow-up
      • Make sure EE is working as expected
      • [CE] Gitlab changes without gitlab-shell changes shouldn't raise any exceptions
      • [CE] Gitlab-shell changes without gitlab changes shouldn't raise any exceptions
      • [EE] Gitlab changes without gitlab-shell changes shouldn't raise any exceptions
      • [EE] Gitlab-shell changes without gitlab changes shouldn't raise any exceptions
    • Wait for merge
      • CE
      • EE
      • Shell

Merge request reports