2016-07-20 12:41:26 -04:00
|
|
|
class Projects::GitHttpController < Projects::GitHttpClientController
|
2016-11-21 10:31:51 -05:00
|
|
|
include WorkhorseRequest
|
2016-08-19 13:10:41 -04:00
|
|
|
|
2016-04-22 07:24:53 -04:00
|
|
|
# GET /foo/bar.git/info/refs?service=git-upload-pack (git pull)
|
|
|
|
# GET /foo/bar.git/info/refs?service=git-receive-pack (git push)
|
|
|
|
def info_refs
|
2016-03-23 13:34:16 -04:00
|
|
|
if upload_pack? && upload_pack_allowed?
|
2016-03-24 13:58:29 -04:00
|
|
|
render_ok
|
|
|
|
elsif receive_pack? && receive_pack_allowed?
|
|
|
|
render_ok
|
2016-06-23 23:01:44 -04:00
|
|
|
elsif http_blocked?
|
2016-08-03 08:54:12 -04:00
|
|
|
render_http_not_allowed
|
2016-03-24 13:58:29 -04:00
|
|
|
else
|
2016-08-03 08:54:12 -04:00
|
|
|
render_denied
|
2016-03-23 13:34:16 -04:00
|
|
|
end
|
|
|
|
end
|
2016-04-15 06:40:43 -04:00
|
|
|
|
2016-04-22 07:24:53 -04:00
|
|
|
# POST /foo/bar.git/git-upload-pack (git pull)
|
|
|
|
def git_upload_pack
|
|
|
|
if upload_pack? && upload_pack_allowed?
|
|
|
|
render_ok
|
|
|
|
else
|
2016-08-03 08:54:12 -04:00
|
|
|
render_denied
|
2016-04-22 07:24:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /foo/bar.git/git-receive-pack" (git push)
|
|
|
|
def git_receive_pack
|
|
|
|
if receive_pack? && receive_pack_allowed?
|
|
|
|
render_ok
|
|
|
|
else
|
2016-08-03 08:54:12 -04:00
|
|
|
render_denied
|
2016-04-22 07:24:53 -04:00
|
|
|
end
|
2016-03-23 13:34:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-07-20 12:41:26 -04:00
|
|
|
def download_request?
|
|
|
|
upload_pack?
|
2016-03-23 13:34:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def upload_pack?
|
2016-04-22 07:24:53 -04:00
|
|
|
git_command == 'git-upload-pack'
|
2016-03-24 13:58:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def receive_pack?
|
2016-04-22 07:24:53 -04:00
|
|
|
git_command == 'git-receive-pack'
|
2016-03-24 13:58:29 -04:00
|
|
|
end
|
|
|
|
|
2016-04-22 07:24:53 -04:00
|
|
|
def git_command
|
2016-03-23 13:34:16 -04:00
|
|
|
if action_name == 'info_refs'
|
2016-03-24 13:58:29 -04:00
|
|
|
params[:service]
|
2016-03-23 13:34:16 -04:00
|
|
|
else
|
2016-06-03 08:57:34 -04:00
|
|
|
action_name.dasherize
|
2016-03-23 13:34:16 -04:00
|
|
|
end
|
|
|
|
end
|
2016-04-15 06:40:43 -04:00
|
|
|
|
2016-03-23 13:34:16 -04:00
|
|
|
def render_ok
|
2016-08-19 13:10:41 -04:00
|
|
|
set_workhorse_internal_api_content_type
|
2016-04-06 11:52:12 -04:00
|
|
|
render json: Gitlab::Workhorse.git_http_ok(repository, user)
|
2016-03-23 13:34:16 -04:00
|
|
|
end
|
2016-04-15 06:40:43 -04:00
|
|
|
|
2016-08-03 08:54:12 -04:00
|
|
|
def render_http_not_allowed
|
|
|
|
render plain: access_check.message, status: :forbidden
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_denied
|
2016-11-21 10:31:51 -05:00
|
|
|
if user && can?(user, :read_project, project)
|
|
|
|
render plain: access_denied_message, status: :forbidden
|
2016-08-03 08:54:12 -04:00
|
|
|
else
|
|
|
|
# Do not leak information about project existence
|
|
|
|
render_not_found
|
|
|
|
end
|
2016-06-23 18:37:57 -04:00
|
|
|
end
|
|
|
|
|
2016-11-21 10:31:51 -05:00
|
|
|
def access_denied_message
|
|
|
|
'Access denied'
|
|
|
|
end
|
|
|
|
|
2016-03-23 13:34:16 -04:00
|
|
|
def upload_pack_allowed?
|
2016-06-03 09:28:35 -04:00
|
|
|
return false unless Gitlab.config.gitlab_shell.upload_pack
|
|
|
|
|
2016-11-02 17:50:44 -04:00
|
|
|
access_check.allowed? || ci?
|
2016-03-23 13:34:16 -04:00
|
|
|
end
|
2016-03-24 13:58:29 -04:00
|
|
|
|
2016-06-27 12:14:44 -04:00
|
|
|
def access
|
2017-01-24 15:04:45 -05:00
|
|
|
@access ||= access_klass.new(user, project, 'http', authentication_abilities: authentication_abilities)
|
2016-06-27 12:14:44 -04:00
|
|
|
end
|
|
|
|
|
2016-08-03 08:54:12 -04:00
|
|
|
def access_check
|
|
|
|
# Use the magic string '_any' to indicate we do not know what the
|
|
|
|
# changes are. This is also what gitlab-shell does.
|
|
|
|
@access_check ||= access.check(git_command, '_any')
|
2016-06-22 14:08:02 -04:00
|
|
|
end
|
|
|
|
|
2016-06-23 23:01:44 -04:00
|
|
|
def http_blocked?
|
2016-06-27 12:14:44 -04:00
|
|
|
!access.protocol_allowed?
|
2016-06-23 23:01:44 -04:00
|
|
|
end
|
|
|
|
|
2016-03-24 13:58:29 -04:00
|
|
|
def receive_pack_allowed?
|
2016-06-03 09:28:35 -04:00
|
|
|
return false unless Gitlab.config.gitlab_shell.receive_pack
|
|
|
|
|
2016-08-03 08:54:12 -04:00
|
|
|
access_check.allowed?
|
2016-03-24 13:58:29 -04:00
|
|
|
end
|
2017-01-24 15:04:45 -05:00
|
|
|
|
|
|
|
def access_klass
|
|
|
|
@access_klass ||= wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess
|
|
|
|
end
|
2016-03-23 13:34:16 -04:00
|
|
|
end
|