Commit 9eb019045a8c1bb9f1cb6e8d3dfb7338ab2f921a
Exists in
master
and in
4 other branches
Merge pull request #1016 from SaitoWu/feature/https
Feature/https
Showing
5 changed files
with
89 additions
and
22 deletions
Show diff stats
Gemfile
... | ... | @@ -15,6 +15,7 @@ gem "gitolite", :git => "https://github.com/gitlabhq/gitolite-client.git", |
15 | 15 | gem "pygments.rb", :git => "https://github.com/gitlabhq/pygments.rb.git", :ref => "2cada028da5054616634a1d9ca6941b65b3ce188" |
16 | 16 | gem "omniauth-ldap", :git => "https://github.com/gitlabhq/omniauth-ldap.git", :ref => "7edf27d0281e09561838122982c16b7e62181f44" |
17 | 17 | gem 'yaml_db', :git => "https://github.com/gitlabhq/yaml_db.git" |
18 | +gem 'grack', :git => "https://github.com/gitlabhq/grack.git" | |
18 | 19 | gem "linguist", "~> 1.0.0", :git => "https://github.com/gitlabhq/linguist.git" |
19 | 20 | |
20 | 21 | gem "stamp" | ... | ... |
Gemfile.lock
... | ... | @@ -14,6 +14,13 @@ GIT |
14 | 14 | hashery (~> 1.4.0) |
15 | 15 | |
16 | 16 | GIT |
17 | + remote: https://github.com/gitlabhq/grack.git | |
18 | + revision: ba46f3b0845c6a09d488ae6abdce6ede37e227e8 | |
19 | + specs: | |
20 | + grack (1.0.0) | |
21 | + rack (~> 1.4.1) | |
22 | + | |
23 | +GIT | |
17 | 24 | remote: https://github.com/gitlabhq/grit.git |
18 | 25 | revision: 7f35cb98ff17d534a07e3ce6ec3d580f67402837 |
19 | 26 | ref: 7f35cb98ff17d534a07e3ce6ec3d580f67402837 |
... | ... | @@ -373,6 +380,7 @@ DEPENDENCIES |
373 | 380 | foreman |
374 | 381 | git |
375 | 382 | gitolite! |
383 | + grack! | |
376 | 384 | grit! |
377 | 385 | haml-rails |
378 | 386 | httparty | ... | ... |
config/gitlab.yml.example
... | ... | @@ -17,11 +17,15 @@ git_host: |
17 | 17 | base_path: /home/git/repositories/ |
18 | 18 | host: localhost |
19 | 19 | git_user: git |
20 | + upload_pack: true | |
21 | + receive_pack: true | |
20 | 22 | # port: 22 |
21 | 23 | |
24 | + | |
22 | 25 | # Git settings |
23 | 26 | # Use default values unless you understand it |
24 | 27 | git: |
28 | + path: /usr/bin/git | |
25 | 29 | # Max size of git object like commit, in bytes |
26 | 30 | # This value can be increased if you have a very large commits |
27 | 31 | git_max_size: 5242880 # 5.megabytes | ... | ... |
... | ... | @@ -0,0 +1,46 @@ |
1 | +module Grack | |
2 | + class Auth < Rack::Auth::Basic | |
3 | + | |
4 | + def valid? | |
5 | + # Authentication with username and password | |
6 | + email, password = @auth.credentials | |
7 | + user = User.find_by_email(email) | |
8 | + return false unless user.valid_password?(password) | |
9 | + | |
10 | + # Find project by PATH_INFO from env | |
11 | + if m = /^\/([\w-]+).git/.match(@env['PATH_INFO']).to_a | |
12 | + return false unless project = Project.find_by_path(m.last) | |
13 | + end | |
14 | + | |
15 | + # Git upload and receive | |
16 | + if @env['REQUEST_METHOD'] == 'GET' | |
17 | + true | |
18 | + elsif @env['REQUEST_METHOD'] == 'POST' | |
19 | + if @env['REQUEST_URI'].end_with?('git-upload-pack') | |
20 | + return project.dev_access_for?(user) | |
21 | + elsif @env['REQUEST_URI'].end_with?('git-receive-pack') | |
22 | + if project.protected_branches.map(&:name).include?(current_ref) | |
23 | + project.master_access_for?(user) | |
24 | + else | |
25 | + project.dev_access_for?(user) | |
26 | + end | |
27 | + else | |
28 | + false | |
29 | + end | |
30 | + else | |
31 | + false | |
32 | + end | |
33 | + end# valid? | |
34 | + | |
35 | + def current_ref | |
36 | + if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/ | |
37 | + input = Zlib::GzipReader.new(@request.body).string | |
38 | + else | |
39 | + input = @request.body.string | |
40 | + end | |
41 | + | |
42 | + oldrev, newrev, ref = input.split(' ') | |
43 | + /refs\/heads\/([\w-]+)/.match(ref).to_a.last | |
44 | + end | |
45 | + end# Auth | |
46 | +end# Grack | ... | ... |
config/routes.rb
... | ... | @@ -8,6 +8,14 @@ Gitlab::Application.routes.draw do |
8 | 8 | require 'resque/server' |
9 | 9 | mount Resque::Server.new, at: '/info/resque' |
10 | 10 | |
11 | + # Enable Grack support | |
12 | + mount Grack::Bundle.new({ | |
13 | + git_path: GIT_OPTS['path'], | |
14 | + project_root: GIT_HOST['base_path'], | |
15 | + upload_pack: GIT_HOST['upload_pack'], | |
16 | + receive_pack: GIT_HOST['receive_pack'] | |
17 | + }), at: '/git' | |
18 | + | |
11 | 19 | # |
12 | 20 | # Help |
13 | 21 | # |
... | ... | @@ -20,15 +28,15 @@ Gitlab::Application.routes.draw do |
20 | 28 | # Admin Area |
21 | 29 | # |
22 | 30 | namespace :admin do |
23 | - resources :users do | |
24 | - member do | |
31 | + resources :users do | |
32 | + member do | |
25 | 33 | put :team_update |
26 | 34 | put :block |
27 | 35 | put :unblock |
28 | 36 | end |
29 | 37 | end |
30 | - resources :projects, :constraints => { :id => /[^\/]+/ } do | |
31 | - member do | |
38 | + resources :projects, :constraints => { :id => /[^\/]+/ } do | |
39 | + member do | |
32 | 40 | get :team |
33 | 41 | put :team_update |
34 | 42 | end |
... | ... | @@ -79,12 +87,12 @@ Gitlab::Application.routes.draw do |
79 | 87 | |
80 | 88 | resources :wikis, :only => [:show, :edit, :destroy, :create] do |
81 | 89 | member do |
82 | - get "history" | |
90 | + get "history" | |
83 | 91 | end |
84 | 92 | end |
85 | 93 | |
86 | - resource :repository do | |
87 | - member do | |
94 | + resource :repository do | |
95 | + member do | |
88 | 96 | get "branches" |
89 | 97 | get "tags" |
90 | 98 | get "archive" |
... | ... | @@ -94,14 +102,14 @@ Gitlab::Application.routes.draw do |
94 | 102 | resources :deploy_keys |
95 | 103 | resources :protected_branches, :only => [:index, :create, :destroy] |
96 | 104 | |
97 | - resources :refs, :only => [], :path => "/" do | |
98 | - collection do | |
105 | + resources :refs, :only => [], :path => "/" do | |
106 | + collection do | |
99 | 107 | get "switch" |
100 | 108 | end |
101 | 109 | |
102 | - member do | |
110 | + member do | |
103 | 111 | get "tree", :constraints => { :id => /[a-zA-Z.\/0-9_\-]+/ } |
104 | - get "blob", | |
112 | + get "blob", | |
105 | 113 | :constraints => { |
106 | 114 | :id => /[a-zA-Z.0-9\/_\-]+/, |
107 | 115 | :path => /.*/ |
... | ... | @@ -126,36 +134,36 @@ Gitlab::Application.routes.draw do |
126 | 134 | end |
127 | 135 | end |
128 | 136 | |
129 | - resources :merge_requests do | |
130 | - member do | |
137 | + resources :merge_requests do | |
138 | + member do | |
131 | 139 | get :diffs |
132 | 140 | get :automerge |
133 | 141 | get :automerge_check |
134 | 142 | end |
135 | 143 | |
136 | - collection do | |
144 | + collection do | |
137 | 145 | get :branch_from |
138 | 146 | get :branch_to |
139 | 147 | end |
140 | 148 | end |
141 | - | |
142 | - resources :snippets do | |
143 | - member do | |
149 | + | |
150 | + resources :snippets do | |
151 | + member do | |
144 | 152 | get "raw" |
145 | 153 | end |
146 | 154 | end |
147 | 155 | |
148 | - resources :hooks, :only => [:index, :create, :destroy] do | |
149 | - member do | |
156 | + resources :hooks, :only => [:index, :create, :destroy] do | |
157 | + member do | |
150 | 158 | get :test |
151 | 159 | end |
152 | 160 | end |
153 | - resources :commits do | |
154 | - collection do | |
161 | + resources :commits do | |
162 | + collection do | |
155 | 163 | get :compare |
156 | 164 | end |
157 | 165 | |
158 | - member do | |
166 | + member do | |
159 | 167 | get :patch |
160 | 168 | end |
161 | 169 | end | ... | ... |