Commit 05422614 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Allow git clone with http for GitLab CI service:

If you enable GitLab CI for project you will be able to clone project
source code with next command:
git clone http://gitlab-ci-token:XXXXXXXXXXXX@host:project.git
Requires for GitLab CI 4.0
parent 71f92d45
...@@ -38,6 +38,16 @@ module Grack ...@@ -38,6 +38,16 @@ module Grack
# Authentication with username and password # Authentication with username and password
login, password = @auth.credentials login, password = @auth.credentials
# Allow authentication for GitLab CI service
# if valid token passed
if login == "gitlab-ci-token" && project.gitlab_ci?
token = project.gitlab_ci_service.token
if token.present? && token == password && service_name == 'git-upload-pack'
return @app.call(env)
end
end
@user = authenticate_user(login, password) @user = authenticate_user(login, password)
if @user if @user
...@@ -59,14 +69,7 @@ module Grack ...@@ -59,14 +69,7 @@ module Grack
end end
def authorized_git_request? def authorized_git_request?
# Git upload and receive authorize_request(service_name)
if @request.get?
authorize_request(@request.params['service'])
elsif @request.post?
authorize_request(File.basename(@request.path))
else
false
end
end end
def authenticate_user(login, password) def authenticate_user(login, password)
...@@ -91,6 +94,16 @@ module Grack ...@@ -91,6 +94,16 @@ module Grack
end end
end end
def service_name
if @request.get?
@request.params['service']
elsif @request.post?
File.basename(@request.path)
else
nil
end
end
def project def project
@project ||= project_by_path(@request.path_info) @project ||= project_by_path(@request.path_info)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment