# Authentication with username and password
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)
if @user
end
def authorized_git_request?
- # Git upload and receive
- if @request.get?
- authorize_request(@request.params['service'])
- elsif @request.post?
- authorize_request(File.basename(@request.path))
- else
- false
- end
+ authorize_request(service_name)
end
def authenticate_user(login, password)
end
end
+ def service_name
+ if @request.get?
+ @request.params['service']
+ elsif @request.post?
+ File.basename(@request.path)
+ else
+ nil
+ end
+ end
+
def project
@project ||= project_by_path(@request.path_info)
end