gitlab-org--gitlab-foss/spec
Douglas Barbosa Alexandre 022242c30f Merge branch '25301-git-2.11-force-push-bug' into 'master'
Accept environment variables from the `pre-receive` script

## 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.
2. 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.

3. 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.

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

## Issue Numbers

- Closes #25301 (assuming the corresponding `gitlab-shell` MR has been merged in first)
- Corresponding `gitlab-shell` MR: gitlab-org/gitlab-shell!112
- Corresponding EE MR: gitlab-org/gitlab-ee!964

## Tasks

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


See merge request !7967
2016-12-19 09:37:16 +00:00
..
bin
config
controllers Merge remote-tracking branch 'origin/master' into bitbucket-oauth2 2016-12-16 18:03:24 -02:00
db/production Allow users to seed the initial runner registration token using an environment variable 2016-12-01 17:21:21 -08:00
factories Add a `scopes` column to the `personal_access_tokens` table 2016-12-16 15:08:10 +05:30
features Merge branch 'dockerfile-templates' into 'master' 2016-12-19 08:42:52 +00:00
finders Merge branch 'jej-24637-move-issue-visible_to_user-to-finder' into 'security' 2016-12-15 11:41:04 -03:00
fixtures adds impersonator variable and makes sudo usage overall more clear 2016-12-07 14:42:51 +00:00
helpers Always use `fixture_file_upload` helper to upload files in tests. 2016-12-18 20:35:07 -05:00
initializers
javascripts Merge branch 'abuse_report-fixture' into 'master' 2016-12-16 12:29:14 +00:00
lib Merge branch '25301-git-2.11-force-push-bug' into 'master' 2016-12-19 09:37:16 +00:00
mailers Merge branch '24880-configurable-plaintext-emails' into 'master' 2016-11-29 12:05:23 +00:00
migrations Encode when migrating ProcessCommitWorker jobs 2016-12-13 16:52:49 +01:00
models Merge branch 'cleaner-merge-commit-messages' into 'master' 2016-12-17 02:06:16 +00:00
policies Add missing group policy spec 2016-12-15 21:30:35 +02:00
requests Enable Style/MultilineOperationIndentation in Rubocop, fixes #25741 2016-12-16 21:37:22 +03:00
routing Changed autocomplete_sources into an action that returns a single 'at' type of sources at a time 2016-12-15 15:20:33 +00:00
serializers fix transient timing failure adding timecop 2016-12-14 14:49:10 +01:00
services Merge branch '20492-access-token-scopes' into 'master' 2016-12-16 17:38:41 +00:00
support Merge branch '25339-2-webhooks-fired-for-issue-closed-and-reopened' into 'master' 2016-12-16 17:00:43 +00:00
tasks/gitlab Don't allow to specify a repo or version when installing Workhorse 2016-12-01 19:22:46 +01:00
uploaders Add Gitlab::Middleware::Multipart 2016-12-15 12:26:36 +01:00
views Fix test 2016-12-12 13:16:52 -06:00
workers Merge branch 'zj-guest-reads-public-builds' into 'master' 2016-12-06 13:54:16 +00:00
factories_spec.rb
rails_helper.rb
rake_helper.rb Move task helpers to a module 2016-11-30 12:20:21 +01:00
simplecov_env.rb
spec_helper.rb Pass commit data to ProcessCommitWorker 2016-12-01 13:36:06 +01:00
teaspoon_env.rb