Skip to content

Commit 1d6f498

Browse files
committed
Allow only authorized users to make push and clone
Check if user is owner of the project when git sends push request or clone request for private projects.
1 parent 3a8e680 commit 1d6f498

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

app/models/user.rb

+9
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,13 @@ def git_author_params
6464
time: Time.now
6565
}
6666
end
67+
68+
# checks if the user if the owner of the passed project
69+
def owner?(project)
70+
if id == project.user.id
71+
true
72+
else
73+
false
74+
end
75+
end
6776
end

config.ru

-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11

22
# This file is used by Rack-based servers to start the application.
33

4-
# require './lib/rack/git_http'
5-
64
require ::File.expand_path('../config/environment', __FILE__)
75
run Glitter::Application
8-
9-
# map '/health' do
10-
# health = proc do |env|
11-
# [200, { "Content-Type" => "text/html" }, ["1"]]
12-
# end
13-
# run health
14-
# end
15-
16-
17-
# map '/git' do
18-
# use Rack::ShowExceptions
19-
20-
# config = {
21-
# :project_root => "#{ENV["OPENSHIFT_DATA_DIR"]}/repos",
22-
# :git_path => '/usr/bin/git',
23-
# :upload_pack => true,
24-
# :receive_pack => true,
25-
# }
26-
27-
# run GitHttp::App.new(config)
28-
29-
# end

lib/rack/grack_auth.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ def project_by_path(path)
6363
def authorized_request?
6464
case git_cmd
6565
when *%w{ git-upload-pack git-upload-archive }
66-
unless project.private
66+
if user
67+
user.owner?(project)
68+
elsif !project.private
6769
# Allow clone/fetch for public projects
6870
true
6971
else
7072
false
7173
end
7274
when *%w{ git-receive-pack }
7375
if user
74-
# Skip user authorization on upload request.
75-
# It will be done by the pre-receive hook in the repository.
76-
true
76+
user.owner?(project)
7777
else
7878
false
7979
end

0 commit comments

Comments
 (0)