Commit 0542261437fd9df7539fe480069449b566057300
1 parent
71f92d45
Exists in
master
and in
4 other branches
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
Showing
1 changed file
with
21 additions
and
8 deletions
Show diff stats
lib/gitlab/backend/grack_auth.rb
@@ -38,6 +38,16 @@ module Grack | @@ -38,6 +38,16 @@ module Grack | ||
38 | # Authentication with username and password | 38 | # Authentication with username and password |
39 | login, password = @auth.credentials | 39 | login, password = @auth.credentials |
40 | 40 | ||
41 | + # Allow authentication for GitLab CI service | ||
42 | + # if valid token passed | ||
43 | + if login == "gitlab-ci-token" && project.gitlab_ci? | ||
44 | + token = project.gitlab_ci_service.token | ||
45 | + | ||
46 | + if token.present? && token == password && service_name == 'git-upload-pack' | ||
47 | + return @app.call(env) | ||
48 | + end | ||
49 | + end | ||
50 | + | ||
41 | @user = authenticate_user(login, password) | 51 | @user = authenticate_user(login, password) |
42 | 52 | ||
43 | if @user | 53 | if @user |
@@ -59,14 +69,7 @@ module Grack | @@ -59,14 +69,7 @@ module Grack | ||
59 | end | 69 | end |
60 | 70 | ||
61 | def authorized_git_request? | 71 | def authorized_git_request? |
62 | - # Git upload and receive | ||
63 | - if @request.get? | ||
64 | - authorize_request(@request.params['service']) | ||
65 | - elsif @request.post? | ||
66 | - authorize_request(File.basename(@request.path)) | ||
67 | - else | ||
68 | - false | ||
69 | - end | 72 | + authorize_request(service_name) |
70 | end | 73 | end |
71 | 74 | ||
72 | def authenticate_user(login, password) | 75 | def authenticate_user(login, password) |
@@ -91,6 +94,16 @@ module Grack | @@ -91,6 +94,16 @@ module Grack | ||
91 | end | 94 | end |
92 | end | 95 | end |
93 | 96 | ||
97 | + def service_name | ||
98 | + if @request.get? | ||
99 | + @request.params['service'] | ||
100 | + elsif @request.post? | ||
101 | + File.basename(@request.path) | ||
102 | + else | ||
103 | + nil | ||
104 | + end | ||
105 | + end | ||
106 | + | ||
94 | def project | 107 | def project |
95 | @project ||= project_by_path(@request.path_info) | 108 | @project ||= project_by_path(@request.path_info) |
96 | end | 109 | end |