gitlab-org--gitlab-foss/lib/gitlab
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
..
auth Move logic to check ci? or lfs_deploy_token? to Gitlab::Auth::Result 2016-09-20 11:03:10 +02:00
backend Refine Git garbage collection 2016-11-04 14:30:11 +01:00
badge Also use latest_status, feedback: 2016-12-15 18:12:33 +08:00
bitbucket_import Fix import issues method 2016-12-16 19:11:48 -02:00
chat_commands Rename issue create slash command to issue new 2016-12-15 13:11:43 +00:00
checks Implement final review comments from @rymai. 2016-12-16 23:32:25 +05:30
ci Make it possible to mix Gitlab::Routing in 2016-12-13 14:51:23 +01:00
conflict Add blob_ace_mode to conflict content response 2016-10-13 14:16:35 -05:00
cycle_analytics Fix and relevant spec for plan stage breaking with nil commits 2016-11-23 09:10:04 +01:00
data_builder Added Ci::Stage specs 2016-12-06 16:04:30 +01:00
database fixing spec failures 2016-11-17 08:22:55 +01:00
diff Fixes ActionView::Template::Error: undefined method text? for nil:NilClass 2016-12-02 14:03:30 +02:00
downtime_check Better formatting for downtime check messages 2016-08-17 12:15:20 +02:00
email Enable Style/MultilineOperationIndentation in Rubocop, fixes #25741 2016-12-16 21:37:22 +03:00
fogbugz_import Pass user instance to Labels::FindOrCreateService or skip_authorization: true 2016-10-28 11:31:45 +02:00
gfm Add Gitlab::Middleware::Multipart 2016-12-15 12:26:36 +01:00
git Implement final review comments from @rymai. 2016-12-16 23:32:25 +05:30
github_import Fix branch validation for GitHub PR where repo/fork was renamed/deleted 2016-12-01 00:03:12 -02:00
gitlab_import Merge branch 'master' of dev.gitlab.org:gitlab/gitlabhq 2016-09-08 17:43:19 +03:00
google_code_import Pass user instance to Labels::FindOrCreateService or skip_authorization: true 2016-10-28 11:31:45 +02:00
graphs
import_export Merge branch 'fix/import-export-symlink-vulnerability' into 'security' 2016-11-03 16:04:18 +01:00
ldap Centralize LDAP config/filter logic 2016-11-11 15:58:33 -06:00
markdown
metrics Adds response mime type to transaction metric action when it's not HTML 2016-08-25 16:33:41 +02:00
middleware Add Gitlab::Middleware::Multipart 2016-12-15 12:26:36 +01:00
o_auth Improve the Gitlab::OAuth::User error message 2016-11-30 11:23:04 -06:00
request_profiler
saml
sanitizers
sherlock
sidekiq_middleware Merge branch 'aiionx_sidekiq_log_patch' into 'master' 2016-10-03 14:20:18 +00:00
slash_commands Fix behavior around commands with optional arguments 2016-08-18 14:29:49 -05:00
sql Merge branch 'jej-note-search-uses-finder' into 'security' 2016-12-15 11:40:12 -03:00
template Allow to use Dockerfile templates 2016-11-08 13:54:58 +00:00
access.rb Allow Member.add_user to handle access requesters 2016-09-28 09:43:00 +02:00
allowable.rb Remove trailing blank line from Allowable module 2016-12-14 08:36:03 +01:00
app_logger.rb
asciidoc.rb Don't open Asciidoc module twice 2016-12-15 18:03:57 +00:00
auth.rb Rename the token_has_scope? method. 2016-12-16 16:29:32 +05:30
award_emoji.rb
blame.rb
changes_list.rb
chat_name_token.rb Add most of specs for chat names 2016-11-17 21:34:23 +01:00
closing_issue_extractor.rb
color_schemes.rb
config_helper.rb
contributions_calendar.rb Merge branch '23403-fix-events-for-private-project-features' into 'security' 2016-11-09 12:27:41 +01:00
contributor.rb
current_settings.rb Only turn on Sidekiq throttling if application settings exists 2016-11-12 16:00:21 -08:00
database.rb Refresh project authorizations using a Redis lease 2016-11-25 13:35:01 +01:00
devise_failure.rb
downtime_check.rb
ee_compat_check.rb Ensure we sanitize branch names with path-unfriendly characters 2016-11-23 10:55:28 +01:00
emoji.rb Convert UTF-8 Emoji to Gitlab emoji 2016-10-13 13:18:30 +02:00
environment_logger.rb Show log corresponding to env in admin/logs 2016-11-03 22:02:47 +01:00
exclusive_lease.rb Refine Git garbage collection 2016-11-04 14:30:11 +01:00
file_detector.rb Unify detecting of special repository files 2016-11-21 12:51:40 +01:00
git.rb Add spec covering 'committer_hash' 2016-09-20 10:15:43 -07:00
git_access.rb Accept environment variables from the pre-receive script. 2016-12-16 23:32:25 +05:30
git_access_status.rb
git_access_wiki.rb Allow access to the wiki with git when repository feature disabled 2016-11-30 16:02:24 -02:00
git_logger.rb
git_post_receive.rb
git_ref_validator.rb
gl_id.rb
gon_helper.rb Render math in Asciidoc and Markdown with KaTeX using code blocks 2016-12-14 16:50:54 +00:00
highlight.rb
identifier.rb Use Commit#author so we share logic and cache 2016-11-24 02:33:55 +08:00
import_export.rb Fix import/export labels to cope with project and group labels. Added relevant specs. 2016-10-19 14:58:25 -02:00
import_formatter.rb
import_sources.rb Remove gitorious 2016-08-25 10:10:10 +01:00
incoming_email.rb implements reset incoming email token on issues modal and account page, 2016-11-07 15:56:18 +00:00
issues_labels.rb Pass user instance to Labels::FindOrCreateService or skip_authorization: true 2016-10-28 11:31:45 +02:00
key_fingerprint.rb
lazy.rb
lfs_token.rb Fix race condition that can be triggered if the token expires right after we retrieve it, but before we can set the new expiry time. 2016-09-29 10:25:26 -05:00
logger.rb
mail_room.rb Make mail_room idle_timeout option configurable. 2016-11-16 12:46:37 +01:00
markup_helper.rb
metrics.rb Tracking of custom events 2016-08-17 10:04:04 +02:00
optimistic_locking.rb Make retry_lock to not be infinite 2016-10-27 12:34:35 +01:00
other_markup.rb
popen.rb Accept environment variables from the pre-receive script. 2016-12-16 23:32:25 +05:30
project_search_results.rb Merge branch 'jej-note-search-uses-finder' into 'security' 2016-12-15 11:40:12 -03:00
protocol_access.rb
recaptcha.rb
redis.rb Updated mail_room and added sentinel support to Reply by Email 2016-10-26 05:02:47 +02:00
reference_extractor.rb
regex.rb Add an environment slug 2016-12-15 13:57:03 +00:00
repository_check_logger.rb
request_profiler.rb
routing.rb Make it possible to mix Gitlab::Routing in 2016-12-13 14:51:23 +01:00
search_results.rb Merge branch 'jej-23867-use-mr-finder-instead-of-access-check' into 'security' 2016-12-08 21:42:07 -03:00
seeder.rb
sentry.rb Fix Sentry not reporting right program for Sidekiq workers 2016-08-25 19:42:52 -07:00
sherlock.rb
sidekiq_logger.rb
sidekiq_throttler.rb Refactored Sidekiq Throttler and updated documentation 2016-11-11 11:14:58 -06:00
snippet_search_results.rb Clean up search result classes 2016-09-06 10:12:55 +03:00
themes.rb
timeless.rb
upgrader.rb
uploads_transfer.rb
url_builder.rb API: Endpoint to expose personal snippets as /snippets 2016-12-01 19:07:49 +01:00
url_sanitizer.rb
user_access.rb
utils.rb Fix project features default values 2016-11-01 11:03:56 -02:00
version_info.rb
visibility_level.rb
workhorse.rb Add Gitlab::Middleware::Multipart 2016-12-15 12:26:36 +01:00